lib/MKDoc/Core/Error.pm

filter: Statementstmt 60.0% 9 / 15 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 2 / 4 Podpod 0.0% 0 / 2 totaltotal 47.8% 11 / 23 CC 2 SCAR 11.6
CC
2
Cov
53%
new
6.0
is
2.0
BEGIN
1.0
CRAP 3.2
« blib/lib/MKDoc/Core/SessionPlugin.pm ↑ Summary lib/MKDoc/Core/Init/Petal.pm »
1 =head1 NAME
2  
3 MKDoc::Core::Error - Object validation error mechanism.
4  
5  
6 =head1 SUMMARY
7  
8 When building web apps errors have to be handled in a certain way. It is not possible
9 to rely on Javascript, and die() unless it's eval triggers a 500 internal server error,
10 which is a tad brutal.
11  
12 This class provides a mechanism for web error reporting. When validating a data object,
13 the object can create one or more L<MKDoc::Core::Error> objects. Those object are then
14 caught by a callback subroutine which is set by L<MKDoc::Core::Plugin> objects and then
15 stored as an array reference within L<MKDoc::Core::Plugin> object themselves.
16  
17 This allows the template to access the error array to do proper user error reporting
18 in the event where there would be user input errors which prevent certain objects from
19 validating.
20  
21 When a user is editing some kind of object, it is needed to report all the errors which
22 the user has made. Usually, objects implement a validate() method as follows:
23  
24 sub validate
25 {
26 my $self = shift;
27 return $self->_validate_XXX() &
28 $self->_validate_XXY() &
29 $self->_validate_XXZ();
30 }
31  
32 With each _validate_XXX() method looking like this:
33  
34 sub _validate_silly_check
35 {
36 my $self = shift;
37 $time % 0 && return 1;
38  
39 new MKDoc::Core::Error ( 'time_is_odd' ) :
40 return 0;
41 }
42  
43  
44 =head1 AUTHOR
45  
46 Copyright 2003 - MKDoc Holdings Ltd.
47  
48 Author: Jean-Michel Hiver
49  
50 This module is free software and is distributed under the same license as Perl
51 itself. Use it at your own risk.
52  
53  
54 =head1 SEE ALSO
55  
56 L<Petal> TAL for perl
57 MKDoc: http://www.mkdoc.com/
58  
59 Help us open-source MKDoc. Join the mkdoc-modules mailing list:
60  
61 mkdoc-modules@lists.webarch.co.uk
62  
63 =cut
64 package MKDoc::Core::Error;
65 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68  
69 # $CALLBACK ($coderef);
70 1 our $CALLBACK = undef;
71 1 our $AUTOLOAD;
72  
73  
74 sub new
75 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
76 0 my $class = shift;
77 0 my $self = bless { id => shift() }, $class;
78 0 ▶ $CALLBACK->($self) if (defined $CALLBACK);
Branch: 1 branch
BranchTrueFalseTotal
if defined $MKDoc::Core::Error::CALLBACK 0 0 0
79 0 return $self;
80 }
81  
82  
83 sub is
84 0 ▶{
Subroutine is: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my $self = shift;
86 0 return $self->{id} eq shift;
87 }
88  
89  
90 1 1;
« blib/lib/MKDoc/Core/SessionPlugin.pm ↑ Summary lib/MKDoc/Core/Init/Petal.pm »