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

Re: What does @_[OBJECT, ARG0, ARG1] mean?

by thomas895 (Deacon)
on Feb 28, 2016 at 00:53 UTC ( [id://1156348]=note: print w/replies, xml ) Need Help??


in reply to What does @_[OBJECT, ARG0, ARG1] mean?

When you encounter things like this in the future, the Debugger is very useful. In particular, look at the X vars... (or V Package::Name vars...) commands. Try, for example,

DB<1> X OBJECT $OBJECT = 123

There's nothing special about constants. All that constant.pm does is create a method in the package that returns the value you gave, by cleverly using import through use. Here's the relevant parts from constant.pm in 5.12.3:

#===================================================================== +== # import() - import symbols into user's namespace # # What we actually do is define a function in the caller's namespace # which returns the value. The function we create will normally # be inlined as a constant, thereby avoiding further sub calling # overhead. #===================================================================== +== sub import { #... #note: $full_name is set to "Package_I_Was_Called_From::ConstantNa +me", for each constant you provide #if you have a scalar, it basically does *$full_name = sub () { $scalar }; #and if you have an array: *$full_name = sub () { @list }; #... }

Note: In the debugger output above, you may have noticed that it appeared as a regular variable. Indeed, in Perl 5.8 (as I understand it), constant.pm had some magic added to it so that scalars are simply added into the symbol table, appearing to be a package variable. Still, you can't really use them as variables, as you can observe here:

DB<6> x &OBJECT 0 123 DB<7> x $OBJECT 0 undef
-Thomas
"Excuse me for butting in, but I'm interrupt-driven..."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found