FormHandler/Field/Display.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 2 / 2 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 92.3% 48 / 52 CC 4 SCAR 7.4
CC
4
Cov
97%
build_render_method
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« FormHandler/Widget/Field/ButtonTag.pm ↑ Summary FormHandler/Field/Email.pm »
1 package HTML::FormHandler::Field::Display;
2 # ABSTRACT: display only field
3 5 $HTML::FormHandler::Field::Display::VERSION = '0.410001';
4 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 extends 'HTML::FormHandler::Field::NoValue';
6 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 5 has 'html' => ( is => 'rw', isa => 'Str', builder => 'build_html', lazy => 1 );
10 3 ▶sub build_html {''}
Subroutine build_html: called CC=1 SCAR=0.0
Pod undocumented
11 5 has 'set_html' => ( isa => 'Str', is => 'ro');
12 5 has '+do_label' => ( default => 0 );
13  
14 5 has 'render_method' => (
15 traits => ['Code'],
16 is => 'ro',
17 isa => 'CodeRef',
18 lazy => 1,
19 predicate => 'does_render_method',
20 handles => { 'render' => 'execute_method' },
21 builder => 'build_render_method',
22 );
23  
24 sub build_render_method {
25 6 ▶ my $self = shift;
Subroutine build_render_method: called CC=4 SCAR=13.9
Pod undocumented
26  
27 6 my $set_html = $self->set_html;
28 6 ▶ $set_html ||= "html_" . HTML::FormHandler::Field::convert_full_name($self->full_name);
Condition100%2/2
$set_html ||= 'html_' . HTML::FormHandler::Field::convert_full_name($self->full_name)
l!l
15
MC/DC100%1/1
$set_html ||= 'html_' . HTML::FormHandler::Field::convert_full_name($self->full_name)
$set_html
Truth table100%2/2
A
A= $set_html
Aresult
11
00
29 2 ▶ return sub { my $self = shift; $self->form->$set_html($self); }
Subroutine __ANON__: called CC=1 SCAR=0.0
30 6 ▶ if ( $self->form && $self->form->can($set_html) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->form and $self->form->can($set_html) 2 4 6
Condition66%2/3
$self->form and $self->form->can($set_html)
!ll&&!rl&&r
042
MC/DC50%1/2
$self->form and $self->form->can($set_html)
$self->form $self->form->can($set_html)
Truth table66%2/3
A and B
A= $self->formB= $self->form->can($set_html)
ABresult
0X0
100
111
31 return sub {
32 4 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
33 4 return $self->html;
34 4 };
35 }
36  
37 sub _result_from_object {
38 1 ▶ my ( $self, $result, $value ) = @_;
Subroutine _result_from_object: called CC=1 SCAR=0.0
39 1 $self->_set_result($result);
40 1 $self->value($value);
41 1 $result->_set_field_def($self);
42 1 return $result;
43 }
44  
45 5 __PACKAGE__->meta->make_immutable;
46 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 5 1;
48  
49 __END__
50  
51 =pod
52  
53 =encoding UTF-8
54  
55 =head1 NAME
56  
57 HTML::FormHandler::Field::Display - display only field
58  
59 =head1 VERSION
60  
61 version 0.410001
62  
63 =head1 SYNOPSIS
64  
65 This class can be used for fields that are display only. It will
66 render the value returned by a form's 'html_<field_name>' method,
67 or the field's 'html' attribute.
68  
69 has_field 'explanation' => ( type => 'Display',
70 html => '<p>This is an explanation...</p>' );
71  
72 or in a form:
73  
74 has_field 'explanation' => ( type => 'Display' );
75 sub html_explanation {
76 my ( $self, $field ) = @_;
77 if( $self->something ) {
78 return '<p>This type of explanation...</p>';
79 }
80 else {
81 return '<p>Another type of explanation...</p>';
82 }
83 }
84 #----
85 has_field 'username' => ( type => 'Display' );
86 sub html_username {
87 my ( $self, $field ) = @_;
88 return '<div><b>User:&nbsp;</b>' . $field->value . '</div>';
89 }
90  
91 or set the name of the rendering method:
92  
93 has_field 'explanation' => ( type => 'Display', set_html => 'my_explanation' );
94 sub my_explanation {
95 ....
96 }
97  
98 or provide a 'render_method':
99  
100 has_field 'my_button' => ( type => 'Display', render_method => \&render_my_button );
101 sub render_my_button {
102 my $self = shift;
103 ....
104 return '...';
105 }
106  
107 =head1 AUTHOR
108  
109 FormHandler Contributors - see HTML::FormHandler
110  
111 =head1 COPYRIGHT AND LICENSE
112  
113 This software is copyright (c) 2017 by Gerda Shank.
114  
115 This is free software; you can redistribute it and/or modify it under
116 the same terms as the Perl 5 programming language system itself.
117  
118 =cut
« FormHandler/Widget/Field/ButtonTag.pm ↑ Summary FormHandler/Field/Email.pm »