Author: jhoblitt Date: Sun Jan 15 15:43:58 2006 New Revision: 11203 Modified: trunk/lib/Parrot/Configure.pm trunk/t/configure/configure.t Log: add Parrot::Configure->add_step() change Parrot::Configure's internal representation of steps to an AoA structure change Parrot::Configure->steps() to return an AoA structure pass any registered parameters to each step's ->runstep() method
Modified: trunk/lib/Parrot/Configure.pm ============================================================================== --- trunk/lib/Parrot/Configure.pm (original) +++ trunk/lib/Parrot/Configure.pm Sun Jan 15 15:43:58 2006 @@ -110,7 +110,9 @@ sub options =item * C<steps()> -Provides a list of registered steps. +Provides a list of registered steps. Where each steps is represented by an +array in the format of C<['stepname', @params]>. Steps are returned in the +order in which they were registered in. Accepts no arguments and returns a list in list context or an arrayref in scalar context. @@ -124,6 +126,25 @@ sub steps return wantarray ? @{$self->{steps}} : $self->{steps}; } +=item * C<add_step()> + +Registers a new step and any parameters that should be passed to it. With the +first parameter being the class name of the step register. All other +parameters are saved and passed to the registered class's C<runstep()> method. + +Accepts a list and returns a L<Parrot::Configure> object. + +=cut + +sub add_step +{ + my ($self, $step, @params) = @_; + + push @{$self->{steps}}, [$step, @params]; + + return $self; +} + =item * C<add_steps()> Registers a new step to be run at the end of the execution queue. @@ -134,11 +155,11 @@ Accepts a list and returns a L<Parrot::C sub add_steps { - my $self = shift; + my ($self, @new_steps) = @_; - my @new_steps = @_; - - push @{$self->{steps}}, @new_steps; + foreach my $step (@new_steps) { + $self->add_step($step); + } return $self; } @@ -147,7 +168,8 @@ sub add_steps Sequentially executes step in the order they were registered. The invoking L<Parrot::Configure> object is passed as the first argument to each steps -C<runstep()> method. +C<runstep()> method followed by any parameters that were registered for that +step. Accepts no arguments and returns a L<Parrot::Configure::Data> object. @@ -161,7 +183,10 @@ sub runsteps $self->options->get(qw(verbose verbose-step ask)); my $n = 0; # step number - foreach my $step ($self->steps) { + foreach my $registered_step ($self->steps) { + my $step = shift @$registered_step; + my @step_params = @$registered_step; + $n++; eval "use $step"; @@ -190,7 +215,12 @@ sub runsteps print "\n", $description, '...'; print "\n" if $verbose && $verbose == 2; - $step->runstep($self); + if (@step_params) { + $step->runstep($self, @step_params); + } else { + $step->runstep($self); + } + my $result = $step->result || 'done'; print "..." if $verbose && $verbose == 2; Modified: trunk/t/configure/configure.t ============================================================================== --- trunk/t/configure/configure.t (original) +++ trunk/t/configure/configure.t Sun Jan 15 15:43:58 2006 @@ -82,7 +82,7 @@ can_ok('Parrot::Configure', qw( my $pc = Parrot::Configure->new; $pc->add_steps(qw(foo::step)); - is_deeply(scalar $pc->steps, [qw(foo::step)], + is_deeply(scalar $pc->steps, [['foo::step']], "->steps() returns the proper list"); } @@ -90,15 +90,12 @@ can_ok('Parrot::Configure', qw( my $pc = Parrot::Configure->new; $pc->add_steps(qw(foo::step bar::step baz::step)); - is_deeply(scalar $pc->steps, [qw(foo::step bar::step baz::step)], + is_deeply(scalar $pc->steps, [['foo::step'], ['bar::step'], ['baz::step']], "->steps() returns the proper list"); } # ->steps() / ->add_step() -SKIP: { - skip "->add_step() is unimplimented", 3; - { my $pc = Parrot::Configure->new; @@ -109,7 +106,7 @@ SKIP: { my $pc = Parrot::Configure->new; $pc->add_step('foo::step'); - is_deeply(scalar $pc->steps, [qw(foo::step)], + is_deeply(scalar $pc->steps, [['foo::step']], "->steps() returns the proper list after ->add_step() w/o args"); } @@ -117,10 +114,9 @@ SKIP: { my $pc = Parrot::Configure->new; $pc->add_step('foo::step', qw(bar baz)); - is_deeply(scalar $pc->steps, [qw(foo::step)], + is_deeply(scalar $pc->steps, [['foo::step', qw(bar baz)]], "->steps() returns the proper list after ->add_step() with args"); } -} # ->runsteps() @@ -187,8 +183,6 @@ SKIP: { "no extra parameters were passed to ->runstep()"); } -SKIP: { - skip "->add_step() is unimplimented", 4; { package test::step::stepparams; @@ -212,12 +206,12 @@ SKIP: { # otherwise runsteps() output will make Test::Harness think this test # failed. print "\n"; - isa_ok($test::step::stepparams::self, 'Parrot::Configure'); + is($test::step::stepparams::self, 'test::step::stepparams', + "->runstep() is called as class method"); isa_ok($test::step::stepparams::conf, 'Parrot::Configure'); cmp_ok($test::step::stepparams::self, 'ne', $test::step::stepparams::conf, '$self and $conf params are not the same object'); - is_deeply([EMAIL PROTECTED]::step::stepparams::conf, [24, qw( bar baz bong ), 42], + is_deeply([EMAIL PROTECTED]::step::stepparams::params, [24, qw( bar baz bong ), 42], "proper additional parameters were passed to ->runstep()"); } -}