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 _action_class/;
13 __PACKAGE__->_dispatch_steps( [qw/_BEGIN _AUTO _ACTION/] );
14 __PACKAGE__->_action_class('Catalyst::Action');
16 sub _DISPATCH : Private {
17 my ( $self, $c ) = @_;
19 foreach my $disp ( @{ $self->_dispatch_steps } ) {
20 last unless $c->forward($disp);
26 sub _BEGIN : Private {
27 my ( $self, $c ) = @_;
28 my $begin = ( $c->get_actions( 'begin', $c->namespace ) )[-1];
29 return 1 unless $begin;
31 return !@{ $c->error };
35 my ( $self, $c ) = @_;
36 my @auto = $c->get_actions( 'auto', $c->namespace );
37 foreach my $auto (@auto) {
39 return 0 unless $c->state;
44 sub _ACTION : Private {
45 my ( $self, $c ) = @_;
46 if ( ref $c->action && $c->action->isa('Catalyst::Action') ) {
47 $c->action->execute($c);
49 return !@{ $c->error };
53 my ( $self, $c ) = @_;
54 my $end = ( $c->get_actions( 'end', $c->namespace ) )[-1];
57 return !@{ $c->error };
62 Catalyst::Base - Catalyst Base Class
76 =item $self->action_namespace($c)
80 sub action_namespace {
81 my ( $self, $c ) = @_;
82 return Catalyst::Utils::class2prefix( ref $self,
83 $c->config->{case_sensitive} )
87 =item $self->register_actions($c)
91 sub register_actions {
92 my ( $self, $c ) = @_;
93 my $class = ref $self || $self;
94 my $namespace = $self->action_namespace($c);
96 $methods{ $self->can($_) } = $_
97 for @{ Class::Inspector->methods($class) || [] };
99 # Advanced inheritance support for plugins and the like
103 for my $isa ( @{"$class\::ISA"}, $class ) {
104 push @action_cache, @{ $isa->_action_cache }
105 if $isa->can('_action_cache');
109 foreach my $cache (@action_cache) {
110 my $code = $cache->[0];
111 my $method = $methods{$code};
113 my $attrs = $self->_parse_attrs( @{ $cache->[1] } );
114 if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
115 $c->log->debug( 'Bad action definition "'
116 . join( ' ', @{ $cache->[1] } )
117 . qq/" for "$class->$method"/ )
121 my $reverse = $namespace ? "$namespace/$method" : $method;
122 my $action = $self->_action_class->new(
127 namespace => $namespace,
129 attributes => $attrs,
132 $c->dispatcher->register( $c, $action );
137 my ( $self, @attrs ) = @_;
139 foreach my $attr (@attrs) {
141 # Parse out :Foo(bar) into Foo => bar etc (and arrayify)
143 if ( my ( $key, $value ) = ( $attr =~ /^(.*?)(?:\(\s*(.+?)\s*\))?$/ ) )
146 if ( defined $value ) {
147 ( $value =~ s/^'(.*)'$/$1/ ) || ( $value =~ s/^"(.*)"/$1/ );
149 push( @{ $attributes{$key} }, $value );
159 L<Catalyst>, L<Catalyst::Controller>.
163 Sebastian Riedel, C<sri@cpan.org>
164 Marcus Ramberg, C<mramberg@cpan.org>
165 Matt S Trout, C<mst@shadowcatsystems.co.uk>
169 This program is free software, you can redistribute it and/or modify it under
170 the same terms as Perl itself.