lib/HTML/FormFu/Element/URL.pm

filter: Statementstmt 92.3% 36 / 39 Branchbran 62.5% 5 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 82.4% 47 / 57 CC 6 SCAR 15.2
CC
6
Cov
84%
pre_process
6.9
BEGIN
1.0
BEGIN
1.0
CRAP 4.6
« lib/HTML/FormFu/Element/DateTime.pm ↑ Summary lib/HTML/FormFu/Element/Password.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Element::URL;
4 4 $HTML::FormFu::Element::URL::VERSION = '2.09';
5 # ABSTRACT: HTML5 URL form field
6  
7 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 extends 'HTML::FormFu::Element';
10  
11 4 with 'HTML::FormFu::Role::Element::Input';
12  
13 4 ▶use HTML::FormFu::Attribute qw( mk_output_accessors );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 has http_only => ( is => 'rw', traits => ['Chained'] );
16 4 has https_only => ( is => 'rw', traits => ['Chained'] );
17  
18 4 has error_message => (
19 is => 'rw',
20 predicate => 'has_message',
21 traits => ['Chained'],
22 );
23  
24 4 has _has_auto_regex_constraint => (
25 is => 'rw',
26 init_arg => undef,
27 );
28  
29 4 __PACKAGE__->mk_output_accessors(qw( message ));
30  
31 1 ▶after BUILD => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 1 my $self = shift;
33  
34 1 $self->field_type('url');
35  
36 1 return;
37 4 };
38  
39 3 ▶sub pre_process {
Subroutine pre_process: called CC=6 SCAR=19.4
40 3 my ($self) = @_;
41  
42 3 my $constraint;
43  
44 3 ▶ if ( $self->_has_auto_regex_constraint ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_auto_regex_constraint) { } 2 1 3
45 2 $constraint = $self->_has_auto_regex_constraint;
46 }
47 else {
48 1 my $scheme;
49  
50 1 ▶ if ( $self->http_only ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->http_only) { } 0 1 1
elsif ($self->https_only) { } 0 1 1
51 0 $scheme = 'http';
52 }
53 elsif ( $self->https_only ) {
54 0 $scheme = 'https';
55 }
56 else {
57 1 $scheme = 'https?';
58 }
59  
60 1 $constraint = $self->constraint(
61 { type => 'Regex',
62 common => [ 'URI', 'HTTP', { -scheme => $scheme }, ],
63 } );
64  
65 1 $self->_has_auto_regex_constraint($constraint);
66  
67 # 'pattern' attribute
68 1 $self->pattern("$scheme://.*");
69  
70 }
71  
72 3 my $message = $self->error_message;
73 3 ▶ if ( defined $message && length $message ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $message and length $message) 0 3 3
Condition33%1/3
defined $message and length $message
!ll&&!rl&&r
300
MC/DC0%0/2
defined $message and length $message
defined $message length $message
Truth table33%1/3
A and B
A= defined $messageB= length $message
ABresult
0X0
100
111
74 0 $constraint->message($message);
75 }
76  
77 3 return;
78 }
79  
80 4 __PACKAGE__->meta->make_immutable;
81  
82 4 1;
83  
84 __END__
« lib/HTML/FormFu/Element/DateTime.pm ↑ Summary lib/HTML/FormFu/Element/Password.pm »