« blib/lib/Catalyst/Plugin/Server/JSONRPC/DispatchType/JSONRPCPath.pm
↑ Summary
blib/lib/JSON/RPC/Common/Marshal/Catalyst.pm »
| 1 | package Catalyst::Plugin::Server::JSONRPC::DispatchType::JSONRPCRegex; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw/Catalyst::DispatchType::Regex/; | ||
| 5 | use Text::SimpleTable; | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Catalyst::Plugin::Server::JSONRPC::DispatchType::JSONRPCRegex - JSONRPCRegex DispatchType | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | See L<Catalyst>. | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | =head1 METHODS | ||
| 18 | |||
| 19 | =head2 $self->list($c) | ||
| 20 | |||
| 21 | Generates a nice debug-table containing the JSONRPCRegex methods. | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | sub list { | ||
| 26 | my ( $self, $c ) = @_; | ||
| 27 | my $re = Text::SimpleTable->new( [ 36, 'JSONRPCRegex' ], [ 37, 'Private' ] ); | ||
| 28 | for my $regex ( @{ $self->{_compiled} } ) { | ||
| 29 | my $action = $regex->{action}; | ||
| 30 | $re->row( $regex->{path}, "/$action" ); | ||
| 31 | } | ||
| 32 | $c->log->debug( "Loaded JSONRPCRegex actions:\n" . $re->draw ) | ||
| 33 | if ( @{ $self->{_compiled} } ); | ||
| 34 | } | ||
| 35 | |||
| 36 | =head2 $self->register( $c, $action ) | ||
| 37 | |||
| 38 | Registers the JSONRPCPath actions into the dispatcher | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | sub register { | ||
| 43 | my ( $self, $c, $action ) = @_; | ||
| 44 | my $attrs = $action->attributes; | ||
| 45 | my @register = map { @{ $_ || [] } } @{$attrs}{ | ||
| 46 | 'JSONRPCRegex', | ||
| 47 | 'JSONRPCRegexp' | ||
| 48 | }; | ||
| 49 | foreach | ||
| 50 | my $r ( map { @{ $_ || [] } } @{$attrs}{ | ||
| 51 | 'JSONRPCLocalRegex', | ||
| 52 | 'JSONRPCLocalRegexp' | ||
| 53 | } | ||
| 54 | ) | ||
| 55 | { | ||
| 56 | unless ( $r =~ s/^\^// ) { $r = "(?:.*?)$r"; } | ||
| 57 | push( @register, '^' . $action->namespace . '/' . $r ); | ||
| 58 | } | ||
| 59 | |||
| 60 | foreach my $r (@register) { | ||
| 61 | $self->register_path( $c, $r, $action ); | ||
| 62 | $self->register_regex( $c, $r, $action ); | ||
| 63 | } | ||
| 64 | return 1 if @register; | ||
| 65 | return 0; | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | =head1 AUTHOR | ||
| 71 | |||
| 72 | Sergey Nosenko C<darknos@cpan.org> | ||
| 73 | |||
| 74 | =head1 BASED ON | ||
| 75 | |||
| 76 | Catalyst::Plugin::Server::JSONRPC::DispatchType::JSONRPCRegex of | ||
| 77 | |||
| 78 | Michiel Ootjers C<michiel@cpan.org> | ||
| 79 | Jos Boumans, C<kane@cpan.org> | ||
| 80 | |||
| 81 | =head1 COPYRIGHT | ||
| 82 | |||
| 83 | This program is free software, you can redistribute it and/or modify it under | ||
| 84 | the same terms as Perl itself. | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | 1; |