From: Peter Rabbitson Date: Thu, 14 Jul 2016 12:50:02 +0000 (+0200) Subject: Add a get_subname to _Util X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=86a432d4cc096062e2374f118ce38aa131799d6a;p=dbsrgits%2FDBIx-Class.git Add a get_subname to _Util --- diff --git a/lib/DBIx/Class/Componentised.pm b/lib/DBIx/Class/Componentised.pm index 47797cc..3adea57 100644 --- a/lib/DBIx/Class/Componentised.pm +++ b/lib/DBIx/Class/Componentised.pm @@ -7,6 +7,7 @@ use warnings; use base 'Class::C3::Componentised'; use mro 'c3'; +use DBIx::Class::_Util 'get_subname'; use DBIx::Class::Carp '^DBIx::Class|^Class::C3::Componentised'; use namespace::clean; @@ -57,8 +58,7 @@ sub inject_base { or next; if ($sc ne $base_store_column) { - require B; - my $definer = B::svref_2object($sc)->STASH->NAME; + my ($definer) = get_subname($sc); push @broken, ($definer eq $existing_comp) ? $existing_comp : "$existing_comp (via $definer)" diff --git a/lib/DBIx/Class/_Util.pm b/lib/DBIx/Class/_Util.pm index 8bca635..a8785c0 100644 --- a/lib/DBIx/Class/_Util.pm +++ b/lib/DBIx/Class/_Util.pm @@ -184,7 +184,7 @@ use base 'Exporter'; our @EXPORT_OK = qw( sigwarn_silencer modver_gt_or_eq modver_gt_or_eq_and_lt fail_on_internal_wantarray fail_on_internal_call - refdesc refcount hrefaddr set_subname describe_class_methods + refdesc refcount hrefaddr set_subname get_subname describe_class_methods scope_guard detected_reinvoked_destructor emit_loud_diag true false is_exception dbic_internal_try visit_namespaces @@ -323,7 +323,14 @@ sub visit_namespaces { $visited_count; } -# FIXME In another life switch this to a polyfill like the one in namespace::clean +# FIXME In another life switch these to a polyfill like the ones in namespace::clean +sub get_subname ($) { + my $gv = B::svref_2object( $_[0] )->GV; + wantarray + ? ( $gv->STASH->NAME, $gv->NAME ) + : ( join '::', $gv->STASH->NAME, $gv->NAME ) + ; +} sub set_subname ($$) { # fully qualify name diff --git a/xt/extra/internals/namespaces_cleaned.t b/xt/extra/internals/namespaces_cleaned.t index e5d74ac..19768a8 100644 --- a/xt/extra/internals/namespaces_cleaned.t +++ b/xt/extra/internals/namespaces_cleaned.t @@ -63,7 +63,7 @@ use Test::More; use DBICTest; use File::Find; use File::Spec; -use B qw/svref_2object/; +use DBIx::Class::_Util 'get_subname'; # makes sure we can load at least something use DBIx::Class; @@ -134,15 +134,14 @@ for my $mod (@modules) { # overload is a funky thing - it is not cleaned, and its imports are named funny next if $name =~ /^\(/; - my $gv = svref_2object($all_method_like{$name})->GV; - my $origin = $gv->STASH->NAME; + my ($origin, $cv_name) = get_subname($all_method_like{$name}); - is ($gv->NAME, $name, "Properly named $name method at $origin" . ($origin eq $mod + is ($cv_name, $name, "Properly named $name method at $origin" . ($origin eq $mod ? '' : " (inherited by $mod)" )); - next if $seen->{"${origin}:${name}"}++; + next if $seen->{"${origin}::${name}"}++; if ($origin eq $mod) { pass ("$name is a native $mod method");