'Perl Error: Attempt to bless into a reference

I have been working with OO Perl. I have base class, which is legacy code and I can't change it. I am writing a derived class with a new style (my convenient style too) but when I am deriving it I am getting an error as

Attempt to bless into a reference 

My code is similar to the below code:

 package Base ;
   sub new {
        my ($class, %args) = @_;
        my $self = {};
    
        $self->{top} = $args{top};
        return bless $self, $class;
    }
1;

The Derived class:

package derived;
use base qw{Base};
use  fields qw{_bot};

sub new {

    my __PACKAGE__ $this = shift;
    my %arg = @_;
    
    unless (ref $this) {
        $this = fields::new($this);

    }
    $this->Base::new( %arg);
    return $this;
}
1;

The caller is

use File::Basename;
BEGIN {
  my $root_dir = dirname $0;
  push(@INC, $root_dir);
}
use derived;
my $d = new derived(top=>"t1");

I am getting error as

Attempt to bless into a reference at Base.pm line 8.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source