HTTPx::Dispatcher - the uri dispatcher(DEPRECATED)


HTTPx-Dispatcher documentation Contained in the HTTPx-Dispatcher distribution.

Index


Code Index:

NAME

Top

HTTPx::Dispatcher - the uri dispatcher(DEPRECATED)

SYNOPSIS

Top

    package Your::Dispatcher;
    use HTTPx::Dispatcher;

    connect ':controller/:action/:id';

    # in your *.psgi file
    use Plack::Request;
    use Your::Dispatcher;
    use UNIVERSAL::require;

    sub {
        my $req = Plack::Request->new($_[0]);
        my $rule = Your::Dispatcher->match($c->req);
        $rule->{controller}->use or die 'hoge';
        my $action = $rule->{action};
        $rule->{controller}->$action( $c->req );
    };

DESCRIPTION

Top

THIS MODULE WAS NO LONGER MAINTAIN. USE Router::Simple INSTEAD.

AUTHOR

Top

Tokuhiro Matsuno <tokuhirom@gmail.com>

THANKS TO

Top

lestrrat

masaki

SEE ALSO

Top

Plack::Request, HTTP::Engine, Routes

LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


HTTPx-Dispatcher documentation Contained in the HTTPx-Dispatcher distribution.

package HTTPx::Dispatcher;
use strict;
use warnings;
use 5.00800;
our $VERSION = '0.08';
use HTTPx::Dispatcher::Rule;
use Scalar::Util qw/blessed/;
use Carp;
use base qw/Exporter/;

our @EXPORT = qw/connect match uri_for/;

my $rules;

sub connect {
    my $pkg  = caller(0);
    my @args = @_;

    push @{ $rules->{$pkg} }, HTTPx::Dispatcher::Rule->new(@args);
}

sub match {
    my ( $class, $req ) = @_;

    for my $rule ( @{ $rules->{$class} } ) {
        if ( my $result = $rule->match($req) ) {
            return $result;
        }
    }
    return;    # no match.
}

sub uri_for {
    my ( $class, @args ) = @_;

    for my $rule ( @{ $rules->{$class} } ) {
        if ( my $result = $rule->uri_for(@args) ) {
            return $result;
        }
    }
}

1;
__END__