Slash Boxes
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • by jrockway (7171) on 2008.07.13 4:40 (#63880) Journal

    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,
            provides => {
                    push => 'add_args',

    sub BUILDARGS {
              shift; # shift off the invocant
              return { args => \@_ };


        my $foo = Stuff->new(qw/foo bar baz/);
        $foo->add_args(qw/quux gorch/);

        my @args = $foo->args; # foo, bar, baz, quux, gorch

    • BTW, normally I align the => arrows, but use.perl killed the spaces in the <code> block. Yay.