File Coverage

lib/MooseX/Attribute/ValidateWithException.pm
Criterion Covered Total %
statement 11 13 84.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 16 18 88.8


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