X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FUtil.pm;h=ff39422f74aa334df4cb293b4ef2d9b8a9e673c0;hp=2f1018137e2bfcd58db838efb2469fd489f86337;hb=3a63a2e7ef8fbac5f61eab04baecbf5d19374b83;hpb=e0396a57ff4663622ba6862a3039d05c2514fe4b diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 2f10181..ff39422 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -2,7 +2,8 @@ package Mouse::Util; use strict; use warnings; use base qw/Exporter/; -use Carp; +use Carp qw(confess); +use B (); our @EXPORT_OK = qw( get_linear_isa @@ -10,6 +11,7 @@ our @EXPORT_OK = qw( version authority identifier + get_code_info ); our %EXPORT_TAGS = ( all => \@EXPORT_OK, @@ -57,6 +59,21 @@ BEGIN { *{ __PACKAGE__ . '::get_linear_isa'} = $impl; } +{ # taken from Sub::Identify + sub get_code_info($) { + my ($coderef) = @_; + ref($coderef) or return; + my $cv = B::svref_2object($coderef); + $cv->isa('B::CV') or return; + + my $gv = $cv->GV; + # bail out if GV is undefined + $gv->isa('B::SPECIAL') and return; + + return ($gv->STASH->NAME, $gv->NAME); + } +} + { # adapted from Class::MOP::Module sub version { no strict 'refs'; ${shift->name.'::VERSION'} } @@ -184,7 +201,7 @@ sub apply_all_roles { } ( $_->[0]->can('meta') && $_->[0]->meta->isa('Mouse::Meta::Role') ) - || croak("You can only consume roles, " + || confess("You can only consume roles, " . $_->[0] . " is not a Moose role") foreach @roles;