Skip to content

Commit

Permalink
context の引数受け渡しをやめた
Browse files Browse the repository at this point in the history
  • Loading branch information
bonnu committed Mar 9, 2010
1 parent 2d447d4 commit 57a217e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/Encomp/Class/Encompasser.pm
Expand Up @@ -20,7 +20,7 @@ sub operate {
$obj->{context} = $context;
if (my $codes = $hooks->{$self->{path_cached} || $self->get_path}) {
for my $code (@{$codes}) {
$code->($obj, $context, @args);
$code->($obj, @args);
}
}
undef $obj->{context};
Expand Down
21 changes: 13 additions & 8 deletions lib/Encomp/Context.pm
Expand Up @@ -5,14 +5,15 @@ use warnings;
use base qw/Class::Accessor::Fast/;
use Carp qw/croak/;

__PACKAGE__->mk_accessors qw/return skip error _goto/;
__PACKAGE__->mk_accessors qw/return skip _goto/;
#__PACKAGE__->mk_accessors qw/return skip error _goto/;

sub new {
my $class = shift;
$class->SUPER::new({
return => 0,
skip => 0,
errors => [],
# errors => [],
current => undef,
_goto => undef,
});
Expand All @@ -24,7 +25,6 @@ sub current {
$self->{current} = $hook;
return unless $self->{skip};
if ($hook eq $self->{_goto}) {
$self->skip(0);
$self->clear_goto;
}
}
Expand All @@ -48,11 +48,16 @@ sub goto {
}
}

sub clear_goto { undef $_[0]->{_goto} }
sub error_number { scalar @{ $_[0]->errors } }
sub has_error { scalar @{ $_[0]->errors } ? 1 : 0 }
sub add_errors { push @{ shift->errors } => @_ }
sub clear_errors { @{ $_[0]->errors } = () }
sub clear_goto {
my $self = shift;
$self->_goto(undef);
$self->skip(0);
}

#sub error_number { scalar @{ $_[0]->errors } }
#sub has_error { scalar @{ $_[0]->errors } ? 1 : 0 }
#sub add_errors { push @{ shift->errors } => @_ }
#sub clear_errors { @{ $_[0]->errors } = () }

1;

Expand Down
38 changes: 19 additions & 19 deletions t/05_process.t
Expand Up @@ -16,25 +16,25 @@ processes
5 => [qw/ 1 2 3 /],
;

hook_to '/1/1' => sub { my ($self, $ctx) = @_; $self->body('/1/1'); $ctx->goto('/2') };
hook_to '/1/2' => sub { my ($self, $ctx) = @_; $self->body('/1/2'); $ctx->goto('/2/2') };
hook_to '/1/3' => sub { my ($self, $ctx) = @_; $self->body('/1/3'); $ctx->goto('/2/3') };

hook_to '/2/1' => sub { my ($self, $ctx) = @_; $self->body('/2/1'); $ctx->goto('/3') };
hook_to '/2/2' => sub { my ($self, $ctx) = @_; $self->body('/2/2'); $ctx->goto('/3/2') };
hook_to '/2/3' => sub { my ($self, $ctx) = @_; $self->body('/2/3'); $ctx->goto('/3/3') };

hook_to '/3/1' => sub { my ($self, $ctx) = @_; $self->body('/3/1'); $ctx->goto('/4') };
hook_to '/3/2' => sub { my ($self, $ctx) = @_; $self->body('/3/2'); $ctx->goto('/4/2') };
hook_to '/3/3' => sub { my ($self, $ctx) = @_; $self->body('/3/3'); $ctx->goto('/4/3') };

hook_to '/4/1' => sub { my ($self, $ctx) = @_; $self->body('/4/1'); $ctx->goto('/5') };
hook_to '/4/2' => sub { my ($self, $ctx) = @_; $self->body('/4/2'); $ctx->goto('/5/2') };
hook_to '/4/3' => sub { my ($self, $ctx) = @_; $self->body('/4/3'); $ctx->goto('/5/3') };

hook_to '/5/1' => sub { my ($self, $ctx) = @_; $self->body('/5/1'); $ctx->goto('/1/2') };
hook_to '/5/2' => sub { my ($self, $ctx) = @_; $self->body('/5/2'); $ctx->goto('/1/3') };
hook_to '/5/3' => sub { my ($self, $ctx) = @_; $self->body('/5/3') };
hook_to '/1/1' => sub { my $self = shift; $self->body('/1/1'); $self->context->goto('/2') };
hook_to '/1/2' => sub { my $self = shift; $self->body('/1/2'); $self->context->goto('/2/2') };
hook_to '/1/3' => sub { my $self = shift; $self->body('/1/3'); $self->context->goto('/2/3') };
hook_to '/2/1' => sub { my $self = shift; $self->body('/2/1'); $self->context->goto('/3') };
hook_to '/2/2' => sub { my $self = shift; $self->body('/2/2'); $self->context->goto('/3/2') };
hook_to '/2/3' => sub { my $self = shift; $self->body('/2/3'); $self->context->goto('/3/3') };
hook_to '/3/1' => sub { my $self = shift; $self->body('/3/1'); $self->context->goto('/4') };
hook_to '/3/2' => sub { my $self = shift; $self->body('/3/2'); $self->context->goto('/4/2') };
hook_to '/3/3' => sub { my $self = shift; $self->body('/3/3'); $self->context->goto('/4/3') };
hook_to '/4/1' => sub { my $self = shift; $self->body('/4/1'); $self->context->goto('/5') };
hook_to '/4/2' => sub { my $self = shift; $self->body('/4/2'); $self->context->goto('/5/2') };
hook_to '/4/3' => sub { my $self = shift; $self->body('/4/3'); $self->context->goto('/5/3') };
hook_to '/5/1' => sub { my $self = shift; $self->body('/5/1'); $self->context->goto('/1/2') };
hook_to '/5/2' => sub { my $self = shift; $self->body('/5/2'); $self->context->goto('/1/3') };
hook_to '/5/3' => sub { my $self = shift; $self->body('/5/3') };

no Encomp;

Expand Down
6 changes: 3 additions & 3 deletions t/lib/DemoFW.pm
Expand Up @@ -12,18 +12,18 @@ plugins 'DemoFW::Plugin::Response';

hook_to '/initialize' =>
sub {
my ($self, $context, @args) = @_;
my ($self, @args) = @_;
};

hook_to '/main' =>
sub {
my ($self, $context, @args) = @_;
my ($self, @args) = @_;
$self->dispatch;
};

hook_to '/finalize' =>
sub {
my ($self, $context, @args) = @_;
my ($self, @args) = @_;
print $self->headers_out;
print "\n";
print $self->output;
Expand Down

0 comments on commit 57a217e

Please sign in to comment.