line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Validating.pm 4 2005-01-06 06:22:24Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Daisuke Maki |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Class::Validating; |
7
|
3
|
|
|
3
|
|
75280
|
use strict; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
139
|
|
8
|
3
|
|
|
3
|
|
3040
|
use Class::Data::Inheritable (); |
|
3
|
|
|
|
|
1600
|
|
|
3
|
|
|
|
|
57
|
|
9
|
3
|
|
|
3
|
|
3242
|
use Params::Validate (); |
|
3
|
|
|
|
|
34155
|
|
|
3
|
|
|
|
|
211
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import |
14
|
|
|
|
|
|
|
{ |
15
|
5
|
|
|
5
|
|
7054
|
my $class = shift; |
16
|
5
|
|
|
|
|
17
|
my($package) = caller; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
{ |
19
|
3
|
|
|
3
|
|
27
|
no strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2012
|
|
|
5
|
|
|
|
|
11
|
|
20
|
5
|
|
|
|
|
8
|
my @isa = @{"${package}::ISA"}; |
|
5
|
|
|
|
|
29
|
|
21
|
5
|
50
|
|
|
|
25
|
if (!grep { 'Class::Data::Inheritable' eq $_ } @isa) { |
|
0
|
|
|
|
|
0
|
|
22
|
5
|
|
|
|
|
6
|
@{"${package}::ISA"} = (@isa, 'Class::Data::Inheritable'); |
|
5
|
|
|
|
|
85
|
|
23
|
|
|
|
|
|
|
} |
24
|
5
|
|
|
|
|
12
|
*{"${package}::validate_args"} = \&validate_args; |
|
5
|
|
|
|
|
23
|
|
25
|
5
|
|
|
|
|
25
|
*{"${package}::get_pv_spec"} = \&get_pv_spec; |
|
5
|
|
|
|
|
21
|
|
26
|
5
|
|
|
|
|
8
|
*{"${package}::_get_pv_spec"} = \&_get_pv_spec; |
|
5
|
|
|
|
|
20
|
|
27
|
5
|
|
|
|
|
7
|
*{"${package}::set_pv_spec"} = \&set_pv_spec; |
|
5
|
|
|
|
|
4314
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Hey, use the (slight) evil-ness that we wanted to fix :) |
33
|
|
|
|
|
|
|
my @SetPVSpecValidate = ( |
34
|
|
|
|
|
|
|
{ type => Params::Validate::SCALAR() }, |
35
|
|
|
|
|
|
|
{ type => Params::Validate::HASHREF() | Params::Validate::ARRAYREF() } |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
sub set_pv_spec |
38
|
|
|
|
|
|
|
{ |
39
|
8
|
|
|
8
|
1
|
158
|
my $class = shift; |
40
|
8
|
|
|
|
|
178
|
my($name, $spec) = Params::Validate::validate_pos(@_, @SetPVSpecValidate); |
41
|
|
|
|
|
|
|
|
42
|
8
|
|
|
|
|
30
|
my $method = "pv_spec_$name"; |
43
|
8
|
|
|
|
|
61
|
$class->mk_classdata($method); |
44
|
8
|
|
|
|
|
189
|
$class->$method($spec); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _get_pv_spec |
48
|
|
|
|
|
|
|
{ |
49
|
16
|
|
|
16
|
|
34
|
my($class, $sub) = @_; |
50
|
|
|
|
|
|
|
|
51
|
16
|
|
|
|
|
122
|
my $simple_sub = ($sub =~ /([^:]+)$/)[0]; |
52
|
16
|
|
|
|
|
37
|
my $pv_spec_name = "pv_spec_${simple_sub}"; |
53
|
16
|
|
|
|
|
72
|
my $pv_spec = $class->$pv_spec_name; |
54
|
16
|
|
|
|
|
146
|
return $pv_spec; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my @GetPVSpecValidate = ( |
58
|
|
|
|
|
|
|
{ type => Params::Validate::SCALAR() } |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
sub get_pv_spec |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
63
|
0
|
|
|
|
|
0
|
my($sub) = Params::Validate::validate_pos(@_, @GetPVSpecValidate); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
0
|
|
|
0
|
$class = ref($class) || $class; |
66
|
0
|
|
|
|
|
0
|
return $class->_get_pv_spec("${class}::${sub}"); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my @ValidateArgsValidate = ( |
70
|
|
|
|
|
|
|
{ type => Params::Validate::ARRAYREF() }, |
71
|
|
|
|
|
|
|
{ type => Params::Validate::HASHREF(), optional => 1 } |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
sub validate_args(\@\%) |
74
|
|
|
|
|
|
|
{ |
75
|
16
|
|
|
16
|
1
|
13471
|
my $self = shift; |
76
|
16
|
|
|
|
|
309
|
my($params, $extra_args) = Params::Validate::validate_pos(@_, @ValidateArgsValidate); |
77
|
|
|
|
|
|
|
|
78
|
16
|
|
|
|
|
112
|
my $sub = (caller(1))[3]; |
79
|
|
|
|
|
|
|
|
80
|
16
|
|
|
|
|
64
|
my $pv_spec = $self->_get_pv_spec($sub); |
81
|
16
|
50
|
|
|
|
48
|
if (!$pv_spec) { |
82
|
0
|
|
|
|
|
0
|
require Carp; |
83
|
0
|
|
|
|
|
0
|
Carp::croak("pv_spec for $sub is not defined."); |
84
|
|
|
|
|
|
|
} |
85
|
16
|
|
|
|
|
58
|
my @args = ( |
86
|
|
|
|
|
|
|
spec => $pv_spec, |
87
|
|
|
|
|
|
|
called => $sub, |
88
|
|
|
|
|
|
|
); |
89
|
16
|
100
|
|
|
|
43
|
if (defined $extra_args) { |
90
|
8
|
|
|
|
|
9
|
push @args, %{$extra_args}; |
|
8
|
|
|
|
|
28
|
|
91
|
|
|
|
|
|
|
} |
92
|
16
|
|
|
|
|
34
|
push @args, (params => $params); |
93
|
16
|
|
|
|
|
1911
|
return Params::Validate::validate_with(@args); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |