Then, after digesting all of the information, you guys gave me and taking a closer look, I've had a revelation that { @_ } is nothing other then a regular anonymous hash reference of @_ array being converted to hash ref by {} braces and a $class is a reference to Self object.

No, not quite. See "Method Invocation" in perlobj. For class methods, the first argument for a method is the class (just its name); for objects, it is the object. Not a reference - just like that. For class methods, the class name is a literal, and the object is a reference already. The arrow operator "->" makes the passing of the first parameter implicit, so the next two are equivalent:

$obj = MyClass->new( %params); $obj = MyClass::new( 'MyClass', %params);
Can I still access them by (I didn't test it yet, still trying to digest everything)?:

Yes, since an object is just a reference blessed into a Namespace. Otherwise, it behaves just like any reference. Again, read perlobj and related material.

qtyTotal=>sub{return &qtyTotal('phrase 1', @_);}

I realize, that this is an inefficient solution, but this is the solution that allows using pseudo methods without an actual objects.

The use of the ampersand "&" as a sigil to suroutine calls makes passing @_ implicit, but only if the call has an empty parameter list. Consider:
$\ = $/; # see perlvar sub b { print join" ",@_ } sub e { &b } # @_ passed implicitly sub f { &b( "got") } # parens necessary! sub g { b "got", @_ } # parens may be omitted, if sub b # has been seen earlier @l = (1...3); e @l; f @l; g @l; __END__ 1 2 3 got got 1 2 3

So, use "&" only if you mean to pass @_ (and only @_) implicitly.

And it's not ineffective, I'd say, but neither is it "pseudo-methods" - that is calling anonymous subroutines. A pseudo method (call) would be something like the following:

sub b { print join" ", @_ } "b"->(1..3)

Further reading: perlboot, perlref, perlreftut, perltoot, ...


In reply to Re^3: How to detect a hash container key from a referenced sub value by shmem
in thread How to detect a hash container key from a referenced sub value by igoryonya

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.