Chloro/Role/Trait/HasFormComponents.pm

filter: Statementstmt 82.6% 38 / 46 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 79.1% 53 / 67 CC 5 SCAR 7.3
CC
5
Cov
78%
add_field
3.7
add_group
3.7
BEGIN
1.0
CRAP 2.1
« Chloro/Trait/Application/ToClass.pm ↑ Summary Chloro/Result/Field.pm »
1 package Chloro::Role::Trait::HasFormComponents;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 our $VERSION = '0.07';
8  
9 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 has _fields => (
15 isa => 'Tie::IxHash',
16 init_arg => undef,
17 21 ▶ default => sub { Tie::IxHash->new() },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 11 handles => {
19 _add_field => 'STORE',
20 has_field => 'EXISTS',
21 get_field => 'FETCH',
22 local_fields => 'Values',
23 },
24 );
25  
26 has _groups => (
27 isa => 'Tie::IxHash',
28 init_arg => undef,
29 21 ▶ default => sub { Tie::IxHash->new() },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 11 handles => {
31 _add_group => 'STORE',
32 has_group => 'EXISTS',
33 local_groups => 'Values',
34 },
35 );
36  
37 30 ▶sub add_field {
Subroutine add_field: called CC=3 SCAR=13.1
Pod undocumented
38 30 my $self = shift;
39 30 my $field = shift;
40  
41 30 ▶ if ( $self->has_field( $field->name() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_field($field->name)) 0 30 30
42 0 my $name = $field->name();
43 0 croak "Cannot add two fields with the same name ($name)";
44 }
45  
46 30 ▶ if ( $self->has_group( $field->name() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_group($field->name)) 0 30 30
47 0 my $name = $field->name();
48 0 croak "Cannot share a name between a field and a group ($name)";
49 }
50  
51 30 $self->_add_field( $field->name() => $field );
52  
53 30 return;
54 }
55  
56 13 ▶sub add_group {
Subroutine add_group: called CC=3 SCAR=13.1
Pod undocumented
57 13 my $self = shift;
58 13 my $group = shift;
59  
60 13 ▶ if ( $self->has_group( $group->name() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_group($group->name)) 0 13 13
61 0 my $name = $group->name();
62 0 croak "Cannot add two groups with the same name ($name)";
63 }
64  
65 13 ▶ if ( $self->has_field( $group->name() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_field($group->name)) 0 13 13
66 0 my $name = $group->name();
67 0 croak "Cannot share a name between a field and a group ($name)";
68 }
69  
70 13 $self->_add_group( $group->name() => $group );
71  
72 13 return;
73 }
74  
75 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
76 35 ▶sub _make_field {
Subroutine _make_field: called CC=1 SCAR=0.0
77 35 my $self = shift;
78  
79 35 return Chloro::Field->new(
80 name => shift,
81 @_,
82 );
83 }
84 ## use critic
85  
86 11 1;
87  
88 # ABSTRACT: A metaclass trait for classes and roles which use Chloro
89  
90 __END__
« Chloro/Trait/Application/ToClass.pm ↑ Summary Chloro/Result/Field.pm »