};
# grab all *non-constant* (stash slot is not a scalarref) subs present
# in the symbol table and store their refaddrs (no need to forcibly
- # inflate constant subs into real subs) - also add '' to here (this
- # is used later) with a map to the coderefs in case of copying or re-use
- my @not_methods = ('', map { *$_{CODE}||() } grep !ref($_), values %$stash);
+ # inflate constant subs into real subs) with a map to the coderefs in
+ # case of copying or re-use
+ my @not_methods = (map { *$_{CODE}||() } grep !ref($_), values %$stash);
@{$INFO{$target}{not_methods}={}}{@not_methods} = @not_methods;
# a role does itself
$APPLIED_TO{$target} = { $target => undef };
# grab all code entries that aren't in the not_methods list
map {
my $code = *{$stash->{$_}}{CODE};
- # rely on the '' key we added in import for "no code here"
- ( ! $code or exists $not_methods->{$code||''} ) ? () : ($_ => $code)
+ ( ! $code or exists $not_methods->{$code} ) ? () : ($_ => $code)
} grep !ref($stash->{$_}), keys %$stash
};
}
--- /dev/null
+use strict;
+use warnings FATAL => 'all';
+use Test::More;
+use Test::Fatal;
+
+{
+ package MyRole1;
+
+ sub before_role {}
+
+ use Role::Tiny;
+
+ our $GLOBAL1 = 1;
+ sub after_role {}
+}
+
+{
+ package MyClass1;
+
+ our $GLOBAL1 = 1;
+ sub method {}
+}
+
+my $role_methods = Role::Tiny->_concrete_methods_of('MyRole1');
+is_deeply([sort keys %$role_methods], ['after_role'],
+ 'only subs after Role::Tiny import are methods' );
+
+my $class_methods = Role::Tiny->_concrete_methods_of('MyClass1');
+is_deeply([sort keys %$class_methods], ['method'],
+ 'only subs from non-Role::Tiny packages are methods' );
+
+done_testing;