File Coverage

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


line stmt bran cond sub pod time code
1 2     2   319886 use strict;
  2         4  
  2         55  
2 2     2   8 use warnings;
  2         3  
  2         102  
3              
4             package MooseX::Attribute::ValidateWithException;
5             BEGIN {
6 2     2   60 $MooseX::Attribute::ValidateWithException::AUTHORITY = 'cpan:KENTNL';
7             }
8             {
9             $MooseX::Attribute::ValidateWithException::VERSION = '0.3.0'; # TRIAL
10             }
11              
12             # ABSTRACT: Cause validation failures to throw exception objects.
13              
14             require Moose;
15 2     2   418 use Moose::Exporter;
  2         91987  
  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             1;
23              
24             __END__
25              
26             =pod
27              
28             =encoding UTF-8
29              
30             =head1 NAME
31              
32             MooseX::Attribute::ValidateWithException - Cause validation failures to throw exception objects.
33              
34             =head1 VERSION
35              
36             version 0.3.0
37              
38             =head1 SYNOPSIS
39              
40             {
41             package Foo;
42             use Moose;
43             use MooseX::Attribute::ValidateWithException;
44              
45             has foo => (
46             isa => 'Str',
47             is => 'rw',
48             required => 1,
49             );
50             __PACKAGE__->meta->make_immutable;
51             no Moose;
52             }
53              
54             use Try::Tiny;
55              
56             try {
57             Foo->new( foo => { this_is => [qw( not what we were wanting )] } );
58             } catch {
59             say $_->name if blessed( $_ ) && $_->isa('Thingy');
60             };
61              
62             =head1 DESCRIPTION
63              
64             B<ALPHA QUALITY SOFTWARE>.
65              
66             At present, when an attribute fails validation, Moose internally die()'s with a
67             string. There is also no way to throw an exception object as part of the
68             validation message, ( in order to give more context on the problem ), without
69             also breaking how much of the validation works.
70              
71             This module is an experiment in providing that feature, which really should be
72             done in Moose itself, and done better, which is why it has been given such an
73             obtuse name.
74              
75             This module makes no promises of forwards compatibility with a future Moose
76             release, in order to permit Moose to do whatever they want and not worry about
77             "breaking code" that uses this module. ( So that they can easily replace this
78             module in incompatible ways )
79              
80             B<< If your code breaking is unacceptable, do I<not> use this module >>.
81              
82             Use of this module assumes several things.
83              
84             =over 4
85              
86             =item 1. You are o.k. with your code breaking in a future Moose release.
87              
88             =item 2. You are o.k. with re-writing any and all code that depends on this
89             functionality, if a future Moose release is incompatible with this module.
90              
91             =back
92              
93             I'm not saying I won't do my best to provide forwards compatibility, but it is
94             highly unlikely it will be possible, due to differences in package naming
95             which may be essential for handling exceptions.
96              
97             =head1 AUTHOR
98              
99             Kent Fredric <kentnl@cpan.org>
100              
101             =head1 COPYRIGHT AND LICENSE
102              
103             This software is copyright (c) 2013 by Kent Fredric <kentnl@cpan.org>.
104              
105             This is free software; you can redistribute it and/or modify it under
106             the same terms as the Perl 5 programming language system itself.
107              
108             =cut