exports. Sigh.
use Moose::Util ();
sub extends {
- my $class = caller();
+ my $class = shift;
croak "Must derive at least one class" unless @_;
}
sub with {
- my $class = caller();
+ my $class = shift;
Moose::Util::apply_all_roles($class->meta, @_);
}
sub has {
- my $class = caller();
+ my $class = shift;
my $name = shift;
croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1;
my %options = @_;
}
sub before {
- my $class = caller();
+ my $class = shift;
Moose::Util::add_method_modifier($class, 'before', \@_);
}
sub after {
- my $class = caller();
+ my $class = shift;
Moose::Util::add_method_modifier($class, 'after', \@_);
}
sub around {
- my $class = caller();
+ my $class = shift;
Moose::Util::add_method_modifier($class, 'around', \@_);
}
}
sub override {
- my $class = caller();
+ my $class = shift;
my ( $name, $method ) = @_;
$class->meta->add_override_method_modifier( $name => $method );
}
}
sub augment {
- my $class = caller();
+ my $class = shift;
my ( $name, $method ) = @_;
$class->meta->add_augment_method_modifier( $name => $method );
}
sub make_immutable {
- my $class = caller();
+ my $class = shift;
cluck "The make_immutable keyword has been deprecated, " .
"please go back to __PACKAGE__->meta->make_immutable\n";
$class->meta->make_immutable(@_);
}
my $exporter = Moose::Exporter->build_import_methods(
- export => [
- qw( extends with has before after around override augment make_immutable super inner ),
+ with_caller => [
+ qw( extends with has before after around override augment make_immutable )
+ ],
+ as_is => [
+ qw( super inner ),
\&Carp::confess,
\&Scalar::Util::blessed,
],
);
my $import = $class->_make_import_sub(
- $exporting_package,
- $args{init_meta_args},
+ $exporting_package, $args{init_meta_args},
$exporter
);
my @exported_names;
my %exports;
- for my $name ( @{ $args{export} } ) {
+ for my $name ( @{ $args{with_caller} } ) {
+ my $sub = do { no strict 'refs'; \&{ $exporting_package . '::' . $name } };
+
+ my $wrapped = Class::MOP::subname(
+ $exporting_package . '::' . $name => sub { $sub->( scalar caller(), @_ ) } );
+
+ $exports{$name} = sub { $wrapped };
+
+ push @exported_names, $name;
+ }
+
+ for my $name ( @{ $args{as_is} } ) {
my $sub;
+
if ( ref $name ) {
$sub = $name;
$name = ( Class::MOP::get_code_info($name) )[1];
}
$exports{$name} = sub { $sub };
-
- push @exported_names, $name;
}
my $exporter = Sub::Exporter::build_exporter(
if ( $exporting_package->can('_init_meta') ) {
$exporting_package->_init_meta(
- %{ $init_meta_args || {} },
for_class => $caller,
+ %{ $init_meta_args || {} }
);
}
=over 4
-=item * export => [ ... ]
+=item * with_caller => [ ... ]
+
+This a list of function I<names only> to be exported wrapped and then
+exported. The wrapper will pass the name of the calling package as the
+first argument to the function. Many sugar functions need to know
+their caller so they can get the calling package's metaclass object.
+
+=item * as_is => [ ... ]
This a list of function names or sub references to be exported
as-is. You can identify a subroutine by reference, which is handy to
}
sub with {
- my $role = caller();
- Moose::Util::apply_all_roles( $role->meta(), @_ );
+ Moose::Util::apply_all_roles( shift->meta(), @_ );
}
sub requires {
- my $role = caller();
- my $meta = $role->meta();
+ my $meta = shift->meta();
croak "Must specify at least one method" unless @_;
$meta->add_required_methods(@_);
}
sub excludes {
- my $role = caller();
- my $meta = $role->meta();
+ my $meta = shift->meta();
croak "Must specify at least one role" unless @_;
$meta->add_excluded_roles(@_);
}
sub has {
- my $role = caller();
- my $meta = $role->meta();
+ my $meta = shift->meta();
my $name = shift;
croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1;
my %options = @_;
}
sub before {
- my $role = caller();
- my $meta = $role->meta();
+ my $meta = shift->meta();
my $code = pop @_;
for (@_) {
}
sub after {
- my $role = caller();
- my $meta = $role->meta();
+ my $meta = shift->meta();
my $code = pop @_;
for (@_) {
}
sub around {
- my $role = caller();
- my $meta = $role->meta();
+ my $meta = shift->meta();
my $code = pop @_;
for (@_) {
croak "Moose::Role do not currently support "
}
sub override {
- my $role = caller();
- my $meta = $role->meta();
+ my $meta = shift->meta();
my ( $name, $code ) = @_;
$meta->add_override_method_modifier( $name, $code );
}
}
my $exporter = Moose::Exporter->build_import_methods(
- export => [
- qw( with requires excludes has before after around override extends super inner augment ),
+ with_caller => [
+ qw( with requires excludes has before after around override make_immutable )
+ ],
+ as_is => [
+ qw( extends super inner augment ),
\&Carp::confess,
\&Scalar::Util::blessed,
],