first release
[gitmo/MooseX-AlwaysCoerce.git] / lib / MooseX / AlwaysCoerce.pm
1 package MooseX::AlwaysCoerce;
2
3 use strict;
4 use warnings;
5
6 use namespace::autoclean;
7 use Moose ();
8 use Moose::Exporter;
9 use Carp;
10
11 Moose::Exporter->setup_import_methods (
12     with_caller => [ 'has', 'class_has' ]
13 );
14
15 =head1 NAME
16
17 MooseX::AlwaysCoerce - Automatically enable coercions for Moose attributes
18
19 =head1 VERSION
20
21 Version 0.01
22
23 =cut
24
25 our $VERSION = '0.01';
26
27 =head1 SYNOPSIS
28
29     package MyClass;
30
31     use Moose;
32     use MooseX::ClassAttribute;
33     use MooseX::AlwaysCoerce;
34     use MyTypeLib 'SomeType';
35
36     has foo => (is => 'rw', isa => SomeType); # coerce => 1 automatically added
37
38     # same, but you must load MooseX::ClassAttribute *BEFORE*
39     # MooseX::AlwaysCoerce
40     class_has bar => (is => 'rw', isa => SomeType);
41
42 =head1 DESCRIPTION
43
44 Have you ever spent an hour or more trying to figure out "WTF, why did my
45 coercion not run?" only to find out that you forgot C<< coerce => 1 >> ?
46
47 Just load this module in your L<Moose> class and C<< coerce => 1 >> will be
48 enabled for every attribute automatically.
49
50 =cut
51
52 sub has {
53     push @_, (coerce => 1);
54     goto &Moose::has;
55 }
56
57 sub class_has {
58     push @_, (coerce => 1);
59     goto &MooseX::ClassAttribute::class_has;
60 }
61
62 =head1 AUTHOR
63
64 Rafael Kitover, C<< <rkitover at cpan.org> >>
65
66 =head1 BUGS
67
68 Please report any bugs or feature requests to C<bug-moosex-alwayscoerce at rt.cpan.org>, or through
69 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-AlwaysCoerce>.  I will be notified, and then you'll
70 automatically be notified of progress on your bug as I make changes.
71
72 =head1 SUPPORT
73
74 You can find more information at:
75
76 =over 4
77
78 =item * RT: CPAN's request tracker
79
80 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-AlwaysCoerce>
81
82 =item * AnnoCPAN: Annotated CPAN documentation
83
84 L<http://annocpan.org/dist/MooseX-AlwaysCoerce>
85
86 =item * CPAN Ratings
87
88 L<http://cpanratings.perl.org/d/MooseX-AlwaysCoerce>
89
90 =item * Search CPAN
91
92 L<http://search.cpan.org/dist/MooseX-AlwaysCoerce/>
93
94 =back
95
96 =head1 ACKNOWLEDGEMENTS
97
98 My own stupidity, for inspiring me to write this module.
99
100 =head1 COPYRIGHT & LICENSE
101
102 Copyright (c) 2009 Rafael Kitover
103
104 This program is free software; you can redistribute it and/or modify it
105 under the same terms as Perl itself.
106
107 =cut
108
109 1; # End of MooseX::AlwaysCoerce