blib/lib/Rose/HTML/Form/Field/Set.pm

filter: Statementstmt 92.5% 50 / 54 Branchbran 82.1% 23 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 90.2% 83 / 92 CC 14 SCAR 17.2
CC
14
Cov
89%
inflate_value
9.1
deflate_value
4.0
validate
3.3
CRAP 5.6
« blib/lib/Rose/HTML/Object/Message.pm ↑ Summary blib/lib/Rose/HTML/Form/Field/Text.pm »
1 package Rose::HTML::Form::Field::Set;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Rose::HTML::Object::Errors qw(:set);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use base 'Rose::HTML::Form::Field::TextArea';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.606';
10  
11 sub deflate_value
12 16 ▶{
Subroutine deflate_value: called CC=4 SCAR=13.9
Pod documented
13 16 my($self, $list) = @_;
14  
15 16 ▶ my @list = $list ? @$list : (); # shallow copy
Branch: 1 branch
BranchTrueFalseTotal
$list ? : 15 1 16
16  
17 16 ▶ return $self->input_value_filtered unless(ref $list eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $list eq "ARRAY" 1 15 16
18  
19 return join(', ', map
20 {
21 15 ▶ if(/["\\\s,]/) # needs escaping
Branch: 1 branch
BranchTrueFalseTotal
if (/["\\\s,]/) { } 24 36 60
22 {
23 24 s/\\/\\\\/g; # escape backslashes
24 24 s/"/\\"/g; # escape double quotes
25 24 qq("$_") # double quote the whole thing
26 }
27 36 else { $_ }
28 }
29 @list);
30 }
31  
32 sub inflate_value
33 17 ▶{
Subroutine inflate_value: called CC=9 SCAR=22.1
Pod documented
34 17 my($self, $value) = @_;
35  
36 17 ▶ return $value if(ref $value eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 5 12 17
37 12 ▶ return undef unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 11 12
38  
39 11 my @strings;
40  
41 # Extract comma- or whitespace-separated, possibly double-quoted strings
42 11 ▶ while(length $value)
Branch: 1 branch
BranchTrueFalseTotal
if (length $value) 41 5 46
43 {
44 41 $value =~ s/^(?:(?:\s*,\s*)+|\s+)//;
45  
46 41 ▶ last unless(length($value));
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 4 37 41
47  
48 37 ▶ if($value =~ s/^"((?:[^"\\]+|\\.)*)"//s)
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ s/^"((?:[^"\\]+|\\.)*)"//s) { } 17 20 37
elsif ($value =~ s/^([^,"\s]+)//) { } 18 2 20
49 {
50 17 my $string = $1;
51 # Interpolate backslash escapes
52 17 my $interpolated = $string;
53  
54 17 my $error;
55  
56 TRY:
57 {
58 17 local $@;
59 17 $interpolated =~ s/\\(.)/eval qq("\\$1")/ge;
60 17 $error = $@;
61 }
62  
63 17 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 17 17
64 {
65 0 $self->add_error_id(SET_INVALID_QUOTED_STRING, { string => $string });
66 0 next;
67 }
68  
69 17 push(@strings, $interpolated);
70 }
71 elsif($value =~ s/^([^,"\s]+)//)
72 {
73 18 push(@strings, $1);
74 }
75 else
76 {
77 2 ▶ $self->error(SET_PARSE_ERROR, { context => (length($value) < 5) ? "...$value" :
Branch: 1 branch
BranchTrueFalseTotal
length $value < 5 ? : 2 0 2
78 '...' . substr($value, 0, 5) });
79 2 last;
80 }
81 }
82  
83 11 return \@strings;
84 }
85  
86 sub validate
87 1 ▶{
Subroutine validate: called CC=3 SCAR=12.0
Pod documented
88 1 my($self) = shift;
89  
90 1 my $ok = $self->SUPER::validate(@_);
91 1 ▶ return $ok unless($ok);
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1 1
92  
93 1 ▶ return 0 if($self->has_errors);
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_errors 1 0 1
94 0 return 1;
95 }
96  
97 2 ▶if(__PACKAGE__->localizer->auto_load_messages)
Branch: 1 branch
BranchTrueFalseTotal
if (__PACKAGE__->localizer->auto_load_messages) 0 2 2
98 {
99 0 __PACKAGE__->localizer->load_all_messages;
100 }
101  
102 2 ▶use utf8; # The __DATA__ section contains UTF-8 text
Subroutine BEGIN: called CC=1 SCAR=0.0
103  
104 2 1;
105  
106 __DATA__
« blib/lib/Rose/HTML/Object/Message.pm ↑ Summary blib/lib/Rose/HTML/Form/Field/Text.pm »