FormHandler/Field/RmElement.pm

filter: Statementstmt 100% 26 / 26 Branchbran n/a Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 75.0% 33 / 44 CC 4 SCAR 10.4
CC
4
Cov
85%
__ANON__
4.2
BEGIN
1.0
BEGIN
1.0
CRAP 2.8
« FormHandler/Widget/Field/Password.pm ↑ Summary FormHandler/Widget/Field/Textarea.pm »
1 package HTML::FormHandler::Field::RmElement;
2 # ABSTRACT: field to support repeatable javascript remove
3 1 $HTML::FormHandler::Field::RmElement::VERSION = '0.410000';
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 '+do_wrapper' => ( default => 1 );
10 1 has '+value' => ( default => 'Remove' );
11  
12 sub build_render_method {
13 return sub {
14 2 ▶ my ( $self, $result ) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.4
15 2 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
200
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
16  
17 2 ▶ my $value = $self->html || $self->html_filter($self->_localize($self->value));
Condition33%1/3
$self->html || $self->html_filter($self->_localize($self->value))
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->html || $self->html_filter($self->_localize($self->value))
$self->html $self->html_filter($self->_localize($self->value))
Truth table33%1/3
A || B
A= $self->htmlB= $self->html_filter($self->_localize($self->value))
ABresult
1X1
011
000
18 2 my $attrs = $self->element_attributes($result);
19 2 push @{$attrs->{class}}, ( 'rm_element', 'btn' );
20 2 $attrs->{'data-rep-elem-id'} = $self->parent->id;
21 2 $attrs->{id} = $self->id;
22 2 my $attr_str = process_attrs($attrs);
23 2 ▶ my $wrapper_tag = $self->get_tag('wrapper_tag') || 'div';
Condition50%1/2
$self->get_tag('wrapper_tag') || 'div'
l!l
02
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
24 2 my $output = qq{<$wrapper_tag$attr_str>$value</$wrapper_tag>};
25 2 $output = $self->wrap_field($self->result, $output);
26 2 return $output;
27 2 ▶ };
Subroutine build_render_method: called CC=1 SCAR=0.0
Pod undocumented
28 }
29  
30 1 __PACKAGE__->meta->make_immutable;
31 1 1;
32  
33 __END__
34  
35 =pod
36  
37 =encoding UTF-8
38  
39 =head1 NAME
40  
41 HTML::FormHandler::Field::RmElement - field to support repeatable javascript remove
42  
43 =head1 VERSION
44  
45 version 0.410000
46  
47 =head1 SYNOPSIS
48  
49 EXAMPLE field for rendering an RmElement field for
50 doing javascript removals of repeatable elements.
51  
52 You probably want to make your own.
53  
54 The main requirements are that the button have 1) the
55 'rm_element' class, 2) a 'data-rep-elem-id' attribute that
56 contains the id of the repeatable instance that you want
57 to remove (C<< $self->parent->id >>).
58  
59 This field should be a subfield of the Repeatable, probably
60 either first or last.
61  
62 =head1 NAME
63  
64 HTML::FormHandler::Field::RmElement
65  
66 =head1 ATTRIBUTES
67  
68 has_field 'rm_element' => ( type => 'RmElement',
69 value => 'Remove',
70 );
71  
72 =head1 AUTHOR
73  
74 FormHandler Contributors - see HTML::FormHandler
75  
76 =head1 COPYRIGHT AND LICENSE
77  
78 This software is copyright (c) 2017 by Gerda Shank.
79  
80 This is free software; you can redistribute it and/or modify it under
81 the same terms as the Perl 5 programming language system itself.
82  
83 =cut
« FormHandler/Widget/Field/Password.pm ↑ Summary FormHandler/Widget/Field/Textarea.pm »