Fixed run-on sentence in COPYRIGHT and s/program/library/
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ActionContainer.pm
index 14a2fcc..e8f71fe 100644 (file)
@@ -1,17 +1,5 @@
 package Catalyst::ActionContainer;
 
-use strict;
-use base qw/Class::Accessor::Fast/;
-
-__PACKAGE__->mk_accessors(qw/part actions/);
-
-use overload (
-
-    # Stringify to path part for tree search
-    q{""} => sub { shift->{part} },
-
-);
-
 =head1 NAME
 
 Catalyst::ActionContainer - Catalyst Action Container
@@ -22,33 +10,84 @@ See L<Catalyst>.
 
 =head1 DESCRIPTION
 
-=head1 METHODS
+This is a container for actions. The dispatcher sets up a tree of these
+to represent the various dispatch points in your application.
 
-=over 4
+=cut
 
-=item get_action
+use Moose;
+with 'MooseX::Emulate::Class::Accessor::Fast';
 
-=cut
+has part => (is => 'rw', required => 1);
+has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
+
+around BUILDARGS => sub {
+    my ($next, $self, @args) = @_;
+    unshift @args, 'part' if scalar @args == 1 && !ref $args[0];
+    return $self->$next(@args);
+};
+
+no Moose;
+
+use overload (
+    # Stringify to path part for tree search
+    q{""} => sub { shift->part },
+);
 
 sub get_action {
-    my ( $self, $c, $name ) = @_;
+    my ( $self, $name ) = @_;
     return $self->actions->{$name} if defined $self->actions->{$name};
     return;
 }
 
-=item actions
+sub add_action {
+    my ( $self, $action, $name ) = @_;
+    $name ||= $action->name;
+    $self->actions->{$name} = $action;
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+__END__
+
+=head1 METHODS
+
+=head2 new(\%data | $part)
+
+Can be called with { part => $part, actions => \%actions } for full
+construction or with just a part, which will result in an empty actions
+hashref to be populated via add_action later
+
+=head2 get_action($name)
+
+Returns an action from this container based on the action name, or undef
+
+=head2 add_action($action, [ $name ])
+
+Adds an action, optionally providing a name to override $action->name
+
+=head2 actions
+
+Accessor to the actions hashref, containing all actions in this container.
+
+=head2 part
+
+Accessor to the path part this container resolves to. Also what the container
+stringifies to.
 
-=item part
+=head2 meta
 
-=back
+Provided by Moose
 
-=head1 AUTHOR
+=head1 AUTHORS
 
-Matt S. Trout
+Catalyst Contributors, see Catalyst.pm
 
 =head1 COPYRIGHT
 
-This program is free software, you can redistribute it and/or modify it under
+This library is free software. You can redistribute it and/or modify it under
 the same terms as Perl itself.
 
 =cut