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

Re: Class::InsideOut 1.01 now with added sugar

by clscott (Friar)
on Jul 27, 2006 at 21:42 UTC ( [id://564234]=note: print w/replies, xml ) Need Help??


in reply to Class::InsideOut 1.01 now with added sugar

Going even another step further why couldn't a minimal Class::InsideOut based class is now as easy as this:
package My::Class; use Class::InsideOut qw/ new id public private /; public name; private age; 1;
The age => my %age still seems redundant but kudos on removing a considerable amount of boilerplate!
--
Clayton

Replies are listed 'Best First'.
Re^2: Class::InsideOut 1.01 now with added sugar
by xdg (Monsignor) on Jul 27, 2006 at 22:25 UTC

    Without the lexical hash, it's not an inside-out object. What I left off was actually using the property hashes:

    sub as_string { my $self = shift; return $name{ id $self } . " is " . $age{ id $self } . " year(s) o +ld."; }

    I suppose there's some XS magic that could take a name and create a lexical in the right place, but I'm not an XS expert (yet) and I'm not sure I'd want to add that kind of dependency.

    (Also, in your example those are barewords, so they really should be quoted.)

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      I think you can reduce public name => my %name; to public \my %name; with the aid of PadWalker’s var_name function. Not sure if you want to depend on that module, though… although OTOH it’s probably better than writing the XS for the purpose yourself.

      Makeshifts last the longest.

        I'm having an offline chat with someone about that. I probably would release a separate module that wraps Class::InsideOut for that. Padwalker requires 5.8 and I don't want to put that limitation on Class::InsideOut itself.

        If it works, I'd prefer this syntax:

        public my %name;

        I'm assuming that I can do var_name on \$_[0]. Anyone who's done that for some other evil purpose and can point me at sample/CPAN code, please do. Or if it's impossible, that would be good to know.

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-23 17:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found