}
sub extends {
- my $class = shift;
+ my $meta = shift;
Moose->throw_error("Must derive at least one class") unless @_;
# this checks the metaclass to make sure
# it is correct, sometimes it can get out
# of sync when the classes are being built
- Moose::Meta::Class->initialize($class)->superclasses(@_);
+ $meta->superclasses(@_);
}
sub with {
- my $class = shift;
- Moose::Util::apply_all_roles(Class::MOP::Class->initialize($class), @_);
+ Moose::Util::apply_all_roles(shift, @_);
}
sub has {
- my $class = shift;
- my $name = shift;
+ my $meta = shift;
+ my $name = shift;
Moose->throw_error('Usage: has \'name\' => ( key => value, ... )')
if @_ % 2 == 1;
my %options = ( definition_context => Moose::Util::_caller_info(), @_ );
my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
- Class::MOP::Class->initialize($class)->add_attribute( $_, %options ) for @$attrs;
+ $meta->add_attribute( $_, %options ) for @$attrs;
}
sub before {
- my $class = shift;
- Moose::Util::add_method_modifier($class, 'before', \@_);
+ Moose::Util::add_method_modifier(shift, 'before', \@_);
}
sub after {
- my $class = shift;
- Moose::Util::add_method_modifier($class, 'after', \@_);
+ Moose::Util::add_method_modifier(shift, 'after', \@_);
}
sub around {
- my $class = shift;
- Moose::Util::add_method_modifier($class, 'around', \@_);
+ Moose::Util::add_method_modifier(shift, 'around', \@_);
}
our $SUPER_PACKAGE;
}
sub override {
- my $class = shift;
+ my $meta = shift;
my ( $name, $method ) = @_;
- Class::MOP::Class->initialize($class)->add_override_method_modifier( $name => $method );
+ $meta->add_override_method_modifier( $name => $method );
}
sub inner {
}
sub augment {
- my $class = shift;
+ my $meta = shift;
my ( $name, $method ) = @_;
- Class::MOP::Class->initialize($class)->add_augment_method_modifier( $name => $method );
+ $meta->add_augment_method_modifier( $name => $method );
}
Moose::Exporter->setup_import_methods(
- with_caller => [
+ with_meta => [
qw( extends with has before after around override augment)
],
as_is => [
use Moose::Exporter;
Moose::Exporter->setup_import_methods(
- with_caller => ['embiggen'],
- also => 'Moose',
+ with_meta => ['embiggen'],
+ also => 'Moose',
);
sub embiggen {
- my $caller = shift;
- $caller->meta()->embiggen(@_);
+ my $meta = shift;
+ $meta->embiggen(@_);
}
And then the consumer of your extension can use your C<embiggen> sub:
use Moose::Exporter;
Moose::Exporter->setup_import_methods(
- with_caller => ['has_table'],
- also => 'Moose',
+ with_meta => ['has_table'],
+ also => 'Moose',
);
sub init_meta {
}
sub has_table {
- my $caller = shift;
- $caller->meta->table(shift);
+ my $meta = shift;
+ $meta->table(shift);
}
package MyApp::Meta::Class;
Moose> with C<use MyApp::Mooseish>. Similarly, C<no Moose> is now
replaced with C<no MyApp::Mooseish>.
-The C<with_caller> parameter specifies a list of functions that should
+The C<with_meta> parameter specifies a list of functions that should
be wrapped before exporting. The wrapper simply ensures that the
importing package name is the first argument to the function, so we
can do C<S<my $caller = shift;>>.
}
sub with {
- Moose::Util::apply_all_roles( Moose::Meta::Role->initialize(shift), @_ );
+ Moose::Util::apply_all_roles( shift, @_ );
}
sub requires {
- my $meta = Moose::Meta::Role->initialize(shift);
+ my $meta = shift;
croak "Must specify at least one method" unless @_;
$meta->add_required_methods(@_);
}
sub excludes {
- my $meta = Moose::Meta::Role->initialize(shift);
+ my $meta = shift;
croak "Must specify at least one role" unless @_;
$meta->add_excluded_roles(@_);
}
sub has {
- my $meta = Moose::Meta::Role->initialize(shift);
+ my $meta = shift;
my $name = shift;
croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1;
my %options = ( definition_context => Moose::Util::_caller_info(), @_ );
sub _add_method_modifier {
my $type = shift;
- my $meta = Moose::Meta::Role->initialize(shift);
+ my $meta = shift;
my $code = pop @_;
for (@_) {
}
sub override {
- my $meta = Moose::Meta::Role->initialize(shift);
+ my $meta = shift;
my ( $name, $code ) = @_;
$meta->add_override_method_modifier( $name, $code );
}
}
Moose::Exporter->setup_import_methods(
- with_caller => [
+ with_meta => [
qw( with requires excludes has before after around override )
],
as_is => [
sub add_method_modifier {
my ( $class_or_obj, $modifier_name, $args ) = @_;
- my $meta = find_meta($class_or_obj);
+ my $meta
+ = $class_or_obj->can('add_before_method_modifier')
+ ? $class_or_obj
+ : find_meta($class_or_obj);
my $code = pop @{$args};
my $add_modifier_method = 'add_' . $modifier_name . '_method_modifier';
if ( my $method_modifier_type = ref( @{$args}[0] ) ) {