Valiant/HTML/Util/View.pm

filter: Statementstmt 90.0% 27 / 30 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 85.7% 6 / 7 totaltotal 83.0% 49 / 59 CC 7 SCAR 10.2
CC
7
Cov
81%
read_attribute_for_html
4.8
attribute_exists_for_html
4.1
escape_html
2.0
CRAP 2.8
« Valiant/Filter/Each.pm ↑ Summary Valiant/Validator/Presence.pm »
1 package Valiant::HTML::Util::View;
2  
3 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use Valiant::HTML::SafeString ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1135 ▶sub safe { shift; return Valiant::HTML::SafeString::safe(@_) }
Subroutine safe: called CC=1 SCAR=0.0
Pod documented
8 883 ▶sub raw { shift; return Valiant::HTML::SafeString::raw(@_) }
Subroutine raw: called CC=1 SCAR=0.0
Pod documented
9 516 ▶sub safe_concat { shift; return Valiant::HTML::SafeString::safe_concat(@_) }
Subroutine safe_concat: called CC=1 SCAR=0.0
Pod documented
10 0 ▶sub escape_html { shift; return Valiant::HTML::SafeString::escape_html(@_) }
Subroutine escape_html: not called CC=1 SCAR=6.9
Pod documented
11  
12 4 ▶sub read_attribute_for_html {
Subroutine read_attribute_for_html: called CC=4 SCAR=15.6
Pod documented
13 4 my ($self, $attribute) = @_;
14 4 ▶ return unless defined $attribute;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attribute 0 4 4
15 4 ▶ return my $value = $self->$attribute if $self->can($attribute);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($attribute) 0 4 4
16 4 ▶ return $self->{$attribute} if exists $self->{$attribute};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$attribute} 4 0 4
17 0 die "No such attribute '$attribute' for view";
18 }
19  
20 4 ▶sub attribute_exists_for_html {
Subroutine attribute_exists_for_html: called CC=4 SCAR=14.1
Pod documented
21 4 my ($self, $attribute) = @_;
22 4 ▶ return unless defined $attribute;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attribute 0 4 4
23 4 ▶ return 1 if $self->can($attribute);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($attribute) 0 4 4
24 4 ▶ return 1 if exists $self->{$attribute};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$attribute} 3 1 4
25 1 return;
26 }
27  
28 16 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
29 16 my ($class, %attrs) = @_;
30 16 return bless \%attrs, $class;
31 }
32  
33 9 1;
34  
35 =head1 NAME
36  
37 Valiant::HTML::Util::View - Default view for Formbuilder
38  
39 =head1 SYNOPSIS
40  
41 For internal use only
42  
43 =head1 DESCRIPTION
44  
45 When using the L<Valiant> HTML packages (L<Valiant::HTML::FormBuilder>, L<Valiant::HTML::Util::FormTags>
46 and the rest) a default view is required to provide methods for escaping strings
47 as well as potentially providing data. This way we escape strings compatible with your
48 view template system. If you are using these packages outside a view or template system
49 then we will use this package to provide those methods. Or if your template does not do
50 escaping (such as L<Template::Toolkit>). You can use this as an example of how to write
51 an adaptor to make things like L<Valiant::HTML::FormBuilder> escape strings such that your
52 system works with them.
53  
54 =head1 METHODS
55  
56 This class defines the following instance methods.
57  
58 =head2 raw
59  
60 given a string return a single tagged object which is marked as safe for display. Do not do any HTML
61 escaping on the string. This is used when you want to pass strings straight to display and that you
62 know is safe. Be careful with this to avoid HTML injection attacks.
63  
64 =head2 safe
65  
66 given a string return a single tagged object which is marked as safe for display. First HTML escape the
67 string as safe unless its already been done (no double escaping).
68  
69 =head2 safe_concat
70  
71 Same as C<safe> but instead works an an array of strings (or mix of strings and safe string objects) and
72 concatenates them all into one big safe marked string.
73  
74 =head2 escape_html
75  
76 Given a string return string that has been HTML escaped.
77  
78 =head2 read_attribute_for_html
79  
80 Given an attribute name return the value that the view has defined for it.
81  
82 =head2 attribute_exists_for_html
83  
84 Given an attribute name return true if the view has defined it.
85  
86 =head1 SEE ALSO
87  
88 L<Valiant>, L<Valiant::HTML::SafeString>, L<Valiant::HTML::FormBuilder>
89  
90 =head1 AUTHOR
91
92 See L<Valiant>
93  
94 =head1 COPYRIGHT & LICENSE
95
96 See L<Valiant>
97  
98 =cut
« Valiant/Filter/Each.pm ↑ Summary Valiant/Validator/Presence.pm »