log/error.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« text.pm ↑ Summary log/event.pm »
1 package HTML::GUI::log::error;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use HTML::GUI::constraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 0 ▶use HTML::GUI::log::event;
Subroutine BEGIN: called CC=1 SCAR=2.6
8  
9 =head1 NAME
10  
11 HTML::GUI::log::error - Create and control a error input for webapp
12  
13 =head1 VERSION
14  
15 Version 0.01
16  
17 =cut
18  
19 our $VERSION = '0.01';
20  
21 our @ISA = qw(HTML::GUI::log::event);
22  
23  
24 =head1 ERROR
25  
26 The error module to log all errors events
27  
28 =cut
29  
30  
31 =head1 PUBLIC METHODS
32  
33 =pod
34  
35 =head3 new
36  
37 =cut
38  
39 sub new
40 {
41 my($class,
42 $params, # widget :
43 ) = @_;
44 foreach my $mandatory qw/visibility error-type/{
45 if (!defined $params->{$mandatory}){
46 return undef;
47 }
48 }
49 my $this = $class->SUPER::new($params);
50 if (!$this){
51 return undef;
52 }
53 $this->{type} = 'error';
54 foreach my $paramName qw/message visibility error-type value/{
55 if (exists $params->{$paramName}){
56 $this->{$paramName} = $params->{$paramName} ;
57 }else{
58 $this->{$paramName} = '' ;
59 }
60 }
61 if (exists $params->{'constraint-info'}){
62 $this->{'constraint-info'} = $params->{'constraint-info'} ;
63 }else{
64 $this->{'constraint-info'} = {} ;
65 }
66 $this->{widgetSrc} = $params->{widgetSrc} ?$params->{widgetSrc}:undef;
67 bless($this, $class);
68 return $this;
69 }
70  
71 =pod
72  
73 =head3 getMessage
74  
75 Description :
76 returns the message corresponding for the current error
77  
78 =cut
79  
80 sub getMessage
81 {
82 my ($self)=@_;
83 my $message = '';
84 if ($self->{'error-type'} eq 'constraint'){
85 $message = HTML::GUI::constraint::getMessage($self->{'constraint-info'});
86 }
87 if ($message ne ''){
88 return $message;
89 }
90 if ($self->{message} ne ''){
91 return $self->{message};
92 }
93 return 'no message found for this error';
94 }
95  
96 =pod
97  
98 =head3 getDtHtml
99  
100 Description :
101 Return the html usefull for localize the error (name of the input, or 'General' for internal errors). This Html is meant to be integrated into a definition list. Example : <dt>Date of Birth :</dt>
102  
103 =cut
104  
105 sub getDtHtml
106 {
107 my($self) = @_;
108  
109 my $domain = "General";
110  
111 my $widgetSrc = exists $self->{widgetSrc} ? $self->{widgetSrc} : undef;
112 if ($widgetSrc && ($self->{'error-type'} eq 'constraint')){
113 #we add the informations of a particular widget
114 $domain = $widgetSrc->getLabel();
115 }
116  
117 return $self->getHtmlTag("dt",{},$domain);
118 }
119  
120 =pod
121  
122 =head3 getDdHtml
123  
124 Description :
125 Return the html of the error for the public errors who should be presented to the user. This Html is meant to be integrated into a definition list (ex : <dd> This field is mandatory <a href="#dateOfBirth">Fix it.</a> </dd>).
126  
127 =cut
128  
129 sub getDdHtml
130 {
131 my($self) = @_;
132  
133 my $explanation = $self->escapeHtml( $self->getMessage());
134 my $correctionLink = '';
135  
136 my $widgetSrc = exists $self->{widgetSrc} ? $self->{widgetSrc} : undef;
137 if ($widgetSrc && ($self->{'error-type'} eq 'constraint')){
138 #we add the informations of a particular widget
139 my %tagProp=(href => '#'.$widgetSrc->getId());
140 $correctionLink = $self->getHtmlTag('a',\%tagProp,
141 $self->escapeHtml('Fix it.'));
142 }
143  
144 return $self->getHtmlTag("dd",{},$explanation.$correctionLink);
145 }
146  
147 sub DESTROY{
148 my($self) = @_;
149  
150 delete $self->{widgetSrc};
151 }
152  
153 =head1 AUTHOR
154  
155 Jean-Christian Hassler, C<< <jhassler at free.fr> >>
156  
157 =head1 BUGS
158  
159 Please report any bugs or feature requests to
160 C<bug-gui-libhtml-error at rt.cpan.org>, or through the web interface at
161 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-GUI-widget>.
162 I will be notified, and then you'll automatically be notified of progress on
163 your bug as I make changes.
164  
165 =head1 SUPPORT
166  
167 You can find documentation for this module with the perldoc command.
168  
169 perldoc HTML::GUI::widget
170  
171 You can also look for information at:
172  
173 =over 4
174  
175 =item * AnnoCPAN: Annotated CPAN documentation
176  
177 L<http://annocpan.org/dist/HTML-GUI-widget>
178  
179 =item * CPAN Ratings
180  
181 L<http://cpanratings.perl.org/d/HTML-GUI-widget>
182  
183 =item * RT: CPAN's request tracker
184  
185 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-GUI-widget>
186  
187 =item * Search CPAN
188  
189 L<http://search.cpan.org/dist/HTML-GUI-widget>
190  
191 =back
192  
193 =head1 ACKNOWLEDGEMENTS
194  
195 =head1 COPYRIGHT & LICENSE
196  
197 Copyright 2007 Jean-Christian Hassler, all rights reserved.
198  
199 This program is free software; you can redistribute it and/or modify it
200 under the same terms as Perl itself.
201  
202 =cut
203  
204 1; # End of HTML::GUI::error::error
« text.pm ↑ Summary log/event.pm »