forked from tokuhirom/p5-httpx-dispatcher
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge from instance-and-declare branch
git-svn-id: http://svn.coderepos.org/share/lang/perl/HTTPx-Dispatcher/trunk@25653 d0d07461-0603-4401-acd4-de1884942a52
- Loading branch information
masaki
committed
Dec 1, 2008
1 parent
058e2fd
commit 3e38538
Showing
7 changed files
with
120 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package HTTPx::Dispatcher::Declare; | ||
use strict; | ||
use warnings; | ||
use HTTPx::Dispatcher; | ||
use Exporter 'import'; | ||
|
||
our @EXPORT = qw/connect match uri_for dispatcher/; | ||
|
||
my $dispatcher = {}; | ||
sub dispatcher { | ||
my $pkg = shift || caller(1); | ||
return ( $dispatcher->{$pkg} ||= HTTPx::Dispatcher->new ); | ||
} | ||
|
||
sub connect { | ||
my @args = @_; | ||
return dispatcher()->add_rule(@args); | ||
} | ||
|
||
sub match { | ||
my ( $class, $req ) = @_; | ||
return $class->dispatcher()->match($req); | ||
} | ||
|
||
sub uri_for { | ||
my ( $class, @args ) = @_; | ||
return $class->dispatcher()->uri_for(@args); | ||
} | ||
|
||
1; | ||
__END__ | ||
=for stopwords TODO URI uri | ||
=encoding utf8 | ||
=head1 NAME | ||
HTTPx::Dispatcher::Declare - declarative dispatcher | ||
=head1 SYNOPSIS | ||
package Your::Dispatcher; | ||
use HTTPx::Dispatcher::Declare; | ||
connect ':controller/:action/:id'; | ||
package Your::Handler; | ||
use HTTP::Engine; | ||
use Your::Dispatcher; | ||
use UNIVERSAL::require; | ||
HTTP::Engine->new( | ||
'config.yaml', | ||
handle_request => sub { | ||
my $c = shift; | ||
my $rule = Your::Dispatcher->match($c->req); | ||
$rule->{controller}->use or die 'hoge'; | ||
my $action = $rule->{action}; | ||
$rule->{controller}->$action( $c->req ); | ||
} | ||
); | ||
=head1 DESCRIPTION | ||
HTTPx::Dispatcher::Declare is DSL for L<HTTPx::Dispatcher>. | ||
=head1 AUTHOR | ||
Tokuhiro Matsuno E<lt>tokuhirom@gmail.comE<gt> | ||
=head1 THANKS TO | ||
lestrrat | ||
=head1 SEE ALSO | ||
L<HTTPx::Dispatcher> | ||
=head1 LICENSE | ||
This library is free software; you can redistribute it and/or modify | ||
it under the same terms as Perl itself. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
use strict; | ||
use Test::More tests => 1; | ||
use Test::More tests => 3; | ||
|
||
BEGIN { use_ok 'HTTPx::Dispatcher' } | ||
BEGIN { | ||
use_ok 'HTTPx::Dispatcher'; | ||
use_ok 'HTTPx::Dispatcher::Rule'; | ||
use_ok 'HTTPx::Dispatcher::Declare'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters