Catalyst-Runtime

 view release on metacpan or  search on metacpan

t/arg_constraints.t  view on Meta::CPAN

use warnings;
use strict;
use HTTP::Request::Common;
use utf8;

BEGIN {
  use Test::More;
  eval "use Type::Tiny 1.000005; 1" || do {
    plan skip_all => "Trouble loading Type::Tiny and friends => $@";
  };
}

BEGIN {
  package MyApp::Types;
  $INC{'MyApp/Types.pm'} = __FILE__;

  use strict;
  use warnings;

  use Type::Utils -all;
  use Types::Standard -types;
  use Type::Library
   -base,
   -declare => qw( UserId Heart User ContextLike );

  extends "Types::Standard";

  class_type User, { class => "MyApp::Model::User::user" };
  duck_type ContextLike, [qw/model/];

  declare UserId,
   as Int,
   where { $_ < 5 };

  declare Heart,
   as Str,
   where { $_ eq '♥' };

  # Tests using this are skipped pending deeper thought
  coerce User,
   from ContextLike,
     via { $_->model('User')->find( $_->req->args->[0] ) };
}

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

  use Moose::Role;
  use MooseX::MethodAttributes::Role;
  use MyApp::Types qw/Int Str/;

  sub role_str :Path('role_test') Args(Str) {
    my ($self, $c, $arg) = @_;
    $c->res->body('role_str'.$arg);
  }

  sub role_int :Path('role_test') Args(Int) {
    my ($self, $c, $arg) = @_;
    $c->res->body('role_int'.$arg);
  }

  package MyApp::Model::User;



( run in 2.298 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )