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