Catalyst::Plugin::Server::JSONRPC::DispatchType::JSONRPCRegex - JSONRPCRegex DispatchType


Catalyst-Plugin-Server-JSONRPC documentation Contained in the Catalyst-Plugin-Server-JSONRPC distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::Server::JSONRPC::DispatchType::JSONRPCRegex - JSONRPCRegex DispatchType

SYNOPSIS

Top

See Catalyst.

DESCRIPTION

Top

METHODS

Top

$self->list($c)

Generates a nice debug-table containing the JSONRPCRegex methods.

$self->register( $c, $action )

Registers the JSONRPCPath actions into the dispatcher

AUTHOR

Top

Sergey Nosenko darknos@cpan.org

BASED ON

Top

Catalyst::Plugin::Server::JSONRPC::DispatchType::JSONRPCRegex of

Michiel Ootjers michiel@cpan.org Jos Boumans, kane@cpan.org

COPYRIGHT

Top


Catalyst-Plugin-Server-JSONRPC documentation Contained in the Catalyst-Plugin-Server-JSONRPC distribution.
package Catalyst::Plugin::Server::JSONRPC::DispatchType::JSONRPCRegex;

use strict;
use base qw/Catalyst::DispatchType::Regex/;
use Text::SimpleTable;

sub list {
    my ( $self, $c ) = @_;
    my $re = Text::SimpleTable->new( [ 36, 'JSONRPCRegex' ], [ 37, 'Private' ] );
    for my $regex ( @{ $self->{_compiled} } ) {
        my $action = $regex->{action};
        $re->row( $regex->{path}, "/$action" );
    }
    $c->log->debug( "Loaded JSONRPCRegex actions:\n" . $re->draw )
      if ( @{ $self->{_compiled} } );
}

sub register {
    my ( $self, $c, $action ) = @_;
    my $attrs = $action->attributes;
    my @register = map { @{ $_ || [] } } @{$attrs}{
                                            'JSONRPCRegex',
                                            'JSONRPCRegexp'
                                        };
    foreach
      my $r ( map { @{ $_ || [] } } @{$attrs}{
                                        'JSONRPCLocalRegex',
                                        'JSONRPCLocalRegexp'
                                    }
            )
    {
        unless ( $r =~ s/^\^// ) { $r = "(?:.*?)$r"; }
        push( @register, '^' . $action->namespace . '/' . $r );
    }

    foreach my $r (@register) {
        $self->register_path( $c, $r, $action );
        $self->register_regex( $c, $r, $action );
    }
    return 1 if @register;
    return 0;
}



1;