| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Params::Validate::Dependencies::all_or_none_of; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
133869
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
49
|
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
38
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
6
|
use base qw(Exporter Params::Validate::Dependencies::Documenter); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
160
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
6
|
use vars qw($VERSION @EXPORT @EXPORT_OK); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
333
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.01'; |
|
11
|
|
|
|
|
|
|
@EXPORT_OK = @EXPORT = ('all_or_none_of'); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Params::Validate::Dependencies::all_or_none_of |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
An extension for Params::Validate::Dependencies to validate that either |
|
20
|
|
|
|
|
|
|
all of or none of a list of params are present. |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
In this example, the 'foo' function takes named arguments, of which |
|
25
|
|
|
|
|
|
|
the 'day', 'month', and 'year' args must either all be present or |
|
26
|
|
|
|
|
|
|
none of them be present. |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Params::Validate::Dependencies qw(:all); |
|
29
|
|
|
|
|
|
|
use Params::Validate::Dependencies::all_or_none_of; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub foo { |
|
32
|
|
|
|
|
|
|
validate(@_, |
|
33
|
|
|
|
|
|
|
{ ... normal Params::Validate stuff ...}, |
|
34
|
|
|
|
|
|
|
all_or_none_of(qw(day month year)) |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SUBROUTINES and EXPORTS |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 all_or_none_of |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This is exported by default. It takes a list of scalars and code-refs |
|
43
|
|
|
|
|
|
|
and returns a code-ref which checks that the hashref it receives matches |
|
44
|
|
|
|
|
|
|
either all or none of the options given. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub all_or_none_of { |
|
49
|
3
|
|
|
3
|
1
|
247
|
my @options = @_; |
|
50
|
|
|
|
|
|
|
return bless sub { |
|
51
|
24
|
|
|
24
|
|
4448
|
my $hashref = shift; |
|
52
|
24
|
100
|
|
|
|
43
|
if($Params::Validate::Dependencies::DOC) { |
|
53
|
2
|
|
|
|
|
127
|
return $Params::Validate::Dependencies::DOC->_doc_me(list => \@options); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
22
|
|
|
|
|
18
|
my $count = 0; |
|
56
|
22
|
|
|
|
|
23
|
foreach my $option (@options) { |
|
57
|
60
|
100
|
100
|
|
|
236
|
$count++ if( |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
58
|
|
|
|
|
|
|
(!ref($option) && exists($hashref->{$option})) || |
|
59
|
|
|
|
|
|
|
(ref($option) && $option->($hashref)) |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
22
|
|
100
|
|
|
133
|
return ($count == 0 || $count == $#options + 1); |
|
63
|
3
|
|
|
|
|
31
|
}, __PACKAGE__; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
2
|
|
|
2
|
0
|
49
|
sub join_with { return 'and'; } |
|
67
|
3
|
|
|
3
|
0
|
45
|
sub name { return 'all_or_none_of'; } |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 LIES |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Some of the above is incorrect. If you really want to know what's |
|
72
|
|
|
|
|
|
|
going on, look at L. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 BUGS, LIMITATIONS, and FEEDBACK |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
I like to know who's using my code. All comments, including constructive |
|
77
|
|
|
|
|
|
|
criticism, are welcome. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Please report any bugs either by email or using L |
|
80
|
|
|
|
|
|
|
or at L. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Bug reports should contain enough detail that I can replicate the |
|
83
|
|
|
|
|
|
|
problem and write a test. The best bug reports have those details |
|
84
|
|
|
|
|
|
|
in the form of a .t file. If you also include a patch I will love |
|
85
|
|
|
|
|
|
|
you for ever. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
L |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SOURCE CODE REPOSITORY |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COPYRIGHT and LICENCE |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Copyright 2011 David Cantrell EFE |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 CONSPIRACY |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This module is also free-as-in-mason. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |