When executing the statement $obj->method();
, perldiag
says that Perl needs to know what package the method belongs to. That's why it needs to be blessed:
Can't call method "%s" on unblessed reference
(F) A method call must know in what package it's supposed to run. It ordinarily finds this out from the object reference you supply, but you didn't supply an object reference in this case. A reference isn't an object reference until it has been blessed. See
perlobj
.
Because of this, it isn't possible to do the following:
my $data = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
];
$data->process( @params ); # Can't call method "process" on unblessed reference
Then why does it work with a coderef?:
my $process = \&process; # Same method as before
$data->$process( @params ); # Works fine now