File Coverage

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


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