line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Validation::Utils; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
3
|
use parent 'Exporter::Tiny'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
47
|
use Data::Validation::Constants qw( EXCEPTION_CLASS TRUE ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
8
|
1
|
|
|
1
|
|
143
|
use Module::Runtime qw( require_module ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
34
|
use Try::Tiny; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
52
|
|
10
|
1
|
|
|
1
|
|
3
|
use Unexpected::Functions qw( is_class_loaded ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( ensure_class_loaded load_class throw ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub ensure_class_loaded ($) { |
15
|
39
|
|
|
39
|
1
|
37
|
my $class = shift; |
16
|
|
|
|
|
|
|
|
17
|
39
|
|
|
39
|
|
174
|
try { require_module( $class ) } catch { throw( $_ ) }; |
|
39
|
|
|
|
|
898
|
|
|
1
|
|
|
|
|
376
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# uncoverable branch true |
20
|
38
|
50
|
|
|
|
3930
|
is_class_loaded( $class ) |
21
|
|
|
|
|
|
|
or throw( 'Class [_1] loaded but package undefined', [ $class ] ); |
22
|
|
|
|
|
|
|
|
23
|
38
|
|
|
|
|
758
|
return TRUE; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub load_class ($$$) { |
27
|
34
|
|
|
34
|
1
|
45
|
my ($proto, $prefix, $class) = @_; $class =~ s{ \A $prefix }{}mx; |
|
34
|
|
|
|
|
172
|
|
28
|
|
|
|
|
|
|
|
29
|
34
|
100
|
|
|
|
79
|
if ('+' eq substr $class, 0, 1) { $class = substr $class, 1 } |
|
3
|
|
|
|
|
8
|
|
30
|
31
|
|
|
|
|
68
|
else { $class = "${proto}::".(ucfirst $class) } |
31
|
|
|
|
|
|
|
|
32
|
34
|
|
|
|
|
51
|
ensure_class_loaded $class; |
33
|
|
|
|
|
|
|
|
34
|
33
|
|
|
|
|
638
|
return $class; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub throw (;@) { |
38
|
50
|
|
|
50
|
1
|
203
|
EXCEPTION_CLASS->throw( @_ ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=pod |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=encoding utf-8 |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 Name |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Data::Validation::Utils - Utility methods for constraints and filters |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 Synopsis |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Data::Validation::Utils qw( ensure_class_loaded ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 Description |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Defines some functions L<Data::Validation::Constraints> and |
60
|
|
|
|
|
|
|
L<Data::Validation::Filters> |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 Configuration and Environment |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Defines no attributes |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 Subroutines/Methods |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 ensure_class_loaded |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Throws if class cannot be loaded |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 load_class |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Load the external plugin subclass at run time |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 throw |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Throws an exception of class |
79
|
|
|
|
|
|
|
L<EXCEPTION_CLASS|Data::Validation::Constants/EXCEPTION_CLASS> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 Diagnostics |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
None |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 Dependencies |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=over 3 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item L<Module::Runtime> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item L<Try::Tiny> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item L<Unexpected> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 Incompatibilities |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
There are no known incompatibilities in this module |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 Bugs and Limitations |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
There are no known bugs in this module. Please report problems to |
104
|
|
|
|
|
|
|
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Validation. Patches are welcome |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 Acknowledgements |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Larry Wall - For the Perl programming language |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 Author |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Peter Flanigan, C<< <pjfl@cpan.org> >> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 License and Copyright |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Copyright (c) 2016 Peter Flanigan. All rights reserved |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
119
|
|
|
|
|
|
|
under the same terms as Perl itself. See L<perlartistic> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
122
|
|
|
|
|
|
|
but WITHOUT WARRANTY; without even the implied warranty of |
123
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Local Variables: |
128
|
|
|
|
|
|
|
# mode: perl |
129
|
|
|
|
|
|
|
# tab-width: 3 |
130
|
|
|
|
|
|
|
# End: |