Acme-Chef
view release on metacpan or search on metacpan
lib/Acme/Chef.pm view on Meta::CPAN
my $self = {};
bless $self => $class;
my @paragraphs = $self->_get_paragraphs( $code );
my @recipes = $self->_paragraphsToRecipes(\@paragraphs);
$_->compile() foreach @recipes;
$self->{start_recipe} = $recipes[0]->recipe_name();
$self->{recipes} = {
map { ($_->recipe_name(), $_) } @recipes
};
return $self;
}
=item execute
Takes no arguments. Runs the program and returns its output.
=cut
sub execute {
my $self = shift;
my $start_recipe = $self->{recipes}->{ $self->{start_recipe} }->new();
$start_recipe->execute($self->{recipes});
return $start_recipe->output();
}
=item dump
Takes one optional argument. If it equals 'autorun',
dump returns a string that, when evaluated, executes
the program and returns the output.
If the argument does not equal 'autorun', a different
lib/Acme/Chef.pm view on Meta::CPAN
until it reaches the "until" statement. The value of ingredient is
rechecked. If it is non-zero, the loop executes again. If at any check
the value of ingredient is zero, the loop exits and execution continues
at the statement after the "until". Loops may be nested.
=item *
C<Verb [the ingredient] until verbed.>
This marks the end of a loop. It must appear as a matched pair with the
above statement. verbed must match the Verb in the matching loop start
statement. The Verb in this statement may be arbitrary and is ignored.
If the ingredient appears in this statement, its value is decremented
by 1 when this statement executes. The ingredient does not have to
match the ingredient in the matching loop start statement.
=item *
C<Set aside.>
This causes execution of the innermost loop in which it occurs to end
immediately and execution to continue at the statement after the "until".
=item *
lib/Acme/Chef/Recipe.pm view on Meta::CPAN
push @loop_stack, $verb;
if ( not $self -> {ingredients} -> {$ingr} -> value() ) {
pop @loop_stack;
$exec_pos = $self -> {loops} -> {$verb} -> {end};
}
} elsif ( $return =~ /^endloop\.([^\.]+)/ ) {
my $verb = $1;
$exec_pos = $self -> {loops} -> {$verb} -> {start} - 1;
} elsif ( $return =~ /^break/ ) {
my $verb = pop @loop_stack;
$exec_pos = $self -> {loops} -> {$verb} -> {end};
}
$exec_pos++;
last if $exec_pos > $max_pos;
}
lib/Acme/Chef/Recipe.pm view on Meta::CPAN
$step_no++;
foreach my $grammar (@GrammarOrder) {
my @res = $Grammars{$grammar}->($self, $step);
@res or next;
if ( $res[0] eq 'verb' ) {
my $verb = $res[1];
my $ingr = $res[2];
$self->{loops}->{$verb} = {start => ($step_no-1), test => $ingr};
} elsif ( $res[0] eq 'until_verbed' ) {
my $verb = $res[1];
exists $self->{loops}->{$verb}
or croak "Loop end without loop start '$verb'.";
$self->{loops}->{$verb}->{end} = $step_no - 1;
}
$step = [@res];
last;
}
croak "Invalid method step (step no. $step_no): '$step'."
if not ref $step eq 'ARRAY';
}
if ( grep { not exists $self->{loops}{$_}{end} } keys %{$self->{loops}} ) {
croak "Not all loop starting points have matching ends.";
}
$self->{method} = \@steps;
$self->{compiled} = 1;
return $self;
}
( run in 0.259 second using v1.01-cache-2.11-cpan-0d8aa00de5b )