FormHandler/Field/AddElement.pm

filter: Statementstmt 100% 28 / 28 Branchbran 50.0% 1 / 2 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 81.4% 35 / 43 CC 4 SCAR 10.2
CC
4
Cov
89%
__ANON__
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.8
« FormHandler/Widget/Field/Hidden.pm ↑ Summary FormHandler/Field/Multiple.pm »
1 package HTML::FormHandler::Field::AddElement;
2 # ABSTRACT: Field to support repeatable javascript add
3 1 $HTML::FormHandler::Field::AddElement::VERSION = '0.410001';
4 1 ▶use HTML::FormHandler::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends 'HTML::FormHandler::Field::Display';
6 1 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 1 has 'repeatable' => ( is => 'rw', isa => 'Str', required => 1 );
10 1 has '+do_wrapper' => ( default => 1 );
11 1 has '+value' => ( default => 'Add Element' );
12  
13 sub build_render_method {
14 return sub {
15 1 ▶ my ( $self, $result ) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.1
16 1 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
010
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
17  
18 1 my $rep_field = $self->parent->field($self->repeatable);
19 1 ▶ die "Invalid repeatable name in field " . $self->name unless $rep_field;
Branch: 1 branch
BranchTrueFalseTotal
unless $rep_field 0 1 1
20 1 my $value = $self->html_filter($self->_localize($self->value));
21 1 my $attrs = $self->element_attributes($result);
22 1 push @{$attrs->{class}}, ( 'add_element', 'btn' );
23 1 $attrs->{'data-rep-id'} = $rep_field->id;
24 1 $attrs->{id} = $self->id;
25 1 my $attr_str = process_attrs($attrs);
26 1 ▶ my $wrapper_tag = $self->get_tag('wrapper_tag') || 'div';
Condition50%1/2
$self->get_tag('wrapper_tag') || 'div'
l!l
01
MC/DC0%0/1
$self->get_tag('wrapper_tag') || 'div'
$self->get_tag('wrapper_tag')
Truth table50%1/2
A
A= $self->get_tag('wrapper_tag')
Aresult
11
00
27 1 my $output = qq{<$wrapper_tag$attr_str>$value</$wrapper_tag>};
28 1 $output = $self->wrap_field($self->result, $output);
29 1 return $output;
30 1 ▶ };
Subroutine build_render_method: called CC=1 SCAR=0.0
Pod undocumented
31 }
32  
33 1 1;
34  
35 __END__
36  
37 =pod
38  
39 =encoding UTF-8
40  
41 =head1 NAME
42  
43 HTML::FormHandler::Field::AddElement - Field to support repeatable javascript add
44  
45 =head1 VERSION
46  
47 version 0.410001
48  
49 =head1 SYNOPSIS
50  
51 EXAMPLE field for rendering an AddElement field for
52 doing javascript additions of repeatable elements.
53  
54 You probably want to make your own.
55  
56 The main requirements are that the button have 1) the
57 'add_element' class, 2) a 'data-rep-id' attribute that
58 contains the id of the repeatable to which you want to
59 add an element.
60  
61 =head1 NAME
62  
63 HTML::FormHandler::Field::AddElement
64  
65 =head1 ATTRIBUTES
66  
67 has_field 'add_element' => ( type => 'AddElement', repeatable => 'foo',
68 value => 'Add another foo',
69 );
70  
71 =head2 repeatable
72  
73 Requires the name of a Repeatable sibling field.
74  
75 =head2 value
76  
77 The value of the button that's rendered, 'Add Element' by default.
78  
79 =head1 AUTHOR
80  
81 FormHandler Contributors - see HTML::FormHandler
82  
83 =head1 COPYRIGHT AND LICENSE
84  
85 This software is copyright (c) 2017 by Gerda Shank.
86  
87 This is free software; you can redistribute it and/or modify it under
88 the same terms as the Perl 5 programming language system itself.
89  
90 =cut
« FormHandler/Widget/Field/Hidden.pm ↑ Summary FormHandler/Field/Multiple.pm »