Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
How about this:
#!/usr/bin/perl use lib 'lib'; use strict; use warnings; use MyHolder; use Moose::Autobox; use Test::More tests => 6; BEGIN { use_ok( 'MyHolder' ); } my $cup_holder = MyHolder->new(); # name $cup_holder->name("cupboard"); is ($cup_holder->name(), "cupboard", "name of cup holder should be cupboard"); # things my @cups = qw(blue green green yellow); $cup_holder->things(\@cups); is ($cup_holder->things->length, 4, "there should be four things in th +e cupboard"); # add an element to the array $cup_holder->things->push("red"); is ($cup_holder->things->length, 5, "there should be five things in th +e cupboard"); # remove the last element from the array my $thing = $cup_holder->things->pop; is ($cup_holder->things->length, 4, "there should be four things in th +e cupboard"); is ($thing, "red", "the cup should be red");
which gives
$ prove -v t/test_holder...... 1..6 ok 1 - use MyHolder; ok 2 - name of cup holder should be cupboard ok 3 - there should be four things in the cupboard ok 4 - there should be five things in the cupboard ok 5 - there should be four things in the cupboard ok 6 - the cup should be red ok All tests successful. Files=1, Tests=6, 3 wallclock secs ( 0.01 usr 0.00 sys + 2.52 cusr + 0.03 csys = 2.56 CPU) Result: PASS
Or you could make 'things' have type Object::Array instead of 'ArrayRef', for similar results but without autoboxing.

In reply to Re: Using ArrayRef data members in Moose by Arunbear
in thread Using ArrayRef data members in Moose by dmorgo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-23 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found