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