[Bps-public-commit] r12504 - in Prophet/branches/moose: . t

sartak at bestpractical.com sartak at bestpractical.com
Sun May 18 06:06:54 EDT 2008


Author: sartak
Date: Sun May 18 06:06:54 2008
New Revision: 12504

Modified:
   Prophet/branches/moose/   (props changed)
   Prophet/branches/moose/lib/Prophet/Test/Arena.pm
   Prophet/branches/moose/lib/Prophet/Test/Participant.pm
   Prophet/branches/moose/t/generalized_sync_n_merge.t

Log:
 r56279 at onn:  sartak | 2008-05-18 06:06:48 -0400
 Moosify Prophet::Test::Arena


Modified: Prophet/branches/moose/lib/Prophet/Test/Arena.pm
==============================================================================
--- Prophet/branches/moose/lib/Prophet/Test/Arena.pm	(original)
+++ Prophet/branches/moose/lib/Prophet/Test/Arena.pm	Sun May 18 06:06:54 2008
@@ -1,9 +1,28 @@
-use warnings;
-use strict;
-
 package Prophet::Test::Arena;
-use base qw/Class::Accessor/;
-__PACKAGE__->mk_accessors(qw/chickens record_callback history/);
+use Moose;
+use MooseX::AttributeHelpers;
+
+has chickens => (
+    is         => 'rw',
+    isa        => 'ArrayRef[Prophet::Test::Participant]',
+    default    => sub { [] },
+    auto_deref => 1,
+);
+
+has record_callback => (
+    is  => 'rw',
+    isa => 'CodeRef',
+);
+
+has history => (
+    metaclass => 'Collection::Array',
+    is        => 'rw',
+    isa       => 'ArrayRef[ArrayRef]',
+    default   => sub { [] },
+    provides  => {
+        push => 'add_history',
+    },
+);
 
 use Prophet::Test::Participant;
 use Acme::MetaSyntactic;
@@ -25,7 +44,7 @@
             });
     }
     
-    $self->chickens(@chickens);
+    $self->chickens(\@chickens);
 }
 
 sub run_from_yaml {
@@ -63,7 +82,7 @@
 
     for ( @{ $data->{recipe} } ) {
         my ( $name, $action, $args ) = @$_;
-        my ($chicken) = grep { $_->name eq $name } @{ $arena->chickens };
+        my ($chicken) = grep { $_->name eq $name } $arena->chickens;
         if ( $args->{record} ) {
             $args->{record} = $record_map->{ $args->{record} };
         }
@@ -97,7 +116,7 @@
     my $step_name = shift || undef;
     my $step_display = defined($step_name) ? $step_name : "(undef)";
 
-    for my $chicken ( @{ $self->chickens } ) {
+    for my $chicken ($self->chickens) {
 
         diag(" as ".$chicken->name. ": $step_display");
         # walk the arena, noting the type of each value
@@ -112,7 +131,7 @@
 sub dump_state {
     my $self = shift;
     my %state;
-    for my $chicken ( @{ $self->chickens } ) {
+    for my $chicken ($self->chickens) {
         $state{ $chicken->name } = as_user( $chicken->name, sub { $chicken->dump_state } );
     }
     return \%state;
@@ -125,8 +144,8 @@
 
     diag("now syncing all pairs");
 
-    my @chickens_a = shuffle @{ $self->chickens };
-    my @chickens_b = shuffle @{ $self->chickens };
+    my @chickens_a = shuffle $self->chickens;
+    my @chickens_b = shuffle $self->chickens;
 
     foreach my $a (@chickens_a) {
         foreach my $b (@chickens_b) {
@@ -152,7 +171,10 @@
         if $self->record_callback;
 
     # XXX: move to some kind of recorder class and make use of callback
-    push @{ $self->{history} ||= [] }, [ $name, $action, $stored ];
+    $self->add_history([$name, $action, $stored]);
 }
 
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
 1;

Modified: Prophet/branches/moose/lib/Prophet/Test/Participant.pm
==============================================================================
--- Prophet/branches/moose/lib/Prophet/Test/Participant.pm	(original)
+++ Prophet/branches/moose/lib/Prophet/Test/Participant.pm	Sun May 18 06:06:54 2008
@@ -116,7 +116,7 @@
     my $self = shift;
     my $args = shift;
 
-    my $from = $args->{from} ||= ( shuffle( grep { $_->name ne $self->name } @{ $self->arena->chickens } ) )[0]->name;
+    my $from = $args->{from} ||= ( shuffle( grep { $_->name ne $self->name } $self->arena->chickens ) )[0]->name;
 
     $self->record_action( 'sync_from_peer', $args );
 

Modified: Prophet/branches/moose/t/generalized_sync_n_merge.t
==============================================================================
--- Prophet/branches/moose/t/generalized_sync_n_merge.t	(original)
+++ Prophet/branches/moose/t/generalized_sync_n_merge.t	Sun May 18 06:06:54 2008
@@ -36,18 +36,18 @@
 ok( !$err, "There was no error ($err)" );
 my $Test = Test::Builder->new;
 if ( grep { !$_ } $Test->summary ) {
-    my $fname = join( '', sort map { substr( $_->name, 0, 1 ) } @{ $arena->chickens } ) . '.yml';
+    my $fname = join( '', sort map { substr( $_->name, 0, 1 ) } $arena->chickens ) . '.yml';
     diag "test failed... dumping recipe to $fname";
     YAML::Syck::DumpFile(
         $fname,
-        {   chickens => [ map { $_->name } @{ $arena->chickens } ],
+        {   chickens => [ map { $_->name } $arena->chickens ],
             recipe   => $arena->{history}
         }
     );
 }
 
 exit;
-for ( @{ $arena->chickens } ) {
+for ( $arena->chickens ) {
     warn $_->name;
     as_user(
         $_->name,



More information about the Bps-public-commit mailing list