'get_method_map' => sub {
my $self = shift;
my $map = $self->{'%:methods'};
-
foreach my $symbol ($self->list_all_package_symbols('CODE')) {
my $code = $self->get_package_symbol('&' . $symbol);
-
- next if exists $map->{$symbol} &&
- $map->{$symbol}->body == $code;
-
+ next if exists $map->{$symbol} && $map->{$symbol}->body == $code;
$map->{$symbol} = $self->method_metaclass->wrap($code);
}
-
- return $map;
+ return $map;
}
},
default => sub { {} }
sub get_method_map {
my $self = shift;
my $map = $self->{'%:methods'};
-
foreach my $symbol ($self->list_all_package_symbols('CODE')) {
- next if exists $map->{$symbol} &&
- $map->{$symbol}->body == $self->get_package_symbol('&' . $symbol);
-
- $map->{$symbol} = $self->method_metaclass->wrap(
- $self->get_package_symbol('&' . $symbol)
- );
+ my $code = $self->get_package_symbol('&' . $symbol);
+ next if exists $map->{$symbol} && $map->{$symbol}->body == $code;
+ $map->{$symbol} = $self->method_metaclass->wrap($code);
}
-
return $map;
}
# informational
sub package_name {
- my $code = shift->{body};
-# (blessed($code))
-# || confess "Can only ask the package name of a blessed CODE";
+ my $code = (shift)->{body};
svref_2object($code)->GV->STASH->NAME;
}
sub name {
- my $code = shift->{body};
-# (blessed($code))
-# || confess "Can only ask the package name of a blessed CODE";
+ my $code = (shift)->{body};
svref_2object($code)->GV->NAME;
}
sub fully_qualified_name {
my $code = shift;
-# (blessed($code))
-# || confess "Can only ask the package name of a blessed CODE";
$code->package_name . '::' . $code->name;
}
sub add_before_modifier {
my $code = shift;
my $modifier = shift;
- #(exists $MODIFIERS{$code})
- # || confess "You must first wrap your method before adding a modifier";
- (blessed($code))
- || confess "Can only ask the package name of a blessed CODE";
- #('CODE' eq (reftype($code) || ''))
- # || confess "You must supply a CODE reference for a modifier";
unshift @{$code->{modifier_table}->{before}} => $modifier;
$_build_wrapped_method->($code->{modifier_table});
}
sub add_after_modifier {
my $code = shift;
my $modifier = shift;
- #(exists $MODIFIERS{$code})
- # || confess "You must first wrap your method before adding a modifier";
- (blessed($code))
- || confess "Can only ask the package name of a blessed CODE";
- #('CODE' eq (reftype($code) || ''))
- # || confess "You must supply a CODE reference for a modifier";
push @{$code->{modifier_table}->{after}} => $modifier;
$_build_wrapped_method->($code->{modifier_table});
}
sub add_around_modifier {
my $code = shift;
my $modifier = shift;
- #(exists $MODIFIERS{$code})
- # || confess "You must first wrap your method before adding a modifier";
- (blessed($code))
- || confess "Can only ask the package name of a blessed CODE";
- #('CODE' eq (reftype($code) || ''))
- # || confess "You must supply a CODE reference for a modifier";
unshift @{$code->{modifier_table}->{around}->{methods}} => $modifier;
$code->{modifier_table}->{around}->{cache} = $compile_around_method->(
@{$code->{modifier_table}->{around}->{methods}},
sub list_all_package_symbols {
my ($self, $type_filter) = @_;
return keys %{$self->namespace} unless defined $type_filter;
+ # NOTE:
# or we can filter based on
# type (SCALAR|ARRAY|HASH|CODE)
my $namespace = $self->namespace;
- return grep { defined(*{$namespace->{$_}}{$type_filter}) } keys %{$namespace};
+ return grep {
+ defined(*{$namespace->{$_}}{$type_filter})
+ } keys %{$namespace};
}
1;