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.
Not to pimp my own module or anything, but... (Score:1)
instead. It has its limitations: there is no slice syntax, because I haven't decided whether
$foo->{bar}[][1, 2, 3]is too weird or not yet, and because it's somewhat trickier to implement; and it doesn't allow a direct deref$foo->[]due to the optimizer not getting run on the ops involved.It doesn't use a source filter, instead it h
list as object (Score:1)
That would be List::oo.
But Class::Accessor::Classy should do what you want without even needing to write the add_args() method.
Re: (Score:2)
List::oo does look very similar to what I want, except that I want is simply to have all the the ease of use of objects for arrays and hashes (maybe scalars?) without the messiness. Also, by using nicely de-coupled functions to build things, I wouldn't have to "buy into" a particular object system. This would work with Moose as well as with hand-rolled code (which is why Class::Accessor::Classy doesn't seem like the right fit for me).
Re: (Score:1)
"All the ease of use of objects without the messiness"? What's the messy part? List::oo blesses an arrayref, so you're never far from punching through the abstraction. If the constructor is the messy part, then you have L().
Or do you mean cognitive messiness? Abstraction layers do tend to be abstract, and everything's a waterbed, so...
As for object systems - C::A::Classy really isn't much of one. And that is intentional. I'm not sure what the benefit of de-coupling is supposed to be - you get to write
You need Perl 6 now? (Score:1)
You’re saying it’d be easier to port your codebase to Perl 6 than to upgrade your perl to a version that supports autobox [cpan.org]? :-)
Re: (Score:2)
Except that if I distribute modules, I want to minimize the dependencies. How many times have people failed to install a module because they don't like the the number of dependencies, have an aversion to a particular dependency or can't risk upgrading a particular dependency? The dependency problem is a very real one in Perl 5 and suggesting (admittedly sexy) XS code to solve this problem seems like overkill :)
A very tiny, lightweight embeddable utility would be nice here (yes, there's the risk of duplica
Moose (Score:1)
Ya do know that Moose + MooseX::AttributeHelpers would abstract away all that code you wrote, right?
Boxing is nice, but not really what you need for your example.
Anyway, here's the same code with Moose:
package Stuff;
use Moose;
use MooseX::AttributeHelpers;
has args => (
is => 'ro',
isa => 'ArrayRef',
metaclass => 'Collection::Array',
auto_deref => 1,
Re: (Score:1)
more Moose (Score:1)
use Moose::Autobox (); # don't actually autobox
sub new {
my ($class, @args) = @_;
bless {
args =>
# this is the class that autoboxing would use anyway
bless \@args => 'Moose::Autobox::ARRAY',
} => $class;
}
sub add_args {
my $self = shift;
$self->{args}->push(@_); # NOT UGLY!!!
}
# Likewise, use Moose::Autobox::HASH for hashes.