Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: goto &method and skipping call frame

by shmem (Chancellor)
on Mar 04, 2021 at 22:15 UTC ( [id://11129136]=note: print w/replies, xml ) Need Help??


in reply to goto &method and skipping call frame

The real use case is a more complicated implementation of a with construct, where $OBJ is a closure var and AUTOLOAD is localized to the block.

Then show this more complicated implementation. What do you mean by "AUTOLOAD is localized to the block"? Does that mean you have a local *AUTOLOAD; in place? Or is it local $AUTOLOAD?

This reminds me of one piece of programming lore -

  1. writing code is hard
  2. debugging code is harder
  3. if you write your programs as clever as you are, you are, by definition, too dumb to debug them

As for your questions: I'd say no, and no (afaik). Prove me wrong with tests.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: goto &method and skipping call frame
by LanX (Saint) on Mar 04, 2021 at 22:20 UTC
    > Then show this more complicated implementation.

    what's the problem with the question?

    I linked the relevant docs.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      One place where I've seen this technique is a ORM package on CPAN - Class::Tables - which auto-generates classes from table names and makes colum names into their methods using AUTOLOAD:

      sub AUTOLOAD { my $self = shift; (my $func = $Class::Tables::AUTOLOAD) =~ s/.*:://; croak qq{Can't locate object method "$func" via package "$self"} unless ref $self and UNIVERSAL::isa( $self, "Class::Tables" ); unshift @_, $self, $func; goto &field; }

      The field() sub translates its arguments to the appropriate SQL call against the database. I've used that package very much, and I have seen no adverse side effects. And no, I'm not aware of a cleaner way to do this.

      I'm still puzzled by the meaning of "AUTOLOAD is localized to a blocks context" part of your question. Does that mean having different lookup-results (depending on scope) for the last-resort AUTOLOAD sub?

      Sorry if I'm just being too dumb or having the wrong kind of humour. ;)

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        Thanks the example from Class::Tables is interesting. :)

        And I now understand goto &$method_ref seems to follow the @ISA chain.

        It doesn't, this was my brain fart. =)

        It's the ->can() which already returned the correct code_ref after following the inheritance chain

        And that's highlighting the difference to Class::Table, $func is a string not a ref.

        Additionally goto &field is not a dynamic call, it will always call the same sub field in the same package.

        Though ->field could be called as a method form other points, since it expects $self as first argument.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

      what's the problem with the question I linked the relevant docs.

      No problem with your question, but probably with my answer. Sorry about that.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129136]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found