File Coverage

blib/lib/MooX/Role/Validatable/Error.pm
Criterion Covered Total %
statement 16 16 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 4 4 100.0
pod 0 1 0.0
total 22 25 88.0


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