summaryrefslogtreecommitdiff
path: root/t/cmop/get_code_info.t
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
commit5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch)
tree298c3d2f08bdfe5689998b11892d72a897985be1 /t/cmop/get_code_info.t
downloadMoose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz
Diffstat (limited to 't/cmop/get_code_info.t')
-rw-r--r--t/cmop/get_code_info.t52
1 files changed, 52 insertions, 0 deletions
diff --git a/t/cmop/get_code_info.t b/t/cmop/get_code_info.t
new file mode 100644
index 0000000..2770b76
--- /dev/null
+++ b/t/cmop/get_code_info.t
@@ -0,0 +1,52 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Sub::Name 'subname';
+
+BEGIN {
+ $^P &= ~0x200; # Don't munge anonymous sub names
+}
+
+use Class::MOP;
+
+
+sub code_name_is {
+ my ( $code, $stash, $name ) = @_;
+
+ is_deeply(
+ [ Class::MOP::get_code_info($code) ],
+ [ $stash, $name ],
+ "sub name is ${stash}::$name"
+ );
+}
+
+code_name_is( sub {}, main => "__ANON__" );
+
+code_name_is( subname("Foo::bar", sub {}), Foo => "bar" );
+
+code_name_is( subname("", sub {}), "main" => "" );
+
+require Class::MOP::Method;
+code_name_is( \&Class::MOP::Method::name, "Class::MOP::Method", "name" );
+
+{
+ package Foo;
+
+ sub MODIFY_CODE_ATTRIBUTES {
+ my ($class, $code) = @_;
+ my @info = Class::MOP::get_code_info($code);
+
+ if ( $] >= 5.011 ) {
+ ::is_deeply(\@info, ['Foo', 'foo'], "got a name for a code ref in an attr handler");
+ }
+ else {
+ ::is_deeply(\@info, [], "no name for a coderef that's still compiling");
+ }
+ return ();
+ }
+
+ sub foo : Bar {}
+}
+
+done_testing;