CGI-Application-Plugin-REST

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

        * rest_error_mode() handlers receive the value of $@ as a parameter.
        * When the client does not provide an HTTP Accept header, try and
          see if there is a handler for */* before giving 415 error status.

0.2     Fri Oct 15 07:14:00 EDT 2010
        Added a rest_resource() function to create an entire set of routes
        in one go.

0.11    Mon Oct 11 21:33:30 EDT 2010
        Added C::A::P::DevPopup to the build requirements as it is
        needed for t/devpopup.t.

0.1     Sun Oct 10 04:57:56 EDT 2010
        First version, released on an unsuspecting world.

MANIFEST  view on Meta::CPAN

Build.PL
Changes
LICENSE
MANIFEST
MANIFEST.SKIP
README
lib/CGI/Application/Plugin/REST.pm
t/00-signature.t
t/01-load.t
t/devpopup.t
t/param.t
t/resource.t
t/routes.t
t/lib/Test/CAPREST.pm
t/lib/Test/CAPRESTNoPopup.pm
t/lib/Test/CAPRESTPopup.pm
t/lib/Test/CAPRESTResource.pm
Makefile.PL
META.yml
META.json

SIGNATURE  view on Meta::CPAN

SHA1 0001e963311ff99f09e0bed164e1611c279136f9 LICENSE
SHA1 057914495bf31ff76a1d3ffb369f7ed89d9ed218 MANIFEST
SHA1 43acd2b351bfcd25a12cbfd8494c1195db3d2eea MANIFEST.SKIP
SHA1 ad5fdcc5786a6fc77a0e40291d32959b299fa9aa META.json
SHA1 eb12863b30f34ccaa13054ed0a19438c80e7eb1e META.yml
SHA1 8f504ae3028a9be37749f10583da08a2819275cf Makefile.PL
SHA1 22755174124562fc10bb6436216cc4360c717ec7 README
SHA1 13a3b8f886be2585b6e68e33031e810319cd83c1 lib/CGI/Application/Plugin/REST.pm
SHA1 8a0a63e135ba8bcbab4744aab395fe27faf537a7 t/00-signature.t
SHA1 d2ce9f93ca2d8864927541b93b9867cc5a486c28 t/01-load.t
SHA1 2db9863b34a3e01834baae77f9658b160f3d7444 t/devpopup.t
SHA1 eaa9d6d9e187a52740d3861a3cd2021325af43b6 t/lib/Test/CAPREST.pm
SHA1 787bd75ded3ca3e17aa9e959b9d28f5d41ff8809 t/lib/Test/CAPRESTNoPopup.pm
SHA1 da09e4a45696f07217ad5ad9e6fb797de863da6d t/lib/Test/CAPRESTPopup.pm
SHA1 5dc0eda4664a759aa7845ef57e26b955665ff1be t/lib/Test/CAPRESTResource.pm
SHA1 4527a213140cd876a66d972aa62c46b1260291ab t/param.t
SHA1 195284eeea1bcaaf7829d369deb24df62d2feaf6 t/resource.t
SHA1 d7f56841bfbc676b851966e214f9a002cf0e064d t/routes.t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

lib/CGI/Application/Plugin/REST.pm  view on Meta::CPAN

    $caller->add_callback(
        'init',
        sub {
            my ($self) = @_;
            $self->mode_param( \&_rest_dispatch );

            return;
        }
    );
    if ( exists $ENV{'CAP_DEVPOPUP_EXEC'} ) {
        $caller->add_callback( 'devpopup_report', \&_rest_devpopup );
    }
    goto &Exporter::import;
}

# Callback for CGI::Application::Plugin::DevPopup which provides debug info.
#
sub _rest_devpopup {
    my ( $self, $outputref ) = @_;

    my $report = "<table>\n";
    foreach my $key ( sort keys %{ $self->{'__r_params'} } ) {
        my $name = $key;
        $name =~ s/_/ /gmsx;
        $report .= join q{},
          (
            "<tr><td>$name: </td>",        '<td colspan="2">',
            $self->{'__r_params'}->{$key}, "</td></tr>\n"

lib/CGI/Application/Plugin/REST.pm  view on Meta::CPAN

        }
        $report .= join q{},
          (
            qq{<td>$param: </td><td>},
            rest_param( $self, $param ),
            "</td></tr>\n"
          );
    }
    $report .= "</table>\n";

    $self->devpopup->add_report(
        title   => 'CGI::Application::Plugin::REST',
        summary => 'Information on the current REST dispatch',
        report  => $report,
    );

    return;
}

# mode_param() callback to set the run mode based on the request URI.
#

t/devpopup.t  view on Meta::CPAN

#!/usr/bin/perl

# Test _rest_devpopup
use strict;
use warnings;
use English qw( -no_match_vars );
use Test::LongString max => 5000;
use Test::More tests => 2;
use Test::WWW::Mechanize::CGIApp;
use lib 't/lib';
use Test::CAPRESTPopup;
use Test::CAPRESTNoPopup;

t/devpopup.t  view on Meta::CPAN

	"<tr><td>path received: </td><td colspan=\"2\">/foo/alpha/beta/gamma/</td></tr>\n" + 
	"<tr><td>rule matched: </td><td colspan=\"2\">/foo/:one/:two/:three/</td></tr>\n" + 
	"<tr><td>runmode: </td><td colspan=\"2\">doop</td></tr>\n" + 
	"<tr><td rowspan=\"3\">parameters: </td><td>one: </td><td>alpha</td></tr>\n" + 
	"<tr><td>three: </td><td>gamma</td></tr>\n" + 
	"<tr><td>two: </td><td>beta</td></tr>\n" + 
	"</table>\n" + 
EOT

$mech1->get('http://localhost/foo/alpha/beta/gamma/');
contains_string($mech1->content, $expected1, 'devpopup');

my $mech2 = Test::WWW::Mechanize::CGIApp->new;

$mech2->add_header(Accept => '*/*;q=1.0');
$mech2->app(
    sub {
        my $app = Test::CAPRESTNoPopup->new;
        $app->run();
    }
);

my $expected2 = qq{<body>

</body>
};


$mech2->get('http://localhost/bar');
contains_string($mech2->content, $expected2, 'without devpopup');

t/lib/Test/CAPRESTNoPopup.pm  view on Meta::CPAN

    return;
}

sub doop {
    my ($self) = @_;

    my $q = $self->query;

    no warnings;
    return $q->start_html(q{}) .
        CGI::Application::Plugin::REST::_rest_devpopup($self) .
        $q->end_html;
}

1;

t/lib/Test/CAPRESTPopup.pm  view on Meta::CPAN

    my ($self) = @_;

    $self->rest_route('/foo/:one/:two/:three/' => 'doop');

    return;
}

sub doop {
    my ($self) = @_;

    return CGI::Application::Plugin::REST::_rest_devpopup($self);
}

1;

t/param.t  view on Meta::CPAN

#!/usr/bin/perl

# Test rest_param.  t/devpopup.t also tests some rest_param functionality.
use strict;
use warnings;
use English qw( -no_match_vars );
use Test::More tests => 3;
use lib 't/lib';
use Test::CAPREST;

my $app = Test::CAPREST->new;

my %params = (



( run in 1.503 second using v1.01-cache-2.11-cpan-364913b4093 )