Valiant/Proxy/Object.pm

filter: Statementstmt 94.7% 18 / 19 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 85.2% 29 / 34 CC 4 SCAR 7.1
CC
4
Cov
88%
AUTOLOAD
3.0
read_attribute_for_validation
2.1
BEGIN
1.0
CRAP 2.0
« Valiant/Filter/Template.pm ↑ Summary Valiant/Validator/Scalar.pm »
1 package Valiant::Proxy::Object;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Valiant::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 with 'Valiant::Proxy';
8  
9 sub read_attribute_for_validation {
10 14 ▶ my ($self, $attribute) = @_;
Subroutine read_attribute_for_validation: called CC=2 SCAR=7.6
Pod undocumented
11 14 ▶ if($self->for->can($attribute)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->for->can($attribute)) { } 14 0 14
12 14 return $self->for->$attribute;
13 } else {
14 0 throw_exception MissingMethod => (object=>$self->for, method=>$attribute);
15 }
16 }
17  
18 sub AUTOLOAD {
19 5 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
20 5 ( my $method = our $AUTOLOAD ) =~ s{.*::}{};
21 5 ▶ if(blessed($self->for) && $self->for->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($self->for) and $self->for->can($method)) { } 3 2 5
Condition66%2/3
builtin::blessed($self->for) and $self->for->can($method)
!ll&&!rl&&r
023
MC/DC50%1/2
builtin::blessed($self->for) and $self->for->can($method)
builtin::blessed($self->for) $self->for->can($method)
Truth table66%2/3
A and B
A= builtin::blessed($self->for)B= $self->for->can($method)
ABresult
0X0
100
111
22 3 return $self->for->$method(@_);
23 } else {
24 # warn "cannot find $method in ${\$self->data}";
25 }
26 }
27  
28 1 1;
29  
30 =head1 NAME
31  
32 Valiant::Result::Object - Wrap any object into a validatable result object.
33  
34 =head1 SYNOPSIS
35  
36 TBD
37  
38 =head1 DESCRIPTION
39  
40 Create a validation object for a given class or role. Useful when you need (or prefer)
41 to build up a validation ruleset in code rather than via the annotations-like approach
42 given in L<Valiant::Validations>. Can also be useful to add validations to a class that
43 isn't Moo/se and can't use L<Valiant::Validations> or is outside your control (such as
44 a third party library). Lastly you may need to build validation sets based on existing
45 metadata, such as via database introspection or from a file containing validation
46 instructions.
47  
48 This uses AUTOLOAD to delegate method calls to the underlying object.
49  
50 Please note that the code used to create the validation object is not speed optimized so
51 I recommend you not use this approach in 'hot' code paths. Its probably best if you can
52 create all these during your application startup once (for long lived applications). Maybe
53 not ideal for 'fire and forget' scripts like cron jobs or CGI.
54  
55 You probably won't use this directly (although you can) since we have L<Valiant::Class> to
56 encapsulate the most common patterns for this need.
57  
58 =head1 SEE ALSO
59  
60 This does the interface defined by L<Valiant::Result> so see the docs on that.
61
62 Also: L<Valiant>, L<Valiant::Validator>, L<Valiant::Validator::Each>.
63  
64 =head1 AUTHOR
65  
« Valiant/Filter/Template.pm ↑ Summary Valiant/Validator/Scalar.pm »