Beginning of dzilization
[gitmo/Moose.git] / lib / oose.pm
1 package oose;
2
3 use strict;
4 use warnings;
5
6 use Class::MOP;
7
8 our $AUTHORITY = 'cpan:STEVAN';
9
10 BEGIN {
11     my $package;
12     sub import {
13         $package = $_[1] || 'Class';
14         if ($package =~ /^\+/) {
15             $package =~ s/^\+//;
16             Class::MOP::load_class($package);
17         }
18     }
19     use Filter::Simple sub { s/^/package $package;\nuse Moose;use Moose::Util::TypeConstraints;\n/; }
20 }
21
22 1;
23
24 # ABSTRACT: syntactic sugar to make Moose one-liners easier
25
26 __END__
27
28 =pod
29
30 =head1 SYNOPSIS
31
32   # create a Moose class on the fly ...
33   perl -Moose=Foo -e 'has bar => ( is=>q[ro], default => q[baz] ); print Foo->new->bar' # prints baz
34
35   # loads an existing class (Moose or non-Moose)
36   # and re-"opens" the package definition to make
37   # debugging/introspection easier
38   perl -Moose=+My::Class -e 'print join ", " => __PACKAGE__->meta->get_method_list'
39
40   # also loads Moose::Util::TypeConstraints to allow subtypes etc
41   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)'
42
43 =head1 DESCRIPTION
44
45 oose.pm is a simple source filter that adds C<package $name; use Moose;>
46 to the beginning of your script and was entirely created because typing
47 C<perl -e'package Foo; use Moose; ...'> was annoying me.
48
49 =head1 INTERFACE
50
51 oose provides exactly one method and it's automatically called by perl:
52
53 =over 4
54
55 =item B<import($package)>
56
57 Pass a package name to import to be used by the source filter.
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