File Coverage

blib/lib/MooseX/Role/Validatable/Error.pm
Criterion Covered Total %
statement 13 13 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 3 3 100.0
pod 1 1 100.0
total 19 21 90.4


line stmt bran cond sub pod time code
1             package MooseX::Role::Validatable::Error;
2              
3 2     2   55984 use Moose;
  2         378294  
  2         13  
4              
5             our $VERSION = '0.12'; ## VERSION
6              
7             has message => (
8             is => 'ro',
9             required => 1,
10             );
11              
12             has message_to_client => (
13             is => 'ro',
14             required => 1,
15             );
16              
17             has details => (
18             is => 'ro',
19             isa => 'HashRef',
20             required => 0,
21             );
22              
23             has set_by => (
24             is => 'ro',
25             required => 1,
26             );
27              
28             has severity => (
29             is => 'ro',
30             isa => 'Int',
31             default => sub { 1 },
32             );
33              
34             has transient => (
35             is => 'ro',
36             isa => 'Bool',
37             default => sub { 0 },
38             );
39              
40             has alert => (
41             is => 'ro',
42             isa => 'Bool',
43             default => sub { 0 },
44             );
45              
46             has info_link => (is => 'ro');
47             has info_text => (is => 'ro');
48              
49             has code => (
50             is => 'ro',
51             isa => 'Str',
52             default => sub {
53             return 'General';
54             },
55             );
56              
57             sub as_html {
58 2     2 1 4 my $self = shift;
59              
60 2         66 my $html = "<p>" . $self->message_to_client;
61 2 50       52 if (my $info_link = $self->info_link) {
62 2   50     51 my $info_text = $self->info_text || 'More Info...';
63 2         8 $html .= qq~<a href="$info_link" class="info_link">$info_text</a>\n~;
64             }
65 2         3 $html .= "</p>\n";
66              
67 2         11 return $html;
68             }
69              
70 2     2   13016 no Moose;
  2         4  
  2         10  
71             __PACKAGE__->meta->make_immutable;
72              
73             1;
74             __END__
75              
76             =encoding utf-8
77              
78             =head1 NAME
79              
80             MooseX::Role::Validatable::Error - Base Error class for MooseX::Role::Validatable
81              
82             =head1 SYNOPSIS
83              
84             use MooseX::Role::Validatable;
85              
86             my $error = MooseX::Role::Validatable::Error->new({
87             message => 'Internal debug message.', # Required
88             message_to_client => 'Client-facing message', # Required
89             details => { field => 'duration' }, # Optional, Must be a HashRef
90             set_by => 'Source of the error', # Required; MAY default to caller(1)
91             severity => 5, # For ordering, bigger is worse. Defaults to 1.
92             transient => 1, # Boolean, defaults to false
93             alert => 1, # Boolean, defaults to false
94             info_link => 'https://example.com/', # Client-facing URI for additional info on this error.
95             });
96              
97             =head1 DESCRIPTION
98              
99             Represents an error in validation
100              
101             =head1 ATTRIBUTES
102              
103             =head2 message
104              
105             A message which might help us figure out what is wrong.
106              
107             =head2 details
108              
109             An arbitrary optional HashRef to pass the error details.
110              
111             =head2 message_to_client
112              
113             A client-friendly string describing the error.
114              
115             =head2 set_by
116              
117             The source of the error.
118              
119             =head2 severity
120              
121             How bad is it that this happened?
122              
123             =head2 transient
124              
125             Is this something likely to resolve itself with a little time?
126              
127             =head2 alert
128              
129             Should someone be alerted when this condition triggers?
130              
131             =head2 info_link
132              
133             A URI for further explanation of the error.
134              
135             =head2 info_text
136              
137             Description of the info_link
138              
139             =head2 as_html
140              
141             =head2 code
142              
143             Error code in string.
144              
145             =head1 AUTHOR
146              
147             Binary.com E<lt>fayland@binary.comE<gt>
148              
149             =head1 COPYRIGHT
150              
151             Copyright 2014- Binary.com
152              
153             =head1 LICENSE
154              
155             This library is free software; you can redistribute it and/or modify
156             it under the same terms as Perl itself.
157              
158             =head1 SEE ALSO
159              
160             =cut