Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Perl semi-object without a constructorby tobyink (Canon) |
on Feb 20, 2013 at 21:29 UTC ( [id://1019849]=note: print w/replies, xml ) | Need Help?? |
Given this
The connect method is not being called with three arguments, it's being called with four arguments. The first argument is the string "Msg" - that is, the part before the ->. This is how method calls work in Perl (we borrowed it from Python); the thing before the arrow gets passed in as the first argument.
$pkg is "Msg".
Why do you think $conn has no methods? Something to do with the hash only having a couple of uninteresting key-value pairs? An object's methods have nothing to do with the blessed reference itself, but are taken from the package it is blessed into. So because $conn is blessed into the Msg package, all the subs defined within Msg are available as methods for $conn.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
In Section
Seekers of Perl Wisdom
|
|