| 1 | package Data::Domain::Dependencies; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Params::Validate::Dependencies qw(:_of exclusively); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use base qw(Data::Domain); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | $VERSION = '1.30'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | @EXPORT = (); | |||||||||||||||||||||||||||||||||||||||||
| 16 | @EXPORT_OK = ( | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | @{$Params::Validate::Dependencies::EXPORT_TAGS{_of}}, | |||||||||||||||||||||||||||||||||||||||||
| 18 | qw(exclusively Dependencies) | ||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | Data::Domain::Dependencies | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | A sub-class of Data::Domain which provides functions and objects | ||||||||||||||||||||||||||||||||||||||||||
| 29 | to let Data::Domain use the same | ||||||||||||||||||||||||||||||||||||||||||
| 30 | functions as Params::Validate::Dependencies. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | NB now this only works on perl 5.10 and higher as Data::Domain started | ||||||||||||||||||||||||||||||||||||||||||
| 33 | using some features of more modern perls. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | This creates a domain which, when passed a hashref to inspect, will | ||||||||||||||||||||||||||||||||||||||||||
| 38 | check that it contains at least one of an 'alpha' or 'beta' key, or | ||||||||||||||||||||||||||||||||||||||||||
| 39 | both of 'foo' and 'bar'. | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | use Data::Domain::Dependencies qw(:all); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | my $domain = Dependencies( | ||||||||||||||||||||||||||||||||||||||||||
| 44 | any_of( | ||||||||||||||||||||||||||||||||||||||||||
| 45 | qw(alpha beta), | ||||||||||||||||||||||||||||||||||||||||||
| 46 | all_of(qw(foo bar)) | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | my $errors = $domain->inspect(\%somehash); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | =head1 SUBROUTINES and EXPORTS | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | Nothing is exported by default, but you can export any of the *_of | ||||||||||||||||||||||||||||||||||||||||||
| 55 | functions of Params::Validate::Dependencies, and the 'Dependencies' | ||||||||||||||||||||||||||||||||||||||||||
| 56 | and 'exclusively' functions. They are all available under the 'all' tag. | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =head2 Dependencies | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | This takes a code-ref argument as returned by the *_of functions. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | It returns an object which is a sub-class of Data::Domain::Dependencies | ||||||||||||||||||||||||||||||||||||||||||
| 63 | and so has an 'inspect' method that you can use to check for errors | ||||||||||||||||||||||||||||||||||||||||||
| 64 | when passing it a hash-ref. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | sub Dependencies { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | ▶ | my $sub = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Dependencies: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 7 | __PACKAGE__->new($sub); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 'Dependencies' above is really just a thin wrapper around this | ||||||||||||||||||||||||||||||||||||||||||
| 76 | constructor. You are encouraged to not call this directly. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 7 | ▶ | my($class, $sub) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 7 | ▶ | die("$class constructor must be passed a Params::Validate::Dependencies object or a code-ref\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
ref($sub) =~ /CODE/ or builtin::blessed($sub) and $sub->isa("Params::Validate::Dependencies::Documenter")
builtin::blessed($sub) and $sub->isa("Params::Validate::Dependencies::Documenter")
MC/DC0%0/3
ref($sub) =~ /CODE/ or builtin::blessed($sub) and $sub->isa("Params::Validate::Dependencies::Documenter")
ref($sub) =~ /CODE/
builtin::blessed($sub)
$sub->isa("Params::Validate::Dependencies::Documenter")
Truth table50%2/4
A or B and C
A= ref($sub) =~ /CODE/B= builtin::blessed($sub)C= $sub->isa("Params::Validate::Dependencies::Documenter")
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | unless(ref($sub) =~ /CODE/ || (blessed($sub) && $sub->isa('Params::Validate::Dependencies::Documenter'))); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 7 | ▶ | if(blessed($sub)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | my $target_class = "${class}::".$sub->name(); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | ▶ | unless(@{"${target_class}::ISA"}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | # multiple inheritance so we can get at Data::Domain->inspect() | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # and Params::Validate::Dependencies::Documenter->_document() | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 6 | @{"${target_class}::ISA"} = ( | |||||||||||||||||||||||||||||||||||||||||
| 91 | 'Data::Domain::Dependencies', | ||||||||||||||||||||||||||||||||||||||||||
| 92 | blessed($sub) | ||||||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | ▶ | return bless sub { $sub->(@_) }, $target_class; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | return bless sub { $sub->(@_) }, $class; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | =head2 generate_documentation | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | This is an additional method, not found in Data::Domain, which | ||||||||||||||||||||||||||||||||||||||||||
| 104 | generates vaguely readable | ||||||||||||||||||||||||||||||||||||||||||
| 105 | documentation for the domain. Broadly speaking, it spits out the | ||||||||||||||||||||||||||||||||||||||||||
| 106 | source code. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | sub generate_documentation { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_documentation: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | $self->_document(); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | # this is where the magic happens ... | ||||||||||||||||||||||||||||||||||||||||||
| 116 | sub inspect { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 12 | ▶ | my $sub = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inspect: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 12 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 12 | ▶ | return __PACKAGE__." can only inspect hashrefs\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | unless(ref($data) =~ /HASH/i); | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 12 | ▶ | return $sub->($data) ? () : __PACKAGE__.": validation failed"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | =head1 LIES | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | Some of the above is incorrect. If you really want to know what's | ||||||||||||||||||||||||||||||||||||||||||
| 128 | going on, look at L<Params::Validate::Dependencies::Extending>. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | =head1 BUGS, LIMITATIONS, and FEEDBACK | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | I like to know who's using my code. All comments, including constructive | ||||||||||||||||||||||||||||||||||||||||||
| 133 | criticism, are welcome. | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | Please report any bugs either by email | ||||||||||||||||||||||||||||||||||||||||||
| 136 | or at L<https://github.com/DrHyde/perl-modules-Params-Validate-Dependencies/issues>. | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | Bug reports should contain enough detail that I can replicate the | ||||||||||||||||||||||||||||||||||||||||||
| 139 | problem and write a test. The best bug reports have those details | ||||||||||||||||||||||||||||||||||||||||||
| 140 | in the form of a .t file. If you also include a patch I will love | ||||||||||||||||||||||||||||||||||||||||||
| 141 | you for ever. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | L<Params::Validate::Dependencies> | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | L<Data::Domain> | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =head1 SOURCE CODE REPOSITORY | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | L<git://github.com/DrHyde/perl-modules-Params-Validate-Dependencies.git> | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | L<https://github.com/DrHyde/perl-modules-Params-Validate-Dependencies/> | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =head1 COPYRIGHT and LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | Copyright 2011 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 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. | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | =head1 CONSPIRACY | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | This module is also free-as-in-mason. | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||