X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FInsideOut.pm;h=ba377c7dd2350a6f808cef76f8ae33368fc5171c;hb=71d2a8c6639f8daa394e83f50345369967d2b490;hp=939dcc5451ae73a8b584167439ede12dce20f162;hpb=fff3c901f8a6730647251934b91f86dc9847aa54;p=gitmo%2FMooseX-InsideOut.git diff --git a/lib/MooseX/InsideOut.pm b/lib/MooseX/InsideOut.pm index 939dcc5..ba377c7 100644 --- a/lib/MooseX/InsideOut.pm +++ b/lib/MooseX/InsideOut.pm @@ -4,28 +4,23 @@ use warnings; package MooseX::InsideOut; # ABSTRACT: inside-out objects with Moose -use MooseX::InsideOut::Meta::Class; -BEGIN { require Moose } -use Carp; - -sub import { - my $class = shift; - - if (@_) { Carp::confess "$class has no exports" } - - my $into = caller; - - return if $into eq 'main'; - - Moose::init_meta( - $into, - 'Moose::Object', - 'MooseX::InsideOut::Meta::Class', +use Moose (); +use Moose::Exporter; +use Moose::Util::MetaRole; +use MooseX::InsideOut::Role::Meta::Instance; + +Moose::Exporter->setup_import_methods( + also => [ 'Moose' ], +); + +sub init_meta { + shift; + my %p = @_; + Moose->init_meta(%p); + Moose::Util::MetaRole::apply_metaclass_roles( + for_class => $p{for_class}, + instance_metaclass_roles => [ 'MooseX::InsideOut::Role::Meta::Instance' ], ); - - Moose->import({ into => $into }); - - return; } 1; @@ -42,22 +37,19 @@ __END__ package My::Subclass; - use metaclass 'MooseX::InsideOut::Meta::Class'; - use Moose; + use MooseX::InsideOut; extends 'Some::Other::Class'; =head1 DESCRIPTION -MooseX::InsideOut provides a metaclass and an instance metaclass for inside-out -objects. +MooseX::InsideOut provides metaroles for inside-out objects. That is, it sets +up attribute slot storage somewhere other than inside C<$self>. This means +that you can extend non-Moose classes, whose internals you either don't want to +care about or aren't hash-based. -You can use MooseX::InsideOut, as in the first example in the L. -This sets up the metaclass and instance metaclass for you, as well as importing -all of the normal Moose goodies. +=method init_meta -You can also use the metaclass C directly, as -in the second example. This is most useful when extending a non-Moose class, -whose internals you either don't want to care about or aren't hash-based. +Apply the instance metarole necessary for inside-out storage. =head1 TODO