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