Catalyst-ControllerRole-At

 view release on metacpan or  search on metacpan

t/at.t  view on Meta::CPAN

  sub places :Via($up/people) :At($path_end/{name:Str}?{p=11:Int}{?rows:Int}) {
    $_->res->body($_{p}.($_{rows}||'na'));
  }


  package MyApp::Controller::User::Records;
  $INC{'MyApp/Controller/User/Records.pm'} = __FILE__;

  use Moose;
  use MooseX::MethodAttributes;
  use Types::Standard qw/Int Str/;

  extends 'Catalyst::Controller';
  with 'Catalyst::ControllerRole::At';

  sub global :At(/global/{}/{}) {
    my ($self, $c, $arg1, $arg2) = @_;
  }

  sub int :At(/int/{:Int}) {
    my ($self, $c, $arg1, $arg2) = @_;
  }

  sub int2 :At(/int/{:Int}/{str:Str}) {
    my ($self, $c, $arg1, $arg2) = @_;
    $_->res->body($_{str});
  }

  sub controller :At($controller/aaa/{:Int}/{name:Str}) {
    my ($self, $c, $arg1, $arg2) = @_;
    $_->res->body($_{name});
  }

  sub me :At($action/{id:Int}/) {
    my ($self, $c, $arg1) = @_;
    $_->res->body($_{id});
  }

  sub this :At($name/{*}/) {
    my ($self, $c, @args) = @_;
    $c->res->body(join ',',@args);
  }

  sub up :At($up/aaa/{:Int}/{name:Str}) {
    my ($self, $c, $arg1, $arg2) = @_;
    $_->res->body($_{name});
  }

  sub parent :At($parent/{id:Int}/) {
    my ($self, $c, $arg1) = @_;
    $_->res->body($_{id});
  }

  package MyApp;
  use Catalyst;

  MyApp->setup;
}

use Test::Most;
use HTTP::Request::Common;
use Catalyst::Test 'MyApp';

{
  ok my $res = request GET "/role/999";
  is $res->code, 200;
  is $res->content, '999';
}

{
  ok my $res = request GET "/user/parent/100";
  is $res->code, 200;
  is $res->content, '100';
}

{
  ok my $res = request GET "/user/aaa/100/john";
  is $res->code, 200;
  is $res->content, 'john';
}

{
  ok my $res = request GET "/this/1/2/3/4";
  is $res->code, 200;
  is $res->content, '1,2,3,4';
}

{
  ok my $res = request GET "/this/200";
  is $res->code, 200;
  is $res->content, '200';
}

{
  ok my $res = request GET "/user/records/me/100";
  is $res->code, 200;
  is $res->content, '100';
}

{
  ok my $res = request GET "/user/records/aaa/100/john";
  is $res->code, 200;
  is $res->content, 'john';
}

{
  ok my $res = request GET "/global/1/2";
  is $res->code, 200;
}

{
  ok my $res = request GET "/int/100";
  is $res->code, 200;
}
  
{
  ok my $res = request GET "/int/xxx";
  is $res->code, 400;
}

{



( run in 1.069 second using v1.01-cache-2.11-cpan-39bf76dae61 )