File Coverage

blib/lib/MooseX/Attribute/ValidateWithException.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 15 15 100.0


line stmt bran cond sub pod time code
1             ## no critic (Moose::RequireMakeImmutable)
2 2     2   324961 use 5.006; # warnings
  2         5  
3 2     2   8 use strict;
  2         2  
  2         41  
4 2     2   6 use warnings;
  2         1  
  2         151  
5              
6             package MooseX::Attribute::ValidateWithException;
7              
8             our $VERSION = 'v0.4.0';
9              
10             # ABSTRACT: Cause validation failures to throw exception objects.
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14             require Moose;
15 2     2   455 use Moose::Exporter;
  2         90565  
  2         14  
16             require MooseX::Attribute::ValidateWithException::AttributeRole;
17              
18             Moose::Exporter->setup_import_methods(
19             class_metaroles => { attribute => ['MooseX::Attribute::ValidateWithException::AttributeRole'], }, );
20              
21              
22              
23              
24              
25              
26              
27              
28              
29              
30              
31              
32              
33              
34              
35              
36              
37              
38              
39              
40              
41              
42              
43              
44              
45              
46              
47              
48              
49              
50              
51              
52              
53              
54              
55              
56              
57              
58              
59              
60              
61              
62              
63              
64              
65              
66              
67              
68              
69              
70              
71              
72              
73              
74              
75              
76              
77              
78              
79              
80              
81              
82             1;
83              
84             __END__
85              
86             =pod
87              
88             =encoding UTF-8
89              
90             =head1 NAME
91              
92             MooseX::Attribute::ValidateWithException - Cause validation failures to throw exception objects.
93              
94             =head1 VERSION
95              
96             version v0.4.0
97              
98             =head1 SYNOPSIS
99              
100             {
101             package Foo;
102             use Moose;
103             use MooseX::Attribute::ValidateWithException;
104              
105             has foo => (
106             isa => 'Str',
107             is => 'rw',
108             required => 1,
109             );
110             __PACKAGE__->meta->make_immutable;
111             no Moose;
112             }
113              
114             use Try::Tiny;
115              
116             try {
117             Foo->new( foo => { this_is => [qw( not what we were wanting )] } );
118             } catch {
119             say $_->name if blessed( $_ ) && $_->isa('Thingy');
120             };
121              
122             =head1 DESCRIPTION
123              
124             B<ALPHA QUALITY SOFTWARE>.
125              
126             At present, when an attribute fails validation, Moose internally die()'s with a
127             string. There is also no way to throw an exception object as part of the
128             validation message, ( in order to give more context on the problem ), without
129             also breaking how much of the validation works.
130              
131             This module is an experiment in providing that feature, which really should be
132             done in Moose itself, and done better, which is why it has been given such an
133             obtuse name.
134              
135             This module makes no promises of forwards compatibility with a future Moose
136             release, in order to permit Moose to do whatever they want and not worry about
137             "breaking code" that uses this module. ( So that they can easily replace this
138             module in incompatible ways )
139              
140             B<< If your code breaking is unacceptable, do I<not> use this module >>.
141              
142             Use of this module assumes several things.
143              
144             =over 4
145              
146             =item 1. You are o.k. with your code breaking in a future Moose release.
147              
148             =item 2. You are o.k. with re-writing any and all code that depends on this
149             functionality, if a future Moose release is incompatible with this module.
150              
151             =back
152              
153             I'm not saying I won't do my best to provide forwards compatibility, but it is
154             highly unlikely it will be possible, due to differences in package naming
155             which may be essential for handling exceptions.
156              
157             =head1 AUTHOR
158              
159             Kent Fredric <kentnl@cpan.org>
160              
161             =head1 COPYRIGHT AND LICENSE
162              
163             This software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>.
164              
165             This is free software; you can redistribute it and/or modify it under
166             the same terms as the Perl 5 programming language system itself.
167              
168             =cut