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

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.

Replies are listed 'Best First'.
Re^3: Class::InsideOut 1.01 now with added sugar
by Aristotle (Chancellor) on Jul 27, 2006 at 22:45 UTC

    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.

        That should work, although I haven’t tested it. And yeah, it’s probably better off in a separate wrapper module. At which point I’d probably switch to a Class:Stdish attribute interface, making it my %name : public; instead.

        Makeshifts last the longest.