NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Class::MOP Makes This Easy (Score:1)
You should be able to do this in a few minutes with Class::MOP::Class [cpan.org], especially the
create_anon_classmethod.Badger::Class also makes this easy (Score:1)
The code sample you posted is almost there. You just need to create an anonymous package name instead of using
__PACKAGE__. I would simply append the accessor names to the base class, e.g.Object::Anonymous_ding_wong_linesub new {
my $class = shift;
my %args = @_;
my $self = { };
my $name = join('_', $class, keys %args);
for my $arg (keys %args) {
Re: (Score:1)
s/Auto/Anon/ # cut and paste failRe: (Score:1)
The code sample you posted is almost there. You just need to create an anonymous package name instead
Ha! Who woulda' thunk? I wrote that example code off-the-cuff in an attempt to better explain what I wanted. But that's a simple enough change that I'm now tempted to start using it as-is. Any other issues you can think might be lurking in the code?
Re: (Score:1)
I guess some sanity checks on the attribute names would be a good idea...
Data::AsObject (Score:1)
And also (Score:1)
* http://search.cpan.org/dist/Hash-AsObject/ [cpan.org]
* http://search.cpan.org/dist/Squatting/ [cpan.org]
And also:
* http://transfixedbutnotdead.com/2009/09/16/easy-anonymous-objects/ [transfixedbutnotdead.com]
As always there is more than one way|solution|module to do it
Re: (Score:1)
http://search.cpan.org/dist/Squatting/lib/Squatting/H.pm [cpan.org]