MuForm/Field/Display.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 25.0% 1 / 4 totaltotal 85.7% 36 / 42 SCAR 16.1
CC
5
Cov
94%
render
5.0
no_fif
2.0
BEGIN
1.0
CRAP 5.0
« MuForm/Meta.pm ↑ Summary MuForm/Field/Password.pm »
1 package Data::MuForm::Field::Display;
2 # ABSTRACT: display only field
3  
4 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends 'Data::MuForm::Field';
6  
7  
8 1 has '+no_update' => ( default => 1 );
9  
10 0 ▶sub no_fif {1}
Subroutine no_fif: not called CC=1 SCAR=6.9
Pod undocumented
11 5 ▶sub fif { shift->value }
Subroutine fif: called CC=1 SCAR=0.0
Pod documented
12  
13 sub base_render_args {
14 5 ▶ my $self = shift;
Subroutine base_render_args: called CC=1 SCAR=0.0
Pod undocumented
15 5 my $args = $self->next::method(@_);
16 5 $args->{layout_type} = 'display';
17 5 $args->{layout} = 'span';
18 5 $args->{no_label} = 1;
19 5 return $args;
20 }
21  
22 1 has 'html' => ( is => 'rw', predicate => 1 );
23  
24 1 has 'render_method' => ( is => 'rw', predicate => 1 );
25  
26 sub render {
27 6 ▶ my $self = shift;
Subroutine render: called CC=5 SCAR=16.1
Pod undocumented
28  
29 6 ▶ return $self->html if $self->has_html;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_html 2 4 6
30 4 my $rargs = $self->get_render_args;
31 4 ▶ return $self->render_method->($self, $rargs) if $self->has_render_method;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_render_method 2 2 4
32 2 ▶ if ( $self->form ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form) 2 0 2
33 2 my $form_meth = "html_" . $self->convert_full_name($self->full_name);
34 2 ▶ if ( $self->form->can($form_meth) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form->can($form_meth)) 1 1 2
35 1 return $self->form->$form_meth($rargs);
36 }
37 }
38 1 return $self->next::method($rargs);
39 }
40  
41 1 1;
42  
43 __END__
44  
45 =pod
46  
47 =encoding UTF-8
48  
49 =head1 NAME
50  
51 Data::MuForm::Field::Display - display only field
52  
53 =head1 VERSION
54  
55 version 0.04
56  
57 =head1 SYNOPSIS
58  
59 This class can be used for fields that are display only. It will
60 render the value returned by a form's 'html_<field_name>' method,
61 or the field's 'html' attribute.
62  
63 has_field 'explanation' => ( type => 'Display',
64 html => '<p>This is an explanation...</p>' );
65  
66 or in a form:
67  
68 has_field 'explanation' => ( type => 'Display' );
69 sub html_explanation {
70 my ( $self, $field ) = @_;
71 if( $self->something ) {
72 return '<p>This type of explanation...</p>';
73 }
74 else {
75 return '<p>Another type of explanation...</p>';
76 }
77 }
78 #----
79 has_field 'username' => ( type => 'Display' );
80 sub html_username {
81 my ( $self, $field ) = @_;
82 return '<div><b>User:&nbsp;</b>' . $field->value . '</div>';
83 }
84  
85 or set the name of the rendering method:
86  
87 has_field 'explanation' => ( type => 'Display', set_html => 'my_explanation' );
88 sub my_explanation {
89 ....
90 }
91  
92 or provide a 'render_method':
93  
94 has_field 'my_button' => ( type => 'Display', render_method => \&render_my_button );
95 sub render_my_button {
96 my $self = shift;
97 ....
98 return '...';
99 }
100  
101 =head1 AUTHOR
102  
103 Gerda Shank
104  
105 =head1 COPYRIGHT AND LICENSE
106  
107 This software is copyright (c) 2017 by Gerda Shank.
108  
109 This is free software; you can redistribute it and/or modify it under
110 the same terms as the Perl 5 programming language system itself.
111  
112 =cut
« MuForm/Meta.pm ↑ Summary MuForm/Field/Password.pm »