blib/lib/Rose/HTMLx/Form/Field/PopUpMenuNumeric.pm

filter: Statementstmt 55.5% 15 / 27 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 38.1% 21 / 55 CC 9 SCAR 31.8
CC
9
Cov
35%
internal_value
42.0
validate
20.0
BEGIN
1.0
CRAP 24.0
↑ Summary
1 package Rose::HTMLx::Form::Field::PopUpMenuNumeric;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use base qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
7 Rose::HTML::Form::Field::PopUpMenu
8 2 );
9  
10 2 our $VERSION = '0.001';
11  
12 =head1 NAME
13  
14 Rose::HTMLx::Form::Field::PopUpMenuNumeric - popup menu for numeric values
15  
16 =head1 SYNOPSIS
17  
18 use Rose::HTMLx::Form::Field::PopUpMenuNumeric;
19 my $menu = Rose::HTMLx::Form::Field::PopUpMenuNumeric->new(
20 id => 'mynum',
21 name => 'mynum',
22 type => 'menu',
23 class => 'numeric-popup',
24 label => 'My Number',
25 options => [qw( 1 2 3 )],
26 labels => { 1 => 'one', 2 => 'two', 3 => 'three' },
27 );
28 $menu->input_value('1');
29 $menu->internal_value; # returns 1
30 $menu->input_value('');
31 $menu->internal_value; # returns undef
32  
33 =head1 DESCRIPTION
34  
35 Rose::HTMLx::Form::Field::PopUpMenuNumeric is like a normal RHTMLO PopUpMenu
36 but it returns an internal_value() like Rose::HTML::Form::Field::Numeric does.
37  
38 This module exists mostly to ensure that popup menus representing numeric values
39 properly return undef instead of an empty string -- an important distinction when
40 you *really* want a numeric value and not a string.
41
42 =head1 METHODS
43  
44 Only new or overridden method are documented here.
45  
46 =cut
47  
48 =head2 internal_value
49  
50 Cribbed verbatim from Rose::HTML::Form::Field::Numeric.
51  
52 =cut
53  
54 0 ▶sub internal_value {
Subroutine internal_value: not called CC=6 SCAR=37.4
Pod documented
55 0 my ($self) = shift;
56  
57 0 my $value = $self->SUPER::internal_value(@_);
58  
59 0 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
60 0 for ($value) {
61 0 ▶ s/-\s+/-/ || s/\+\s+//;
Branch: 1 branch
BranchTrueFalseTotal
s/-\s+/-/ or s/\+\s+// 0 0 0
62 }
63 }
64  
65 0 ▶ return ( defined $value && $value =~ /\S/ ) ? $value : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value && $value =~ /\S/ ? : 0 0 0
Condition0%0/3
defined $value and $value =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and $value =~ /\S/
defined $value $value =~ /\S/
Truth table0%0/3
A and B
A= defined $valueB= $value =~ /\S/
ABresult
0X0
100
111
66 }
67  
68 # This is $RE{num}{dec} from Regexp::Common::number
69 2 my $Match
70 = qr{^(?:(?i)(?:[+-]?)(?:(?=[0123456789]|[.])(?:[0123456789]*)(?:(?:[.])(?:[0123456789]{0,}))?)(?:(?:[E])(?:(?:[+-]?)(?:[0123456789]+))|))$};
71  
72 =head2 validate
73  
74 Cribbed nearly verbatim from Rose::HTML::Form::Field::Numeric.
75  
76 =cut
77  
78 0 ▶sub validate {
Subroutine validate: not called CC=4 SCAR=30.0
Pod documented
79 0 my ($self) = shift;
80  
81 0 my $ok = $self->SUPER::validate(@_);
82 0 ▶ return $ok unless ($ok);
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
83  
84 0 my $value = $self->internal_value;
85 0 ▶ return 1 unless ( defined $value && length $value );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
86  
87 0 return $value =~ $Match;
88 }
89  
90 2 1;
91  
92 __END__
↑ Summary