1 package Catalyst::Base;
4 use base qw/Catalyst::Component Catalyst::AttrContainer Class::Accessor::Fast/;
6 use Catalyst::Exception;
11 __PACKAGE__->mk_classdata($_) for qw/_dispatch_steps/;
13 __PACKAGE__->_dispatch_steps( [qw/_BEGIN _AUTO _ACTION/] );
15 sub _DISPATCH : Private {
16 my ( $self, $c ) = @_;
18 foreach my $disp ( @{ $self->_dispatch_steps } ) {
19 last unless $c->forward($disp);
25 sub _BEGIN : Private {
26 my ( $self, $c ) = @_;
27 my $begin = ( $c->get_actions( 'begin', $c->namespace ) )[-1];
28 return 1 unless $begin;
30 return !@{ $c->error };
34 my ( $self, $c ) = @_;
35 my @auto = $c->get_actions( 'auto', $c->namespace );
36 foreach my $auto (@auto) {
38 return 0 unless $c->state;
43 sub _ACTION : Private {
44 my ( $self, $c ) = @_;
45 $c->action->execute($c);
46 return !@{ $c->error };
50 my ( $self, $c ) = @_;
51 my $end = ( $c->get_actions( 'end', $c->namespace ) )[-1];
54 return !@{ $c->error };
57 sub action_namespace {
58 my ( $self, $c ) = @_;
59 return Catalyst::Utils::class2prefix( ref $self,
60 $c->config->{case_sensitive} )
64 sub register_actions {
65 my ( $self, $c ) = @_;
66 my $class = ref $self || $self;
67 my $namespace = $self->action_namespace($c);
69 $methods{ $self->can($_) } = $_
70 for @{ Class::Inspector->methods($class) || [] };
72 # Advanced inheritance support for plugins and the like
76 for my $isa ( @{"$class\::ISA"}, $class ) {
77 push @action_cache, @{ $isa->_action_cache }
78 if $isa->can('_action_cache');
82 foreach my $cache (@action_cache) {
83 my $code = $cache->[0];
84 my $method = $methods{$code};
86 my $attrs = $self->_parse_attrs( @{ $cache->[1] } );
87 if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
88 $c->log->debug( 'Bad action definition "'
89 . join( ' ', @{ $cache->[1] } )
90 . qq/" for "$class->$method"/ )
94 my $reverse = $namespace ? "$namespace/$method" : $method;
95 my $action = Catalyst::Action->new(
100 namespace => $namespace,
102 attributes => $attrs,
105 $c->dispatcher->register( $c, $action );
110 my ( $self, @attrs ) = @_;
112 foreach my $attr (@attrs) {
114 # Parse out :Foo(bar) into Foo => bar etc (and arrayify)
116 if ( my ( $key, $value ) = ( $attr =~ /^(.*?)(?:\(\s*(.+)\s*\))?$/ ) ) {
118 if ( defined $value ) {
119 ( $value =~ s/^'(.*)'$/$1/ ) || ( $value =~ s/^"(.*)"/$1/ );
121 push( @{ $attributes{$key} }, $value );
129 Catalyst::Base - Catalyst Controller Base Class
149 Sebastian Riedel, C<sri@cpan.org>
150 Marcus Ramberg, C<mramberg@cpan.org>
151 Matt S Trout, C<mst@shadowcatsystems.co.uk>
155 This program is free software, you can redistribute it and/or modify it under
156 the same terms as Perl itself.