File: 06-options.t

package info (click to toggle)
libparams-validate-perl 0.91-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 524 kB
  • ctags: 729
  • sloc: perl: 2,596; makefile: 52
file content (43 lines) | stat: -rw-r--r-- 661 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
use strict;
use warnings;

use File::Spec;
use lib File::Spec->catdir( 't', 'lib' );

use PVTests;
use Test::More tests => 4;

use Params::Validate qw(:all);


validation_options( stack_skip => 2 );

sub foo
{
    my %p = validate(@_, { bar => 1 });
}

sub bar { foo(@_) }

sub baz { bar(@_) }

eval { baz() };

like( $@, qr/mandatory.*missing.*call to main::bar/i );

validation_options( stack_skip => 3 );

eval { baz() };
like( $@, qr/mandatory.*missing.*call to main::baz/i );

validation_options
    ( on_fail => sub { die bless { hash => 'ref' }, 'Dead' } );

eval { baz() };

my $e = $@;
is( $e->{hash}, 'ref' );
ok( eval { $e->isa( 'Dead' ); 1; } );