File: 21-can.t

package info (click to toggle)
libparams-validate-perl 0.76-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 316 kB
  • ctags: 214
  • sloc: perl: 2,230; makefile: 36
file content (51 lines) | stat: -rw-r--r-- 736 bytes parent folder | download
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
#!/usr/bin/perl -w

use strict;

use Params::Validate qw(validate);
use Test::More tests => 3;

{
    my @p = ( foo => 'ClassCan' );

    eval
    {
        validate( @p,
                  { foo => { can => 'cancan' } },
                );
    };

    ok( ! $@ );

    eval
    {
        validate( @p,
                  { foo => { can => 'thingy' } },
                );
    };

    like( $@, qr/does not have the method: 'thingy'/ );
}

{
    my @p = ( foo => undef );
    eval
    {
        validate( @p,
                  { foo => { can => 'baz' } },
                );
    };

    like( $@, qr/does not have the method: 'baz'/ );
}


package ClassCan;

sub can
{
    return 1 if $_[1] eq 'cancan';
    return 0;
}

sub thingy { 1 }