Catalyst::Dispatcher

いったんメモ

sub new {
    my $self  = shift;
    my $class = ref($self) || $self;

    my $obj = $class->SUPER::new(@_);

    # set the default pre- and and postloads
    $obj->preload_dispatch_types( \@PRELOAD );
    $obj->postload_dispatch_types( \@POSTLOAD );
    $obj->action_hash(    {} );
    $obj->container_hash( {} );

    # Create the root node of the tree
    my $container =
      Catalyst::ActionContainer->new( { part => '/', actions => {} } );
    $obj->tree( Tree::Simple->new( $container, Tree::Simple->ROOT ) );

    return $obj;
}
sub dispatch {
    my ( $self, $c ) = @_;
    if ( $c->action ) {
        $c->forward( join( '/', '', $c->action->namespace, '_DISPATCH' ) );
    }

    else {
        my $path  = $c->req->path;
        my $error = $path
          ? qq/Unknown resource "$path"/
          : "No default action defined";
        $c->log->error($error) if $c->debug;
        $c->error($error);
    }
}