blib/lib/Params/Validate/Dependencies/all_or_none_of.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 4 / 4 Conditioncond 100% 12 / 12 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 8 / 8 Podpod 33.3% 1 / 3 totaltotal 93.2% 55 / 59 CC 8 SCAR 15.5
CC
8
Cov
100%
__ANON__
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.7
↑ Summary
1 package Params::Validate::Dependencies::all_or_none_of;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base qw(Exporter Params::Validate::Dependencies::Documenter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use vars qw($VERSION @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 $VERSION = '1.01';
11 3 @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 ▶ my @options = @_;
Subroutine all_or_none_of: called CC=1 SCAR=0.0
Pod documented
50 return bless sub {
51 32 ▶ my $hashref = shift;
Subroutine __ANON__: called CC=8 SCAR=20.8
52 32 ▶ if($Params::Validate::Dependencies::DOC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Params::Validate::Dependencies::DOC) 10 22 32
53 10 return $Params::Validate::Dependencies::DOC->_doc_me(list => \@options);
54 }
55 22 my $count = 0;
56 22 foreach my $option (@options) {
57 $count++ if(
58 60 ▶ (!ref($option) && exists($hashref->{$option})) ||
Branch: 1 branch
BranchTrueFalseTotal
if not ref $option and exists $hashref->{$option} or ref $option and &$option($hashref) 31 29 60
Condition100%9/9
not ref $option and exists $hashref->{$option} or ref $option and &$option($hashref)
l!l&&r!l&&!r
27627
not ref $option and exists $hashref->{$option}
!ll&&!rl&&r
62727
ref $option and &$option($hashref)
!ll&&!rl&&r
2724
MC/DC50%2/4
not ref $option and exists $hashref->{$option} or ref $option and &$option($hashref)
not ref $option exists $hashref->{$option} ref $option &$option($hashref)
Truth table42%3/7
not(A) and B or C and D
A= not ref $optionB= exists $hashref->{$option}C= ref $optionD= &$option($hashref)
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
59 (ref($option) && $option->($hashref))
60 );
61 }
62 22 ▶ return ($count == 0 || $count == $#options + 1);
Condition100%3/3
$count == 0 || $count == $#options + 1
l!l&&r!l&&!r
3415
MC/DC100%2/2
$count == 0 || $count == $#options + 1
$count == 0 $count == $#options + 1
Truth table100%3/3
A || B
A= $count == 0B= $count == $#options + 1
ABresult
1X1
011
000
63 3 }, __PACKAGE__;
64 }
65  
66 10 ▶sub join_with { return 'and'; }
Subroutine join_with: called CC=1 SCAR=0.0
Pod undocumented
67 11 ▶sub name { return 'all_or_none_of'; }
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
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<Params::Validate::Dependencies::Extending>.
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<http://rt.cpan.org/>
80 or at L<https://github.com/DrHyde/perl-modules-Params-Validate-Dependencies/issues>.
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<Params::Validate::Dependencies>
90  
91 L<Data::Domain::Dependencies>
92  
93 =head1 SOURCE CODE REPOSITORY
94  
95 L<git://github.com/DrHyde/perl-modules-Params-Validate-Dependencies-all_or_none_of.git>
96  
97 L<https://github.com/DrHyde/perl-modules-Params-Validate-Dependencies-all_or_none_of/>
98  
99 =head1 COPYRIGHT and LICENCE
100  
101 Copyright 2011 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt>
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 3 1;
↑ Summary