Commit | Line | Data |
---|---|---|
3eca5b1c | 1 | package oose; |
004222dc | 2 | |
3eca5b1c | 3 | use strict; |
25374f01 | 4 | use warnings; |
5 | ||
b5ae7c00 | 6 | use Class::Load qw(load_class); |
1321f087 | 7 | |
3eca5b1c | 8 | BEGIN { |
9 | my $package; | |
d03bd989 | 10 | sub import { |
1321f087 | 11 | $package = $_[1] || 'Class'; |
12 | if ($package =~ /^\+/) { | |
13 | $package =~ s/^\+//; | |
b5ae7c00 | 14 | load_class($package); |
1321f087 | 15 | } |
16 | } | |
405fb885 | 17 | use Filter::Simple sub { s/^/package $package;\nuse Moose;use Moose::Util::TypeConstraints;\n/; } |
3eca5b1c | 18 | } |
3eca5b1c | 19 | |
25374f01 | 20 | 1; |
3eca5b1c | 21 | |
ad46f524 | 22 | # ABSTRACT: syntactic sugar to make Moose one-liners easier |
23 | ||
25374f01 | 24 | __END__ |
3eca5b1c | 25 | |
25374f01 | 26 | =pod |
3eca5b1c | 27 | |
3eca5b1c | 28 | =head1 SYNOPSIS |
29 | ||
1321f087 | 30 | # create a Moose class on the fly ... |
31 | perl -Moose=Foo -e 'has bar => ( is=>q[ro], default => q[baz] ); print Foo->new->bar' # prints baz | |
d03bd989 | 32 | |
1321f087 | 33 | # loads an existing class (Moose or non-Moose) |
34 | # and re-"opens" the package definition to make | |
35 | # debugging/introspection easier | |
d03bd989 | 36 | perl -Moose=+My::Class -e 'print join ", " => __PACKAGE__->meta->get_method_list' |
3eca5b1c | 37 | |
405fb885 | 38 | # also loads Moose::Util::TypeConstraints to allow subtypes etc |
c3455158 | 39 | 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 | 40 | |
3eca5b1c | 41 | =head1 DESCRIPTION |
42 | ||
5a97faae | 43 | oose.pm is a simple source filter that adds |
44 | C<package $name; use Moose; use Moose::Util::TypeConstraints;> | |
d03bd989 | 45 | to the beginning of your script and was entirely created because typing |
6549b0d1 | 46 | C<perl -e'package Foo; use Moose; ...'> was annoying me. |
3eca5b1c | 47 | |
d03bd989 | 48 | =head1 INTERFACE |
3eca5b1c | 49 | |
c7874946 | 50 | oose provides exactly one method and it's automatically called by perl: |
1aa48307 | 51 | |
25374f01 | 52 | =over 4 |
3eca5b1c | 53 | |
25374f01 | 54 | =item B<import($package)> |
3eca5b1c | 55 | |
5a97faae | 56 | Pass a package name to import to be used by the source filter. The |
57 | package defaults to C<Class> if none is given. | |
3eca5b1c | 58 | |
59 | =back | |
60 | ||
3eca5b1c | 61 | =head1 DEPENDENCIES |
62 | ||
3eca5b1c | 63 | You will need L<Filter::Simple> and eventually L<Moose> |
64 | ||
3eca5b1c | 65 | =head1 INCOMPATIBILITIES |
66 | ||
3eca5b1c | 67 | None reported. But it is a source filter and might have issues there. |
68 | ||
25374f01 | 69 | =head1 BUGS |
3eca5b1c | 70 | |
d4048ef3 | 71 | See L<Moose/BUGS> for details on reporting bugs. |
3eca5b1c | 72 | |
25374f01 | 73 | =cut |