Given this

package Msg; sub connect { my ($pkg, $to_host, $to_port, $rcvd_notification_proc) = @_; } # ... Msg->connect($host, $port, \&rcvd_msg_from_server);

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.

"From the comment, an object was created. The reference is the anonymous hash with 2 members, and the class name is what? $pkg appears to be an undefined scalar?"

$pkg is "Msg".

"From the prior 'bless', a $conn has no methods"

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 reply to Re: Perl semi-object without a constructor by tobyink
in thread Perl semi-object without a constructor by Wiggins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.