1 package # hide from PAUSE
7 use constant SPURIOUS_VERSION_CHECK_WARNINGS => ($] < 5.010 ? 1 : 0);
10 package # hide from pause
18 BROKEN_FORK => ($^O eq 'MSWin32') ? 1 : 0,
20 HAS_ITHREADS => $Config{useithreads} ? 1 : 0,
22 # ::Runmode would only be loaded by DBICTest, which in turn implies t/
23 DBICTEST => eval { DBICTest::RunMode->is_author } ? 1 : 0,
25 # During 5.13 dev cycle HELEMs started to leak on copy
27 # request for all tests would force "non-leaky" illusion and vice-versa
28 defined $ENV{DBICTEST_ALL_LEAKS} ? !$ENV{DBICTEST_ALL_LEAKS}
29 # otherwise confess that this perl is busted ONLY on smokers
30 : eval { DBICTest::RunMode->is_smoker } && ($] >= 5.013005 and $] <= 5.013006) ? 1
31 # otherwise we are good
35 ASSERT_NO_INTERNAL_WANTARRAY => $ENV{DBIC_ASSERT_NO_INTERNAL_WANTARRAY} ? 1 : 0,
37 IV_SIZE => $Config{ivsize},
44 constant->import( OLD_MRO => 1 );
48 constant->import( OLD_MRO => 0 );
52 # FIXME - this is not supposed to be here
53 # Carp::Skip to the rescue soon
54 use DBIx::Class::Carp '^DBIx::Class|^DBICTest';
57 use Scalar::Util qw(weaken blessed reftype);
58 use List::Util qw(first);
63 sigwarn_silencer modver_gt_or_eq fail_on_internal_wantarray
64 refcount hrefaddr is_exception
65 is_plain_value is_literal_value
68 sub sigwarn_silencer ($) {
71 croak "Expecting a regexp" if ref $pattern ne 'Regexp';
73 my $orig_sig_warn = $SIG{__WARN__} || sub { CORE::warn(@_) };
75 return sub { &$orig_sig_warn unless $_[0] =~ $pattern };
78 sub hrefaddr ($) { sprintf '0x%x', &Scalar::Util::refaddr }
81 croak "Expecting a reference" if ! length ref $_[0];
84 # No tempvars - must operate on $_[0], otherwise the pad
85 # will count as an extra ref
86 B::svref_2object($_[0])->REFCNT;
89 sub is_exception ($) {
92 # this is not strictly correct - an eval setting $@ to undef
93 # is *not* the same as an eval setting $@ to ''
94 # but for the sake of simplicity assume the following for
96 return 0 unless defined $e;
98 my ($not_blank, $suberror);
102 $not_blank = ($e ne '') ? 1 : 0;
107 if (defined $suberror) {
108 if (length (my $class = blessed($e) )) {
109 carp_unique( sprintf(
110 'External exception object %s=%s(%s) implements partial (broken) '
111 . 'overloading preventing it from being used in simple ($x eq $y) '
112 . 'comparisons. Given Perl\'s "globally cooperative" exception '
113 . 'handling this type of brokenness is extremely dangerous on '
114 . 'exception objects, as it may (and often does) result in silent '
115 . '"exception substitution". DBIx::Class tries to work around this '
116 . 'as much as possible, but other parts of your software stack may '
117 . 'not be even aware of this. Please submit a bugreport against the '
118 . 'distribution containing %s and in the meantime apply a fix similar '
119 . 'to the one shown at %s, in order to ensure your exception handling '
120 . 'is saner application-wide. What follows is the actual error text '
121 . "as generated by Perl itself:\n\n%s\n ",
126 'http://v.gd/DBIC_overload_tempfix/',
130 # workaround, keeps spice flowing
131 $not_blank = ("$e" ne '') ? 1 : 0;
134 # not blessed yet failed the 'ne'... this makes 0 sense...
143 sub modver_gt_or_eq ($$) {
144 my ($mod, $ver) = @_;
146 croak "Nonsensical module name supplied"
147 if ! defined $mod or ! length $mod;
149 croak "Nonsensical minimum version supplied"
150 if ! defined $ver or $ver =~ /[^0-9\.\_]/;
152 local $SIG{__WARN__} = sigwarn_silencer( qr/\Qisn't numeric in subroutine entry/ )
153 if SPURIOUS_VERSION_CHECK_WARNINGS;
155 croak "$mod does not seem to provide a version (perhaps it never loaded)"
156 unless $mod->VERSION;
159 eval { $mod->VERSION($ver) } ? 1 : 0;
162 sub is_literal_value ($) {
164 ref $_[0] eq 'SCALAR'
166 ( ref $_[0] eq 'REF' and ref ${$_[0]} eq 'ARRAY' )
170 # FIXME XSify - this can be done so much more efficiently
171 sub is_plain_value ($) {
180 # deliberately not using Devel::OverloadInfo - the checks we are
181 # intersted in are much more limited than the fullblown thing, and
182 # this is a relatively hot piece of code
184 # either has stringification which DBI prefers out of the box
185 #first { *{$_ . '::(""'}{CODE} } @{ mro::get_linear_isa( ref $_[0] ) }
186 overload::Method($_[0], '""')
188 # has nummification and fallback is *not* disabled
190 $_[1] = first { *{"${_}::(0+"}{CODE} } @{ mro::get_linear_isa( ref $_[0] ) }
192 ( ! defined ${"$_[1]::()"} or ${"$_[1]::()"} )
200 my $list_ctx_ok_stack_marker;
202 sub fail_on_internal_wantarray {
203 return if $list_ctx_ok_stack_marker;
205 if (! defined wantarray) {
206 croak('fail_on_internal_wantarray() needs a tempvar to save the stack marker guard');
210 while ( ( (caller($cf+1))[3] || '' ) =~ / :: (?:
212 # these are public API parts that alter behavior on wantarray
213 search | search_related | slice | search_literal
217 # these are explicitly prefixed, since we only recognize them as valid
218 # escapes when they come from the guts of CDBICompat
219 CDBICompat .*? :: (?: search_where | retrieve_from_sql | retrieve_all )
226 (caller($cf))[0] =~ /^(?:DBIx::Class|DBICx::)/
230 DBIx::Class::Exception->throw( sprintf (
231 "Improper use of %s(%s) instance in list context at %s line %d\n\n\tStacktrace starts",
232 ref($obj), hrefaddr($obj), (caller($cf))[1,2]
233 ), 'with_stacktrace');
237 weaken ( $list_ctx_ok_stack_marker = $mark );