File Coverage

blib/lib/MooseX/Exception/Base/Stringify.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package MooseX::Exception::Base::Stringify;
2              
3             # Created on: 2012-07-11 11:07:06
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 2     2   749 use Moose::Role;
  2         6453  
  2         8  
10 2     2   8027 use strict;
  2         3  
  2         47  
11 2     2   6 use warnings;
  2         3  
  2         41  
12 2     2   6 use version;
  2         3  
  2         10  
13              
14             our $VERSION = version->new('0.0.5');
15              
16             Moose::Util::meta_attribute_alias('MooseX::Exception::Stringify');
17              
18             has stringify_pre => (
19             is => 'rw',
20             isa => 'Str',
21             predicate => 'has_stringify_pre',
22             );
23             has stringify_post => (
24             is => 'rw',
25             isa => 'Str',
26             predicate => 'has_stringify_post',
27             );
28             has stringify => (
29             is => 'rw',
30             isa => 'CodeRef',
31             predicate => 'has_stringify',
32             );
33              
34             1;
35              
36             __END__
37              
38             =head1 NAME
39              
40             MooseX::Exception::Base::Stringify - Traits class for attributes that are to be stringified.
41              
42             =head1 VERSION
43              
44             This documentation refers to MooseX::Exception::Base::Stringify version 0.0.5.
45              
46              
47             =head1 SYNOPSIS
48              
49             use Moose;
50             use MooseX::Exception::Base::Stringify;
51              
52             # cause a MooseX::Exception::Base to output this value
53             has my_attrib => (
54             is => 'rw',
55             isa => 'Str',
56             traits => [qw{MooseX::Exception::Stringify}],
57             );
58              
59             # custom stringification from an object
60             has my_date => (
61             is => 'rw',
62             isa => 'DateTime',
63             traits => [qw{MooseX::Exception::Stringify}],
64             stringify => sub {$_->ymd},
65             );
66              
67             # causes the stringified object to show the my_message value
68             # something like 'Message : ' . $obj->my_message
69             has my_message => (
70             is => 'rw',
71             isa => 'Str',
72             traits => [qw{MooseX::Exception::Stringify}],
73             stringify_pre => 'Message : ',
74             );
75              
76             # like with stringify_pre the value has stringify_post appended
77             # $obj->my_post . ' km/h'
78             has my_post => (
79             is => 'rw',
80             isa => 'Num',
81             traits => [qw{MooseX::Exception::Stringify}],
82             stringify_post => ' km/h',
83             );
84              
85             =head1 DESCRIPTION
86              
87             Defines the trait (MooseX::Exception::Stringify) for L<MooseX::Exception::Base>
88             objects that want other parameters to be stringified along with the error
89             object.
90              
91             =head1 INCOMPATIBILITIES
92              
93             =head1 BUGS AND LIMITATIONS
94              
95             There are no known bugs in this module.
96              
97             Please report problems to Ivan Wills (ivan.wills@gmail.com).
98              
99             Patches are welcome.
100              
101             =head1 AUTHOR
102              
103             Ivan Wills - (ivan.wills@gmail.com)
104              
105             =head1 LICENSE AND COPYRIGHT
106              
107             Copyright (c) 2012 Ivan Wills (14 Mullion Close Hornsby Heights NSW Australia 2077).
108             All rights reserved.
109              
110             This module is free software; you can redistribute it and/or modify it under
111             the same terms as Perl itself. See L<perlartistic>. This program is
112             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
113             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
114             PARTICULAR PURPOSE.
115              
116             =cut