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 # Fix for stupid components
16 *new = \&Catalyst::Component::new;
18 sub _DISPATCH : Private {
19 my ( $self, $c ) = @_;
21 foreach my $disp ( @{ $self->_dispatch_steps } ) {
22 last unless $c->forward($disp);
28 sub _BEGIN : Private {
29 my ( $self, $c ) = @_;
30 my $begin = ( $c->get_actions( 'begin', $c->namespace ) )[-1];
31 return 1 unless $begin;
33 return !@{ $c->error };
37 my ( $self, $c ) = @_;
38 my @auto = $c->get_actions( 'auto', $c->namespace );
39 foreach my $auto (@auto) {
41 return 0 unless $c->state;
46 sub _ACTION : Private {
47 my ( $self, $c ) = @_;
48 $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 };
60 sub action_namespace {
61 my ( $self, $c ) = @_;
62 return Catalyst::Utils::class2prefix( ref $self,
63 $c->config->{case_sensitive} )
67 sub register_actions {
68 my ( $self, $c ) = @_;
69 my $class = ref $self || $self;
70 my $namespace = $self->action_namespace($c);
72 $methods{ $self->can($_) } = $_
73 for @{ Class::Inspector->methods($class) || [] };
75 # Advanced inheritance support for plugins and the like
79 for my $isa ( @{"$class\::ISA"}, $class ) {
80 push @action_cache, @{ $isa->_action_cache }
81 if $isa->can('_action_cache');
85 foreach my $cache (@action_cache) {
86 my $code = $cache->[0];
87 my $method = $methods{$code};
89 my $attrs = $self->_parse_attrs( @{ $cache->[1] } );
90 if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
91 $c->log->debug( 'Bad action definition "'
92 . join( ' ', @{ $cache->[1] } )
93 . qq/" for "$class->$method"/ )
97 my $reverse = $namespace ? "$namespace/$method" : $method;
98 my $action = Catalyst::Action->new(
103 namespace => $namespace,
105 attributes => $attrs,
108 $c->dispatcher->register( $c, $action );
113 my ( $self, @attrs ) = @_;
115 foreach my $attr (@attrs) {
117 # Parse out :Foo(bar) into Foo => bar etc (and arrayify)
119 if ( my ( $key, $value ) = ( $attr =~ /^(.*?)(?:\(\s*(.+)\s*\))?$/ ) ) {
121 if ( defined $value ) {
122 ( $value =~ s/^'(.*)'$/$1/ ) || ( $value =~ s/^"(.*)"/$1/ );
124 push( @{ $attributes{$key} }, $value );
132 Catalyst::Base - Catalyst Controller Base Class
152 Sebastian Riedel, C<sri@cpan.org>
153 Marcus Ramberg, C<mramberg@cpan.org>
154 Matt S Trout, C<mst@shadowcatsystems.co.uk>
158 This program is free software, you can redistribute it and/or modify it under
159 the same terms as Perl itself.