lib/Form/Sensible.pm

filter: Statementstmt 86.4% 83 / 96 Branchbran 50.0% 7 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 95.0% 19 / 20 Podpod 100% 3 / 3 totaltotal 80.2% 114 / 142 CC 12 SCAR 12.5
CC
12
Cov
79%
get_validator
12.0
__ANON__
5.6
create_form
5.0
CRAP 3.5
« lib/Form/Sensible/Field/Select.pm ↑ Summary lib/Form/Sensible/Field/Text.pm »
1 package Form::Sensible;
2  
3 16 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use Class::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Form::Sensible::Form;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Form::Sensible::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Form::Sensible::Field::DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Form::Sensible::Field::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Form::Sensible::Field::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Form::Sensible::Field::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use Form::Sensible::Field::LongText;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 16 ▶use Form::Sensible::Field::Toggle;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 16 ▶use Form::Sensible::Field::Trigger;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 ▶use Form::Sensible::Field::SubForm;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 16 ▶use Form::Sensible::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 16 ▶use Form::Sensible::Validator::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 16 ▶use Form::Sensible::DelegateConnection;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 16 our $VERSION = "0.20023";
21  
22 16 Moose::Exporter->setup_import_methods(
23 also => [ 'Form::Sensible::DelegateConnection' ]
24 );
25  
26 1 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=4 SCAR=17.2
27 1 my $orig = shift;
28 1 my $class = shift;
29
30 ## this is somewhat odd, but it's a lot easier to track down with this error
31 ## than getting back an empty Form::Sensible object.
32
33 1 ▶ if ($#_ == 0 && ref($_[0]) && exists($_[0]->{'fields'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ == 0 and ref $_[0] and exists $_[0]{'fields'}) { } 1 0 1
Condition33%2/6
$#_ == 0 and ref $_[0] and exists $_[0]{"fields"}
!ll&&!rl&&r
001
$#_ == 0 and ref $_[0]
!ll&&!rl&&r
001
MC/DC0%0/3
$#_ == 0 and ref $_[0] and exists $_[0]{"fields"}
$#_ == 0 ref $_[0] exists $_[0]{"fields"}
Truth table25%1/4
A and B and C
A= $#_ == 0B= ref $_[0]C= exists $_[0]{"fields"}
ABCresult
0XX0
10X0
1100
1111
34 1 die "Invalid call to Form::Sensible->new() !! Form::Sensible is not meant to be instantiated. You probably meant to call create_form()";
35 } else {
36 0 return $class->$orig(@_);
37 }
38 16 };
39  
40 ## This module is a simple factory class which will load and create the various
41 ## types of modules required when working with Form::Sensible
42  
43 21 ▶sub create_form {
Subroutine create_form: called CC=5 SCAR=16.2
Pod documented
44 21 my ($class, $template) = @_;
45
46 21 my $formhash = { %{$template} };
47 21 delete($formhash->{'fields'});
48 21 delete($formhash->{'field_order'});
49
50 21 my $form = Form::Sensible::Form->new(%{$formhash});
51
52 21 ▶ if (ref($template->{'fields'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $template->{'fields'} eq 'ARRAY') { } 19 2 21
53 19 foreach my $field (@{$template->{'fields'}}) {
54 46 $form->add_field($field, $field->{name});
55 #Form::Sensible::Field->create_from_flattened($field);
56 #$form->add_field($newfield, $newfield->name);
57 }
58 } else {
59 2 my @field_order;
60 2 ▶ if (exists($template->{'field_order'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $template->{'field_order'}) { } 2 0 2
61 2 push @field_order, @{$template->{'field_order'}};
62 } else {
63 0 push @field_order, keys %{$template->{'fields'}};
64 }
65 2 foreach my $fieldname (@field_order) {
66 8 $form->add_field($template->{'fields'}{$fieldname}, $fieldname);
67
68 #my $newfield = Form::Sensible::Field->create_from_flattened($template->{'fields'}{$fieldname});
69 #$form->add_field($newfield, $fieldname);
70 }
71 }
72 21 return $form;
73 }
74  
75 6 ▶sub get_renderer {
Subroutine get_renderer: called CC=3 SCAR=11.1
Pod documented
76 6 my ($class, $type, $options) = @_;
77  
78 6 my $class_to_load;
79 6 ▶ if ($type =~ /^\+(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^\+(.*)$/) { } 0 6 6
80 0 $class_to_load = $1;
81 } else {
82 6 $class_to_load = 'Form::Sensible::Renderer::' . $type;
83 }
84 6 Class::MOP::load_class($class_to_load);
85 6 ▶ if (!$options) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options) 1 5 6
86 1 $options = {};
87 }
88
89 6 return $class_to_load->new($options);
90 }
91  
92 0 ▶sub get_validator {
Subroutine get_validator: not called CC=3 SCAR=24.8
Pod documented
93 0 my ($class, $type, $options) = @_;
94
95 0 my $class_to_load;
96 0 ▶ if (!defined($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 0 0 0
97 0 $type = "+Form::Sensible::Validator";
98 }
99 0 ▶ if ($type =~ /^\+(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^\+(.*)$/) { } 0 0 0
100 0 $class_to_load = $1;
101 } else {
102 0 $class_to_load = 'Form::Sensible::Validator::' . $type;
103 }
104 0 Class::MOP::load_class($class_to_load);
105
106 0 return $class_to_load->new($options);
107 }
108  
109  
110  
111 16 __PACKAGE__->meta->make_immutable;
112 16 1;
113  
114 __END__
« lib/Form/Sensible/Field/Select.pm ↑ Summary lib/Form/Sensible/Field/Text.pm »