use strict;
use warnings;
-our $VERSION = '0.76';
+our $VERSION = '0.83';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
use List::MoreUtils qw( first_index uniq );
use Moose::Util::MetaRole;
use Sub::Exporter;
-
+use Sub::Name qw(subname);
my %EXPORT_SPEC;
sub _follow_also_real {
my $exporting_package = shift;
- die "Package in also ($exporting_package) does not seem to use Moose::Exporter"
- unless exists $EXPORT_SPEC{$exporting_package};
+ if (!exists $EXPORT_SPEC{$exporting_package}) {
+ my $loaded = Class::MOP::is_class_loaded($exporting_package);
+
+ die "Package in also ($exporting_package) does not seem to "
+ . "use Moose::Exporter"
+ . ($loaded ? "" : " (is it loaded?)");
+ }
my $also = $EXPORT_SPEC{$exporting_package}{also};
return sub {
my $caller = $CALLER;
- my $wrapper = $self->_make_wrapper($caller, $sub, $fq_name);
+ my $wrapper = $self->_curry_wrapper($sub, $fq_name, $caller);
- my $sub = Class::MOP::subname($fq_name => $wrapper);
+ my $sub = subname($fq_name => $wrapper);
$export_recorder->{$sub} = 1;
};
}
-sub _make_wrapper {
+sub _curry_wrapper {
my $class = shift;
- my $caller = shift;
my $sub = shift;
my $fq_name = shift;
+ my @extra = @_;
- my $wrapper = sub { $sub->($caller, @_) };
+ my $wrapper = sub { $sub->(@extra, @_) };
if (my $proto = prototype $sub) {
# XXX - Perl's prototype sucks. Use & to make set_prototype
- # ignore the fact that we're passing a "provate variable"
+ # ignore the fact that we're passing "private variables"
&Scalar::Util::set_prototype($wrapper, $proto);
}
return $wrapper;
}
}
+sub import {
+ strict->import;
+ warnings->import;
+}
+
1;
__END__
package MyApp::Moose;
- use strict;
- use warnings;
-
use Moose ();
use Moose::Exporter;
sub has_rw {
my ($caller, $name, %options) = @_;
- Class::MOP::Class->initialize($caller)->add_attribute($name,
+ Class::MOP::class_of($caller)->add_attribute($name,
is => 'rw',
%options,
);
=head1 DESCRIPTION
-This module encapsulates the logic to export sugar functions like
-C<Moose.pm>. It does this by building custom C<import> and C<unimport>
-methods for your module, based on a spec your provide.
+This module encapsulates the exporting of sugar functions in a
+C<Moose.pm>-like manner. It does this by building custom C<import> and
+C<unimport> methods for your module, based on a spec you provide.
-It also lets your "stack" Moose-alike modules so you can export
+It also lets you "stack" Moose-alike modules so you can export
Moose's sugar as well as your own, along with sugar from any random
C<MooseX> module, as long as they all use C<Moose::Exporter>.
+To simplify writing exporter modules, C<Moose::Exporter> also imports
+C<strict> and C<warnings> into your exporter module, as well as into
+modules that use it.
+
=head1 METHODS
This module provides two public methods: