1 package # hide from PAUSE
4 use DBIx::Class::StartupCheck; # load es early as we can, usually a noop
9 # For the love of everything that is crab-like: DO NOT reach into this
10 # The entire thing is really fragile and should not be screwed with
11 # unless absolutely and unavoidably necessary
12 our $__describe_class_query_cache;
15 package # hide from pause
28 BROKEN_FORK => (OS_NAME eq 'MSWin32') ? 1 : 0,
30 BROKEN_GOTO => ( PERL_VERSION < 5.008003 ) ? 1 : 0,
32 # perl -MScalar::Util=weaken -e 'weaken( $hash{key} = \"value" )'
33 BROKEN_WEAK_SCALARREF_VALUES => ( PERL_VERSION < 5.008003 ) ? 1 : 0,
35 HAS_ITHREADS => $Config{useithreads} ? 1 : 0,
37 UNSTABLE_DOLLARAT => ( PERL_VERSION < 5.013002 ) ? 1 : 0,
41 # the "DBIC_" prefix below is crucial - this is what makes CI pick up
42 # all envvars without further adjusting its scripts
43 # DO NOT CHANGE to the more logical { $_ => !!( $ENV{"DBIC_$_"} ) }
45 { substr($_, 5) => !!( $ENV{$_} ) }
47 DBIC_SHUFFLE_UNORDERED_RESULTSETS
48 DBIC_ASSERT_NO_INTERNAL_WANTARRAY
49 DBIC_ASSERT_NO_INTERNAL_INDIRECT_CALLS
50 DBIC_STRESSTEST_UTF8_UPGRADE_GENERATED_COLLAPSER_SOURCE
51 DBIC_STRESSTEST_COLUMN_INFO_UNAWARE_STORAGE
55 IV_SIZE => $Config{ivsize},
58 if ( PERL_VERSION < 5.009_005) {
60 constant->import( OLD_MRO => 1 );
63 # Yes, I know this is a rather PHP-ish name, but please first read
64 # https://metacpan.org/source/BOBTFISH/MRO-Compat-0.12/lib/MRO/Compat.pm#L363-368
66 # Even if we are using Class::C3::XS it still won't work, as doing
67 # defined( *{ "SubClass::"->{$_} }{CODE} )
68 # will set pkg_gen to the same value for SubClass and *ALL PARENTS*
70 *DBIx::Class::_Util::get_real_pkg_gen = sub ($) {
77 # the non-assign-unless-there-is-a-hash is deliberate
78 ( $__describe_class_query_cache->{'!internal!'} || {} )->{$_[0]}{gen} ||= (
79 Math::BigInt->new( '0x' . ( Digest::MD5::md5_hex( join "\0", map {
81 ( $__describe_class_query_cache->{'!internal!'} || {} )->{$_}{methlist} ||= (
87 # RV to be hashed up and turned into a number
92 # stringification should be sufficient, ignore names/refaddr entirely
97 local $SIG{__DIE__} if $SIG{__DIE__};
98 # attributes::get may throw on blessed-false crefs :/
99 eval { @attrs = attributes::get( $_ ); 1 }
100 or warn "Unable to determine attributes of coderef $_ due to the following error: $@";
106 # skip dummy C::C3 helper crefs
107 ! ( ( $Class::C3::MRO{$cur_class} || {} )->{methods}{$_} )
110 ref(\ "${cur_class}::"->{$_} ) ne 'GLOB'
112 defined( *{ "${cur_class}::"->{$_} }{CODE} )
115 ? ( \&{"${cur_class}::$_"} )
118 keys %{ "${cur_class}::" }
124 ( $__describe_class_query_cache->{'!internal!'} || {} )->{$_[0]}{linear_isa}
126 mro::get_linear_isa($_[0])
130 ( $__describe_class_query_cache->{'!internal!'} || {} )->{$_[0]}{is_universal}
132 mro::is_universal($_[0])
134 ( $__describe_class_query_cache->{'!internal!'} || {} )->{UNIVERSAL}{linear_isa}
136 mro::get_linear_isa("UNIVERSAL")
145 constant->import( OLD_MRO => 0 );
146 *DBIx::Class::_Util::get_real_pkg_gen = \&mro::get_pkg_gen;
149 # Both of these are no longer used for anything. However bring
150 # them back after they were purged in 08a8d8f1, as there appear
151 # to be outfits with *COPY PASTED* pieces of lib/DBIx/Class/Storage/*
152 # in their production codebases. There is no point in breaking these
153 # if whatever they used actually continues to work
155 DBIx::Class::_Util::emit_loud_diag(
157 msg => "The @{[ (caller(1))[3] ]} constant is no more - adjust your code"
162 sub DBICTEST () { &$sigh }
163 sub PEEPEENESS () { &$sigh }
166 use constant SPURIOUS_VERSION_CHECK_WARNINGS => ( DBIx::Class::_ENV_::PERL_VERSION < 5.010 ? 1 : 0);
168 # FIXME - this is not supposed to be here
169 # Carp::Skip to the rescue soon
170 use DBIx::Class::Carp '^DBIx::Class|^DBICTest';
174 use Storable 'nfreeze';
175 use Scalar::Util qw(weaken blessed reftype refaddr);
176 use Sub::Quote qw(qsub);
180 # Already correctly prototyped: perlbrew exec perl -MStorable -e 'warn prototype \&Storable::dclone'
181 BEGIN { *deep_clone = \&Storable::dclone }
185 sigwarn_silencer modver_gt_or_eq modver_gt_or_eq_and_lt
186 fail_on_internal_wantarray fail_on_internal_call
187 refdesc refcount hrefaddr set_subname get_subname describe_class_methods
188 scope_guard detected_reinvoked_destructor emit_loud_diag
190 is_exception dbic_internal_try visit_namespaces
191 quote_sub qsub perlstring serialize deep_clone dump_value uniq
193 UNRESOLVABLE_CONDITION
196 use constant UNRESOLVABLE_CONDITION => \ '1 = 0';
198 # Override forcing no_defer, and adding naming consistency checks
199 our %refs_closed_over_by_quote_sub_installed_crefs;
201 Carp::confess( "Anonymous quoting not supported by the DBIC quote_sub override - supply a sub name" ) if
209 Carp::confess( "The DBIC quote_sub override expects sub name '$_[0]' to be fully qualified" )
210 unless (my $stash) = $_[0] =~ /^(.+)::/;
213 "The DBIC sub_quote override does not support 'no_install'"
221 'The DBIC quote_sub override expects the namespace-part of sub name '
222 . "'$_[0]' to match the supplied package argument '$_[3]->{package}'"
226 defined $_[3]->{package}
228 $stash ne $_[3]->{package}
231 my @caller = caller(0);
233 package => $caller[0],
235 warning_bits => $caller[9],
236 hintshash => $caller[10],
239 # explicitly forced for everything
244 # just use a growing counter, no need to perform neither compaction
245 # nor any special ithread-level handling
246 $refs_closed_over_by_quote_sub_installed_crefs
247 { scalar keys %refs_closed_over_by_quote_sub_installed_crefs }
253 ! DBIx::Class::_ENV_::BROKEN_WEAK_SCALARREF_VALUES
257 } values %{ $_[2] || {} };
259 Sub::Quote::quote_sub( $_[0], $_[1], $_[2]||{}, $sq_opts );
262 sub sigwarn_silencer ($) {
265 croak "Expecting a regexp" if ref $pattern ne 'Regexp';
267 my $orig_sig_warn = $SIG{__WARN__} || sub { CORE::warn(@_) };
269 return sub { &$orig_sig_warn unless $_[0] =~ $pattern };
272 sub perlstring ($) { q{"}. quotemeta( shift ). q{"} };
274 sub hrefaddr ($) { sprintf '0x%x', &refaddr||0 }
277 croak "Expecting a reference" if ! length ref $_[0];
279 # be careful not to trigger stringification,
280 # reuse @_ as a scratch-pad
281 sprintf '%s%s(0x%x)',
282 ( defined( $_[1] = blessed $_[0]) ? "$_[1]=" : '' ),
289 croak "Expecting a reference" if ! length ref $_[0];
291 # No tempvars - must operate on $_[0], otherwise the pad
292 # will count as an extra ref
293 B::svref_2object($_[0])->REFCNT;
296 sub visit_namespaces {
297 my $args = { (ref $_[0]) ? %{$_[0]} : @_ };
299 my $visited_count = 1;
301 # A package and a namespace are subtly different things
302 $args->{package} ||= 'main';
303 $args->{package} = 'main' if $args->{package} =~ /^ :: (?: main )? $/x;
304 $args->{package} =~ s/^:://;
306 if ( $args->{action}->($args->{package}) ) {
308 ( ($args->{package} eq 'main') ? '' : $args->{package} )
313 $visited_count += visit_namespaces( %$args, package => $_ ) for
315 # this happens sometimes on %:: traversal
318 { $_ =~ /^(.+?)::$/ ? "$ns$1" : () }
319 do { no strict 'refs'; keys %$ns }
326 # FIXME In another life switch these to a polyfill like the ones in namespace::clean
327 sub get_subname ($) {
328 my $gv = B::svref_2object( $_[0] )->GV;
330 ? ( $gv->STASH->NAME, $gv->NAME )
331 : ( join '::', $gv->STASH->NAME, $gv->NAME )
334 sub set_subname ($$) {
337 splice @_, 0, 1, caller(0) . "::$_[0]"
344 local $Storable::canonical = 1;
349 my( %seen, $seen_undef, $numeric_preserving_copy );
352 ? $seen{ $numeric_preserving_copy = $_ }++
359 local $Data::Dumper::Indent = 1
360 unless defined $Data::Dumper::Indent;
366 require Data::Dumper;
367 my $d = Data::Dumper->new([])
380 $d->Sparseseen(1) if modver_gt_or_eq (
381 'Data::Dumper', '2.136'
386 )->Values([$_[0]])->Dump;
388 $dd_obj->Reset->Values([]);
393 my $seen_loud_screams;
395 my $args = { ref $_[0] eq 'HASH' ? %{$_[0]} : @_ };
397 unless ( defined $args->{msg} and length $args->{msg} ) {
399 msg => "No 'msg' value supplied to emit_loud_diag()"
404 my $msg = "\n$0: $args->{msg}";
406 # when we die - we usually want to keep doing it
407 $args->{emit_dups} = !!$args->{confess}
408 unless exists $args->{emit_dups};
410 local $Carp::CarpLevel =
411 ( $args->{skip_frames} || 0 )
419 my $longmess = Carp::longmess();
421 # different object references will thwart deduplication without this
422 ( my $key = "${msg}\n${longmess}" ) =~ s/\b0x[0-9a-f]+\b/0x.../gi;
424 return $seen_loud_screams->{$key} if
425 $seen_loud_screams->{$key}++
431 unless $msg =~ /\n\z/;
433 print STDERR "$msg\n"
435 print STDOUT "\n!!!STDERR ISN'T WRITABLE!!!:$msg\n";
437 return $seen_loud_screams->{$key}
438 unless $args->{confess};
440 # increment *again*, because... Carp.
443 # not $msg - Carp will reapply the longmess on its own
444 Carp::confess($args->{msg});
449 ### This is *NOT* boolean.pm - deliberately not using a singleton
452 package # hide from pause
453 DBIx::Class::_Util::_Bool;
455 bool => sub { ${$_[0]} },
459 sub true () { my $x = 1; bless \$x, "DBIx::Class::_Util::_Bool" }
460 sub false () { my $x = 0; bless \$x, "DBIx::Class::_Util::_Bool" }
462 sub scope_guard (&) {
463 croak 'Calling scope_guard() in void context makes no sense'
464 if ! defined wantarray;
466 # no direct blessing of coderefs - DESTROY is buggy on those
467 bless [ $_[0] ], 'DBIx::Class::_Util::ScopeGuard';
471 DBIx::Class::_Util::ScopeGuard;
474 &DBIx::Class::_Util::detected_reinvoked_destructor;
476 local $@ if DBIx::Class::_ENV_::UNSTABLE_DOLLARAT;
483 DBIx::Class::_Util::emit_loud_diag(
485 msg => "Execution of scope guard $_[0] resulted in the non-trappable exception:\n\n$@\n "
491 sub is_exception ($) {
495 # this is not strictly correct - an eval setting $@ to undef
496 # is *not* the same as an eval setting $@ to ''
497 # but for the sake of simplicity assume the following for
499 return 0 unless defined $e;
501 my ($not_blank, $suberror);
503 local $SIG{__DIE__} if $SIG{__DIE__};
506 # The ne() here is deliberate - a plain length($e), or worse "$e" ne
507 # will entirely obviate the need for the encolsing eval{}, as the
508 # condition we guard against is a missing fallback overload
509 $not_blank = ( $e ne '' );
514 if (defined $suberror) {
515 if (length (my $class = blessed($e) )) {
516 carp_unique( sprintf(
517 'External exception class %s implements partial (broken) overloading '
518 . 'preventing its instances from being used in simple ($x eq $y) '
519 . 'comparisons. Given Perl\'s "globally cooperative" exception '
520 . 'handling this type of brokenness is extremely dangerous on '
521 . 'exception objects, as it may (and often does) result in silent '
522 . '"exception substitution". DBIx::Class tries to work around this '
523 . 'as much as possible, but other parts of your software stack may '
524 . 'not be even aware of this. Please submit a bugreport against the '
525 . 'distribution containing %s and in the meantime apply a fix similar '
526 . 'to the one shown at %s, in order to ensure your exception handling '
527 . 'is saner application-wide. What follows is the actual error text '
528 . "as generated by Perl itself:\n\n%s\n ",
531 'http://v.gd/DBIC_overload_tempfix/',
535 # workaround, keeps spice flowing
536 $not_blank = !!( length $e );
539 # not blessed yet failed the 'ne'... this makes 0 sense...
545 # a ref evaluating to '' is definitively a "null object"
548 length( my $class = ref $e )
551 "Objects of external exception class '$class' stringify to '' (the "
552 . 'empty string), implementing the so called null-object-pattern. '
553 . 'Given Perl\'s "globally cooperative" exception handling using this '
554 . 'class of exceptions is extremely dangerous, as it may (and often '
555 . 'does) result in silent discarding of errors. DBIx::Class tries to '
556 . 'work around this as much as possible, but other parts of your '
557 . 'software stack may not be even aware of the problem. Please submit '
558 . "a bugreport against the distribution containing '$class'",
570 # Recreate the logic of try(), while reusing the catch()/finally() as-is
572 # FIXME: We need to move away from Try::Tiny entirely (way too heavy and
573 # yes, shows up ON TOP of profiles) but this is a batle for another maint
574 sub dbic_internal_try (&;@) {
576 my $try_cref = shift;
577 my $catch_cref = undef; # apparently this is a thing... https://rt.perl.org/Public/Bug/Display.html?id=119311
581 if( ref($arg) eq 'Try::Tiny::Catch' ) {
583 croak 'dbic_internal_try() may not be followed by multiple catch() blocks'
588 elsif ( ref($arg) eq 'Try::Tiny::Finally' ) {
589 croak 'dbic_internal_try() does not support finally{}';
593 'dbic_internal_try() encountered an unexpected argument '
594 . "'@{[ defined $arg ? $arg : 'UNDEF' ]}' - perhaps "
595 . 'a missing semi-colon before or ' # trailing space important
600 my $wantarray = wantarray;
601 my $preexisting_exception = $@;
604 my $all_good = eval {
605 $@ = $preexisting_exception;
607 local $callstack_state->{in_internal_try} = 1
608 unless $callstack_state->{in_internal_try};
610 # always unset - someone may have snuck it in
611 local $SIG{__DIE__} if $SIG{__DIE__};
614 @ret = $try_cref->();
616 elsif( defined $wantarray ) {
617 $ret[0] = $try_cref->();
627 $@ = $preexisting_exception;
630 return $wantarray ? @ret : $ret[0]
632 elsif ( $catch_cref ) {
634 return $catch_cref->($exception);
641 sub in_internal_try { !! $callstack_state->{in_internal_try} }
645 my $destruction_registry = {};
647 sub DBIx::Class::__Util_iThreads_handler__::CLONE {
648 %$destruction_registry = map {
650 ? ( refaddr($_) => $_ )
652 } values %$destruction_registry;
654 weaken($_) for values %$destruction_registry;
656 # Dummy NEXTSTATE ensuring the all temporaries on the stack are garbage
657 # collected before leaving this scope. Depending on the code above, this
658 # may very well be just a preventive measure guarding future modifications
662 # This is almost invariably invoked from within DESTROY
663 # throwing exceptions won't work
664 sub detected_reinvoked_destructor {
666 # quick "garbage collection" pass - prevents the registry
667 # from slowly growing with a bunch of undef-valued keys
668 defined $destruction_registry->{$_} or delete $destruction_registry->{$_}
669 for keys %$destruction_registry;
671 if (! length ref $_[0]) {
674 msg => (caller(0))[3] . '() expects a blessed reference'
676 return undef; # don't know wtf to do
678 elsif (! defined $destruction_registry->{ my $addr = refaddr($_[0]) } ) {
679 weaken( $destruction_registry->{$addr} = $_[0] );
683 emit_loud_diag( msg => sprintf (
684 'Preventing *MULTIPLE* DESTROY() invocations on %s - an *EXTREMELY '
685 . 'DANGEROUS* condition which is *ALMOST CERTAINLY GLOBAL* within your '
686 . 'application, affecting *ALL* classes without active protection against '
687 . 'this. Diagnose and fix the root cause ASAP!!!%s',
689 ( ( $INC{'Devel/StackTrace.pm'} and ! do { local $@; eval { Devel::StackTrace->VERSION(2) } } )
690 ? " (likely culprit Devel::StackTrace\@@{[ Devel::StackTrace->VERSION ]} found in %INC, http://is.gd/D_ST_refcap)"
700 my $module_name_rx = qr/ \A [A-Z_a-z] [0-9A-Z_a-z]* (?: :: [0-9A-Z_a-z]+ )* \z /x;
701 my $ver_rx = qr/ \A [0-9]+ (?: \. [0-9]+ )* (?: \_ [0-9]+ )* \z /x;
703 sub modver_gt_or_eq ($$) {
704 my ($mod, $ver) = @_;
706 croak "Nonsensical module name supplied"
707 if ! defined $mod or $mod !~ $module_name_rx;
709 croak "Nonsensical minimum version supplied"
710 if ! defined $ver or $ver !~ $ver_rx;
713 my $ver_cache = ${"${mod}::__DBIC_MODULE_VERSION_CHECKS__"} ||= ( $mod->VERSION
715 : croak "$mod does not seem to provide a version (perhaps it never loaded)"
718 ! defined $ver_cache->{$ver}
720 $ver_cache->{$ver} = do {
722 local $SIG{__WARN__} = sigwarn_silencer( qr/\Qisn't numeric in subroutine entry/ )
723 if SPURIOUS_VERSION_CHECK_WARNINGS;
725 local $SIG{__DIE__} if $SIG{__DIE__};
727 eval { $mod->VERSION($ver) } ? 1 : 0;
733 sub modver_gt_or_eq_and_lt ($$$) {
734 my ($mod, $v_ge, $v_lt) = @_;
736 croak "Nonsensical maximum version supplied"
737 if ! defined $v_lt or $v_lt !~ $ver_rx;
740 modver_gt_or_eq($mod, $v_ge)
742 ! modver_gt_or_eq($mod, $v_lt)
748 sub describe_class_methods {
750 ref $_[0] eq 'HASH' ? $_[0]
751 : ( @_ == 1 and ! length ref $_[0] ) ? { class => $_[0] }
755 my ($class, $requested_mro) = @{$args}{qw( class use_mro )};
757 croak "Expecting a class name either as the sole argument or a 'class' option"
758 if not defined $class or $class !~ $module_name_rx;
760 $requested_mro ||= mro::get_mro($class);
762 # mro::set_mro() does not bump pkg_gen - WHAT THE FUCK?!
763 my $query_cache_key = "$class|$requested_mro";
765 my $internal_cache_key =
766 ( mro::get_mro($class) eq $requested_mro )
771 # use a cache on old MRO, since while we are recursing in this function
772 # nothing can possibly change (the speedup is immense)
773 # (yes, people could be tie()ing the stash and adding methods on access
774 # but there is a limit to how much crazy can be supported here)
776 # we use the cache for linear_isa lookups on new MRO as well - it adds
777 # a *tiny* speedup, and simplifies the code a lot
779 local $__describe_class_query_cache->{'!internal!'} = {}
780 unless $__describe_class_query_cache->{'!internal!'};
784 $my_gen += get_real_pkg_gen($_) for ( my @full_ISA = (
787 $__describe_class_query_cache->{'!internal!'}{$internal_cache_key}{linear_isa}
789 mro::get_linear_isa($class, $requested_mro)
793 $__describe_class_query_cache->{'!internal!'}{$class}{is_universal}
795 mro::is_universal($class)
797 $__describe_class_query_cache->{'!internal!'}{UNIVERSAL}{linear_isa}
799 mro::get_linear_isa("UNIVERSAL")
804 my $slot = $__describe_class_query_cache->{$query_cache_key} ||= {};
806 unless ( ($slot->{cumulative_gen}||0) == $my_gen ) {
811 isa => { map { $_ => 1 } @full_ISA },
813 @{ $__describe_class_query_cache->{'!internal!'}{$internal_cache_key}{linear_isa} }
814 [ 1 .. $#{$__describe_class_query_cache->{'!internal!'}{$internal_cache_key}{linear_isa}} ]
817 type => $requested_mro,
818 is_c3 => ( ($requested_mro eq 'c3') ? 1 : 0 ),
820 cumulative_gen => $my_gen,
823 # remove ourselves from ISA
826 # ensure the cache is populated for the parents, code below can then
827 # efficiently operate over the query_cache directly
828 describe_class_methods($_) for reverse @full_ISA;
832 # combine full ISA-order inherited and local method list into a
836 unshift @{ $slot->{methods}{$_->{name}} }, $_
841 $_->{via_class} ne $class
843 $slot->{methods_defined_in_class}{$_->{name}} = $_
848 @{ $slot->{methods}{$_->{name}} } > 1
852 $slot->{methods_with_supers}{$_->{name}} = $slot->{methods}{$_->{name}}
856 # what describe_class_methods for @full_ISA produced above
858 $__describe_class_query_cache->{$_}{methods_defined_in_class} || {}
859 } } map { "$_|" . mro::get_mro($_) } reverse @full_ISA ),
861 # our own non-cleaned subs + their attributes
864 # need to account for dummy helper crefs under OLD_MRO
866 ! DBIx::Class::_ENV_::OLD_MRO
868 ! ( ( $Class::C3::MRO{$class} || {} )->{methods}{$_} )
871 # these 2 OR-ed checks are sufficient for 5.10+
873 ref(\ "${class}::"->{$_} ) ne 'GLOB'
875 defined( *{ "${class}::"->{$_} }{CODE} )
880 attributes => { map { $_ => 1 } do {
883 local $SIG{__DIE__} if $SIG{__DIE__};
884 # attributes::get may throw on blessed-false crefs :/
885 eval { @attrs = attributes::get( \&{"${class}::${_}"} ); 1 }
886 or warn "Unable to determine attributes of the \\&${class}::$_ method due to following error: $@";
891 } keys %{"${class}::"} )
895 # recalculate the pkg_gen on newer perls under Taint mode,
896 # because of shit like:
897 # perl -T -Mmro -e 'package Foo; sub bar {}; defined( *{ "Foo::"->{bar}}{CODE} ) and warn mro::get_pkg_gen("Foo") for (1,2,3)'
900 ! DBIx::Class::_ENV_::OLD_MRO
905 $slot->{cumulative_gen} = 0;
906 $slot->{cumulative_gen} += get_real_pkg_gen($_)
907 for $class, @full_ISA;
918 # Why not just use some higher-level module or at least File::Spec here?
920 # 1) This is a *very* rarely used function, and the deptree is large
921 # enough already as it is
923 # 2) (more importantly) Our tooling is utter shit in this area. There
924 # is no comprehensive support for UNC paths in PathTools and there
925 # are also various small bugs in representation across different
926 # path-manipulation CPAN offerings.
928 # Since this routine is strictly used for logical path processing (it
929 # *must* be able to work with not-yet-existing paths), use this seemingly
930 # simple but I *think* complete implementation to feed to other consumers
932 # If bugs are ever uncovered in this routine, *YOU ARE URGED TO RESIST*
933 # the impulse to bring in an external dependency. During runtime there
934 # is exactly one spot that could potentially maybe once in a blue moon
935 # use this function. Keep it lean.
938 ( $_[0] =~ m{ [\/\\] ( \.{0,2} ) ( [\/\\]* ) \z }x )
942 ( ( length($1) and ! length($2) ) ? '/' : '' )
949 File::Spec->catpath (
950 ( File::Spec->splitpath( "$_[0]" ) )[0,1],
959 # do not ask for a recent version, use 1.x API calls
960 File::Path::mkpath([ "$_[0]" ]); # File::Path does not like objects
965 my $list_ctx_ok_stack_marker;
967 sub fail_on_internal_wantarray () {
968 return if $list_ctx_ok_stack_marker;
970 if (! defined wantarray) {
971 croak('fail_on_internal_wantarray() needs a tempvar to save the stack marker guard');
975 while ( ( (CORE::caller($cf+1))[3] || '' ) =~ / :: (?:
977 # these are public API parts that alter behavior on wantarray
978 search | search_related | slice | search_literal
982 # these are explicitly prefixed, since we only recognize them as valid
983 # escapes when they come from the guts of CDBICompat
984 CDBICompat .*? :: (?: search_where | retrieve_from_sql | retrieve_all )
990 my ($fr, $want, $argdesc);
993 $fr = [ CORE::caller($cf) ];
994 $want = ( CORE::caller($cf-1) )[5];
995 $argdesc = ref $DB::args[0]
996 ? DBIx::Class::_Util::refdesc($DB::args[0])
1002 $want and $fr->[0] =~ /^(?:DBIx::Class|DBICx::)/
1004 DBIx::Class::Exception->throw( sprintf (
1005 "Improper use of %s instance in list context at %s line %d\n\n Stacktrace starts",
1006 $argdesc, @{$fr}[1,2]
1007 ), 'with_stacktrace');
1010 weaken( $list_ctx_ok_stack_marker = my $mark = [] );
1016 sub fail_on_internal_call {
1020 $fr = [ CORE::caller(1) ];
1021 $argdesc = ref $DB::args[0]
1022 ? DBIx::Class::_Util::refdesc($DB::args[0])
1023 : ( $DB::args[0] . '' )
1028 # need to make allowance for a proxy-yet-direct call
1030 $fr->[0] eq 'DBIx::Class::ResultSourceProxy'
1032 @fr2 = (CORE::caller(2))
1035 ( $fr->[3] =~ /([^:])+$/ )[0]
1037 ( $fr2[3] =~ /([^:])+$/ )[0]
1047 $check_fr->[0] =~ /^(?:DBIx::Class|DBICx::)/
1049 $check_fr->[1] !~ /\b(?:CDBICompat|ResultSetProxy)\b/ # no point touching there
1051 DBIx::Class::Exception->throw( sprintf (
1052 "Illegal internal call of indirect proxy-method %s() with argument '%s': examine the last lines of the proxy method deparse below to determine what to call directly instead at %s on line %d\n\n%s\n\n Stacktrace starts",
1053 $fr->[3], $argdesc, @{$fr}[1,2], ( $fr->[6] || do {
1056 B::Deparse->new->coderef2text(\&{$fr->[3]})
1058 ), 'with_stacktrace');