Valiant/Validator/Scalar.pm

filter: Statementstmt 100% 15 / 15 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 83.8% 26 / 31 CC 4 SCAR 7.0
CC
4
Cov
91%
validate_each
3.0
normalize_shortcut
2.1
BEGIN
1.0
CRAP 2.0
« Valiant/Proxy/Object.pm ↑ Summary Catalyst/View/Valiant/HTMLBuilder/Form.pm »
1 package Valiant::Validator::Scalar;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Valiant::I18N;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 with 'Valiant::Validator::Each';
7  
8 1 ▶has is_not_scalar => (is=>'ro', required=>1, default=>sub {_t 'is_not_a_scalar'});
Subroutine __ANON__: called CC=1 SCAR=0.0
9  
10 sub normalize_shortcut {
11 1 ▶ my ($class, $arg) = @_;
Subroutine normalize_shortcut: called CC=2 SCAR=7.2
Pod undocumented
12 1 ▶ return +{} if $arg eq '1' ;
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq 1 1 0 1
13 }
14  
15 sub validate_each {
16 2 ▶ my ($self, $record, $attribute, $value, $opts) = @_;
Subroutine validate_each: called CC=3 SCAR=11.0
Pod undocumented
17 2 ▶ return if ref( \$value ) eq 'SCALAR' or ref( \( my $val = $value ) ) eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref \$value eq "SCALAR" or ref \(my $val = $value) eq "SCALAR" 1 1 2
Condition66%2/3
ref \$value eq "SCALAR" or ref \(my $val = $value) eq "SCALAR"
l!l&&r!l&&!r
101
MC/DC50%1/2
ref \$value eq "SCALAR" or ref \(my $val = $value) eq "SCALAR"
ref \$value eq "SCALAR" ref \(my $val = $value) eq "SCALAR"
Truth table66%2/3
A or B
A= ref \$value eq "SCALAR"B= ref \(my $val = $value) eq "SCALAR"
ABresult
1X1
011
000
18  
19 1 $record->errors->add($attribute, $self->is_not_scalar, $opts)
20 }
21  
22 1 1;
23  
24 =head1 NAME
25  
26 Valiant::Validator::Scalar - Validate that a value is a scalar (like a string or number)
27  
28 =head1 SYNOPSIS
29  
30 package Local::Test::Scalar;
31  
32 use Moo;
33 use Valiant::Validations;
34  
35 has name => (is=>'ro');
36  
37 validates name => ( scalar => 1 );
38  
39 ok my $object = Local::Test::Scalar->new(name=>[111,'John']);
40 ok $object->validate->invalid;
41  
42 is_deeply +{ $object->errors->to_hash(full_messages=>1) },
43 {
44 'name' => [
45 'Name must be a string or number',
46 ]
47 };
48  
49 =head1 DESCRIPTION
50  
51 Validates that the value in question is a scalar.
52  
53 =head1 SHORTCUT FORM
54  
55 This validator supports the follow shortcut forms:
56  
57 validates attribute => ( scalar => 1, ... );
58  
59 Which is the same as:
60  
61 validates attribute => (
62 scalar => { },
63 );
64
65 =head1 GLOBAL PARAMETERS
66  
67 This validator supports all the standard shared parameters: C<if>, C<unless>,
68 C<message>, C<strict>, C<allow_undef>, C<allow_blank>.
69  
70 =head1 AUTHOR
71
72 John Napiorkowski L<email:jjnapiork@cpan.org>
73
74 =head1 SEE ALSO
75
76 L<Valiant>, L<Valiant::Validator>, L<Valiant::Validator::Each>.
77
78 =head1 COPYRIGHT & LICENSE
79
80 Copyright 2020, John Napiorkowski L<email:jjnapiork@cpan.org>
81
82 This library is free software; you can redistribute it and/or modify it under
83 the same terms as Perl itself.
84  
85 =cut
« Valiant/Proxy/Object.pm ↑ Summary Catalyst/View/Valiant/HTMLBuilder/Form.pm »