Version 1.04
[gitmo/Moose.git] / lib / oose.pm
CommitLineData
3eca5b1c 1package oose;
004222dc 2
3eca5b1c 3use strict;
25374f01 4use warnings;
5
0addec44 6use Class::MOP;
1321f087 7
40290d18 8our $VERSION = '1.04';
75b95414 9$VERSION = eval $VERSION;
25374f01 10our $AUTHORITY = 'cpan:STEVAN';
3eca5b1c 11
12BEGIN {
13 my $package;
d03bd989 14 sub import {
1321f087 15 $package = $_[1] || 'Class';
16 if ($package =~ /^\+/) {
17 $package =~ s/^\+//;
18 Class::MOP::load_class($package);
19 }
20 }
405fb885 21 use Filter::Simple sub { s/^/package $package;\nuse Moose;use Moose::Util::TypeConstraints;\n/; }
3eca5b1c 22}
3eca5b1c 23
25374f01 241;
3eca5b1c 25
25374f01 26__END__
3eca5b1c 27
25374f01 28=pod
3eca5b1c 29
25374f01 30=head1 NAME
3eca5b1c 31
25374f01 32oose - syntactic sugar to make Moose one-liners easier
3eca5b1c 33
34=head1 SYNOPSIS
35
1321f087 36 # create a Moose class on the fly ...
37 perl -Moose=Foo -e 'has bar => ( is=>q[ro], default => q[baz] ); print Foo->new->bar' # prints baz
d03bd989 38
1321f087 39 # loads an existing class (Moose or non-Moose)
40 # and re-"opens" the package definition to make
41 # debugging/introspection easier
d03bd989 42 perl -Moose=+My::Class -e 'print join ", " => __PACKAGE__->meta->get_method_list'
3eca5b1c 43
405fb885 44 # also loads Moose::Util::TypeConstraints to allow subtypes etc
c3455158 45 perl -Moose=Person -e'subtype q[ValidAge] => as q[Int] => where { $_ > 0 && $_ < 78 }; has => age ( isa => q[ValidAge], is => q[ro]); Person->new(age => 90)'
405fb885 46
3eca5b1c 47=head1 DESCRIPTION
48
d03bd989 49oose.pm is a simple source filter that adds C<package $name; use Moose;>
50to the beginning of your script and was entirely created because typing
6549b0d1 51C<perl -e'package Foo; use Moose; ...'> was annoying me.
3eca5b1c 52
d03bd989 53=head1 INTERFACE
3eca5b1c 54
c7874946 55oose provides exactly one method and it's automatically called by perl:
1aa48307 56
25374f01 57=over 4
3eca5b1c 58
25374f01 59=item B<import($package)>
3eca5b1c 60
25374f01 61Pass a package name to import to be used by the source filter.
3eca5b1c 62
63=back
64
3eca5b1c 65=head1 DEPENDENCIES
66
3eca5b1c 67You will need L<Filter::Simple> and eventually L<Moose>
68
3eca5b1c 69=head1 INCOMPATIBILITIES
70
3eca5b1c 71None reported. But it is a source filter and might have issues there.
72
25374f01 73=head1 BUGS
3eca5b1c 74
d4048ef3 75See L<Moose/BUGS> for details on reporting bugs.
3eca5b1c 76
77=head1 AUTHOR
78
405fb885 79Chris Prather C<< <chris@prather.org> >>
3eca5b1c 80
25374f01 81=head1 COPYRIGHT AND LICENSE
3eca5b1c 82
2840a3b2 83Copyright 2007-2009 by Infinity Interactive, Inc.
3eca5b1c 84
25374f01 85L<http://www.iinteractive.com>
3eca5b1c 86
25374f01 87This library is free software; you can redistribute it and/or modify
88it under the same terms as Perl itself.
3eca5b1c 89
25374f01 90=cut