File: parameterized_subtype.t

package info (click to toggle)
libmoox-types-mooselike-perl 0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 192 kB
  • ctags: 14
  • sloc: perl: 492; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,587 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use strict;
use warnings;
use Test::More;
use Test::Fatal;

BEGIN {
  package Local::TypeLibrary;
  use MooX::Types::MooseLike qw/ exception_message /;
  use MooX::Types::MooseLike::Base qw/ Object AllOf InstanceOf ConsumerOf HasMethods /;
  use Exporter 5.57 'import';
  MooX::Types::MooseLike::register_types([{
        name       => 'Douche',
        subtype_of => AllOf[InstanceOf['Man'], ConsumerOf['Role::Dick'], HasMethods['thought', 'testosterone']],
        from       => 'MooX::Types::MooseLike::Base',
        test       => sub { ($_[0]->testosterone =~ /beaucou/) and ($_[0]->thought < 0.5) },
        message    => sub { return exception_message($_[0], 'a douche') },
      }], __PACKAGE__);
  $INC{'Local/TypeLibrary.pm'} = __FILE__;
}
{
  package Human;
  use Moo;
  use MooX::Types::MooseLike::Base qw/ Num /;
  has thought => (is => 'ro', isa => Num);
}
{ package Woman; use Moo; extends 'Human'; sub sings {}; }
{ package Man;   use Moo; extends 'Human'; sub hunts {}; }
{
  package Role::Dick;
  use Moo::Role;
  sub testosterone { 'beaucoupe' };
}
{
  package Brogrammer;
  use Moo;
  extends 'Man';
  with ('Role::Dick');
}
{
  package MooX::Types::MooseLike::Test;
  use Moo;
  use Local::TypeLibrary qw/Douche/;
  has brogrammer => (
    is  => 'ro',
    isa => Douche,
    );
}

ok(MooX::Types::MooseLike::Test->new(brogrammer => Brogrammer->new(thought => 0)), 'A brogrammer is a douche');
like(
  exception {
    MooX::Types::MooseLike::Test->new(brogrammer => bless {}, 'Elkman');
  },
  qr/is not a douche/,
  'Elk man is not a douche',
  );

done_testing();