File Coverage

blib/lib/Syccess/Error.pm
Criterion Covered Total %
statement 15 15 100.0
branch 2 2 100.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package Syccess::Error;
2             BEGIN {
3 9     9   5060 $Syccess::Error::AUTHORITY = 'cpan:GETTY';
4             }
5             # ABSTRACT: Syccess error message
6             $Syccess::Error::VERSION = '0.103';
7 9     9   61 use Moo;
  9         11  
  9         51  
8              
9             with qw(
10             MooX::Traits
11             );
12              
13             has syccess_field => (
14             is => 'ro',
15             required => 1,
16             );
17              
18             has syccess_result => (
19             is => 'ro',
20             required => 1,
21             );
22              
23             has message => (
24             is => 'lazy',
25             init_arg => undef,
26             );
27              
28             sub _build_message {
29 19     19   6799 my ( $self ) = @_;
30 19         53 my $validator_message = $self->validator_message;
31 19         20 my $format;
32 19         258 my @args = ( $self->syccess_field->label );
33 19 100       51 if (ref $validator_message eq 'ARRAY') {
34 4         4 my @sprintf_args = @{$validator_message};
  4         8  
35 4         7 $format = shift @sprintf_args;
36 4         6 push @args, @sprintf_args;
37             } else {
38 15         19 $format = $validator_message;
39             }
40 19         151 return sprintf($format,@args);
41             }
42              
43             has validator_message => (
44             is => 'ro',
45             init_arg => 'message',
46             required => 1,
47             );
48              
49             1;
50              
51             __END__
52              
53             =pod
54              
55             =head1 NAME
56              
57             Syccess::Error - Syccess error message
58              
59             =head1 VERSION
60              
61             version 0.103
62              
63             =head1 DESCRIPTION
64              
65             This class is used to store an error and will be given back on the call of
66             L<Syccess::Field/errors> or L<Syccess::Result/errors>.
67              
68             =head1 ATTRIBUTES
69              
70             =head2 message
71              
72             Contains the actual resulting error message. See L</validator_message>.
73              
74             =head2 syccess_field
75              
76             References to the L<Syccess::Field> where this error comes from.
77              
78             =head2 syccess_result
79              
80             References to the L<Syccess::Result> where this error comes from.
81              
82             =head2 validator_message
83              
84             This field contains the error message information given back by the validator.
85             I<Syccess::Error> uses this message with B<sprintf> to generate the resulting
86             error message in L</message>. As parameter for the B<sprintf> you will get
87             the label of the field. Alternative the validator can give back an ArrayRef
88             which first element is the format for sprintf, while the rest of the ArrayRef
89             is used as additional parameter for the formatting. This functionality is
90             added to make localization of error messages easier, but its still not tested
91             in a real environment, so changes might happen here.
92              
93             With an own error trait given via L<Syccess/error_traits> you can always
94             override the way how the error messages are generated, if you are not happy
95             with the given procedure.
96              
97             =encoding utf8
98              
99             =head1 SUPPORT
100              
101             IRC
102              
103             Join #sycontent on irc.perl.org. Highlight Getty for fast reaction :).
104              
105             Repository
106              
107             http://github.com/SyContent/Syccess
108             Pull request and additional contributors are welcome
109              
110             Issue Tracker
111              
112             http://github.com/SyContent/Syccess/issues
113              
114             =cut
115              
116             =head1 AUTHOR
117              
118             Torsten Raudssus <torsten@raudss.us>
119              
120             =head1 COPYRIGHT AND LICENSE
121              
122             This software is copyright (c) 2014 by Torsten Raudssus.
123              
124             This is free software; you can redistribute it and/or modify it under
125             the same terms as the Perl 5 programming language system itself.
126              
127             =cut