Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Could anyone explain the following Class::MethodMaker Code ?

by jesuashok (Curate)
on Feb 20, 2006 at 11:15 UTC ( #531384=perlquestion: print w/ replies, xml ) Need Help??
jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks !!!

Could anyone explain the below code.
I am aware of new => new. what about the following ?

scalar => [+{ -type => 'File::stat' }, qw/ name /],

use Class::MethodMaker [ scalar => [+{ -type => 'File::stat' }, qw/ name /], new => 'new', ];

"Keep pouring your ideas"

Comment on Could anyone explain the following Class::MethodMaker Code ?
Select or Download Code
Re: Could anyone explain the following Class::MethodMaker Code ?
by wazoox (Prior) on Feb 20, 2006 at 11:53 UTC
    Blech. That is really the sort of code that makes perl's bad reputation...
    So what do we have ? here's my explanation : the enclosing "[]" force an anonymous array context. Inside we have 2 array elements :
    scalar => [+{ -type => 'File::stat' }, qw/ name /], new => 'new',
    The last one ( new => 'new') is clear enough. The first one is trickier : scalar is the hash key; let's analyse the content :
    [+{ -type => 'File::stat' }, qw/ name /]
    the enclosing square braces once again force an anonymous array. Inside there are two elements :
    +{ -type => 'File::stat' }, qw/ name /
    , the + force the following curly brace {} to be interpreted as an hash element and not a code block. so that's simply an anonymous hash entry.
    "qw/name/" is just useless here because there's only one word...
    Finally that's not very complex, just extremely obfuscated...
    Here's what Data::Dumper can tell us about this structure, finally :
    $VAR1 = { 'scalar' => [ { '-type' => 'File::stat' }, 'name' ], 'new' => 'new' };
    It's way better, isn't it ?
    update : I forgot to mention that this structure looks like a pseudo-hash.
Re: Could anyone explain the following Class::MethodMaker Code ?
by mattr (Curate) on Feb 22, 2006 at 07:12 UTC
    While on the subject, I had exactly the same question since that line appears in the docs.

    Could use more tutorials / docs on Class::MethodMaker and especially persistence of its objects. (Am posting a separate thread about that now).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2015-07-02 10:48 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 (34 votes), past polls