Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: defining methods on the fly

by revdiablo (Prior)
on Aug 04, 2006 at 17:37 UTC ( #565711=note: print w/ replies, xml ) Need Help??


in reply to Re^4: defining methods on the fly
in thread defining methods on the fly

The following modification does not assign to a glob.

Apologies if I'm misunderstanding something here, but isn't the following code assigning to a glob?

*{$package . "::" . $name} = sub :lvalue {

Update: Thanks for the reply -- I was indeed "misunderstanding something here."


Comment on Re^5: defining methods on the fly
Download Code
Re^6: defining methods on the fly
by jdhedden (Deacon) on Aug 05, 2006 at 01:57 UTC
    Apologies if I'm misunderstanding something here, but isn't the following code assigning to a glob?
    *{$package . "::" . $name} = sub :lvalue {
    True, but that wasn't what I was referring to. The above is only executed once. The concern was with the following line in the original code that was executed every time the method was called:
    local *call = sub { $self->{$name}->(@_); };
    By removing that line, my suggested code should not suffer from the method cache reset performance penalty that occurs each time the method in the original code is called.

    Remember: There's always one more bug.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2015-07-01 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (19 votes), past polls