in reply to Re: Objects and passing/calling methods
in thread Objects and passing/calling methods

Ah, that explains it then. I was under the assumption that self and class are always passed inherently. So if class is not, what is the class of the ticket object? SomePackage or SomePackage::Ticket?
  • Comment on Re^2: Objects and passing/calling methods

Replies are listed 'Best First'.
Re^3: Objects and passing/calling methods
by choroba (Cardinal) on Sep 22, 2018 at 20:26 UTC
    The one it's been blessed to.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Thank you, much appreciated!

        You can (usually) easily tell what class an object is blessed into by using one of many fine dumpers; I like Data::Dump, but it's not core; Data::Dumper is core.

        c:\@Work\Perl\monks>perl -wMstrict -le "use 5.014; ;; package Foo { sub defaults { return { 'default' => 'zing' }; } sub new { my $class = shift; my ($hr_args) = @_; my $obj = { %{ $class->defaults }, %{ $hr_args || {} } }; return bless $obj => $class; } sub show { my $self = shift; print qq{@{[ %$self ]} @_}; } } ;; package Bar { use parent -norequire, qw(Foo); sub show { my $self = shift; $self->SUPER::show('from ' . __PACKAGE__, @_); } } ;; my $b = Bar->new({ 'hi' => 'there' }); $b->show('zoot'); ;; use Data::Dump qw(dd); ;; dd $b; " hi there default zing from Bar zoot bless({ default => "zing", hi => "there" }, "Bar")

        Update: Per kevbot's comment:   Addition to code posted above:

        ... print ref $b;
        And it's output:
        Bar


        Give a man a fish:  <%-{-{-{-<

Re^3: Objects and passing/calling methods
by haukex (Archbishop) on Sep 24, 2018 at 20:37 UTC
    I was under the assumption that self and class are always passed inherently.

    I can recommend a read of perlobj, which says (among many other useful things):

    When you call a method, the thing on the left side of the arrow is passed as the first argument to the method. That means when we call Critter->new(), the new() method receives the string "Critter" as its first argument. When we call $fred->speak(), the $fred variable is passed as the first argument to speak().

    And BTW, since there was mention of it further down in the thread, having to retrieve the class of one's own object with something like ref would seem like a code smell to me, most things can (and should) be solved with the appropriate OO concepts (encapsulation, inheritance, etc.). But I guess you were asking about the class out of curiosity, not because you need it?