Shakan/Field.pm

filter: Statementstmt 50.0% 26 / 52 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 26.6% 4 / 15 Podpod 0.0% 0 / 3 totaltotal 41.6% 30 / 72 CC 2 SCAR 8.1
CC
2
Cov
48%
get_constraints
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.2
« Shakan/Declare.pm ↑ Summary Shakan/Fields.pm »
1 package HTML::Shakan::Field;
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 has id => (
7 is => 'rw',
8 isa => 'Str',
9 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
10 0 my ($self, $id) = @_;
11 0 $self->{attr}->{id} = $id;
12 },
13 22 );
14  
15 has name => (
16 is => 'ro',
17 isa => 'Str',
18 required => 1,
19 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 0 my ( $self, $name ) = @_;
21 0 $self->{attr}->{name} = $name;
22 },
23 22 );
24  
25 has value => (
26 is => 'rw',
27 isa => 'Str',
28 required => 0,
29 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 my ( $self, $value ) = @_;
31 0 $self->{attr}->{value} = $value;
32 },
33 22 );
34  
35 has filters => (
36 is => 'rw',
37 isa => 'ArrayRef[Str]',
38 0 ▶ default => sub { +[] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 22 );
40  
41 22 has widget => (
42 is => 'ro',
43 isa => 'Str',
44 required => 1,
45 );
46  
47 has attr => (
48 is => 'ro',
49 isa => 'HashRef',
50 lazy => 1,
51 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 +{}
53 0 },
54 22 );
55  
56 has label => (
57 is => 'ro',
58 isa => 'Str',
59 lazy => 1,
60 0 ▶ default => sub { shift->name }
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 22 );
62  
63 22 has label_class => (
64 is => 'ro',
65 isa => 'Str',
66 predicate => 'has_label_class',
67 );
68  
69 22 has required => (
70 is => 'ro',
71 isa => 'Bool',
72 default => 0,
73 );
74  
75 22 has inflator => (
76 is => 'ro',
77 isa => 'Object',
78 );
79  
80 22 has custom_validation => (
81 is => 'ro',
82 isa => 'CodeRef',
83 );
84  
85 has constraints => (
86 is => 'ro',
87 isa => 'ArrayRef',
88 0 ▶ default => sub { +[] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 22 );
90  
91 0 ▶sub add_constraint {
Subroutine add_constraint: not called CC=1 SCAR=6.9
Pod undocumented
92 0 my ($self, @constraint) = @_;
93 0 push @{$self->{constraints}}, @constraint;
94 0 $self; # method chain
95 }
96  
97 has complex_constraints => (
98 is => 'ro',
99 isa => 'ArrayRef',
100 0 ▶ default => sub { +[] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 22 );
102  
103 0 ▶sub add_complex_constraint {
Subroutine add_complex_constraint: not called CC=1 SCAR=6.9
Pod undocumented
104 0 my ($self, @constraints) = @_;
105 0 push @{$self->{complex_constraints}}, @constraints;
106 0 $self; # method chain
107 }
108  
109 0 ▶sub get_constraints {
Subroutine get_constraints: not called CC=2 SCAR=17.9
Pod undocumented
110 0 my $self = shift;
111  
112 0 my @rule = @{$self->{constraints}};
113 0 ▶ if ($self->required) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->required) 0 0 0
114 0 push @rule, 'NOT_NULL';
115 }
116 return (
117 $self->name => \@rule,
118 0 @{ $self->complex_constraints },
119 );
120 }
121  
122 22 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 22 __PACKAGE__->meta->make_immutable;
124 __END__
« Shakan/Declare.pm ↑ Summary Shakan/Fields.pm »