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 BROKEN_GOTO => ($] < '5.008003') ? 1 : 0,
22 HAS_ITHREADS => $Config{useithreads} ? 1 : 0,
24 # ::Runmode would only be loaded by DBICTest, which in turn implies t/
25 DBICTEST => eval { DBICTest::RunMode->is_author } ? 1 : 0,
27 # During 5.13 dev cycle HELEMs started to leak on copy
28 # add an escape for these perls ON SMOKERS - a user will still get death
29 PEEPEENESS => ( eval { DBICTest::RunMode->is_smoker } && ($] >= 5.013005 and $] <= 5.013006) ),
31 SHUFFLE_UNORDERED_RESULTSETS => $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} ? 1 : 0,
33 ASSERT_NO_INTERNAL_WANTARRAY => $ENV{DBIC_ASSERT_NO_INTERNAL_WANTARRAY} ? 1 : 0,
35 ASSERT_NO_INTERNAL_INDIRECT_CALLS => $ENV{DBIC_ASSERT_NO_INTERNAL_INDIRECT_CALLS} ? 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);
60 # DO NOT edit away without talking to riba first, he will just put it back
61 # BEGIN pre-Moo2 import block
63 my $initial_fatal_bits = (${^WARNING_BITS}||'') & $warnings::DeadBits{all};
64 local $ENV{PERL_STRICTURES_EXTRA} = 0;
65 require Sub::Quote; Sub::Quote->import('quote_sub');
66 ${^WARNING_BITS} &= ( $initial_fatal_bits | ~ $warnings::DeadBits{all} );
68 sub qsub ($) { goto "e_sub } # no point depping on new Moo just for this
69 # END pre-Moo2 import block
73 sigwarn_silencer modver_gt_or_eq
74 fail_on_internal_wantarray fail_on_internal_call
75 refdesc refcount hrefaddr is_exception
76 quote_sub qsub perlstring
77 UNRESOLVABLE_CONDITION
80 use constant UNRESOLVABLE_CONDITION => \ '1 = 0';
82 sub sigwarn_silencer ($) {
85 croak "Expecting a regexp" if ref $pattern ne 'Regexp';
87 my $orig_sig_warn = $SIG{__WARN__} || sub { CORE::warn(@_) };
89 return sub { &$orig_sig_warn unless $_[0] =~ $pattern };
92 sub perlstring ($) { q{"}. quotemeta( shift ). q{"} };
94 sub hrefaddr ($) { sprintf '0x%x', &Scalar::Util::refaddr||0 }
97 croak "Expecting a reference" if ! length ref $_[0];
99 # be careful not to trigger stringification,
100 # reuse @_ as a scratch-pad
101 sprintf '%s%s(0x%x)',
102 ( defined( $_[1] = blessed $_[0]) ? "$_[1]=" : '' ),
104 Scalar::Util::refaddr($_[0]),
109 croak "Expecting a reference" if ! length ref $_[0];
112 # No tempvars - must operate on $_[0], otherwise the pad
113 # will count as an extra ref
114 B::svref_2object($_[0])->REFCNT;
117 sub is_exception ($) {
120 # this is not strictly correct - an eval setting $@ to undef
121 # is *not* the same as an eval setting $@ to ''
122 # but for the sake of simplicity assume the following for
124 return 0 unless defined $e;
126 my ($not_blank, $suberror);
130 $not_blank = ($e ne '') ? 1 : 0;
135 if (defined $suberror) {
136 if (length (my $class = blessed($e) )) {
137 carp_unique( sprintf(
138 'External exception class %s implements partial (broken) overloading '
139 . 'preventing its instances from being used in simple ($x eq $y) '
140 . 'comparisons. Given Perl\'s "globally cooperative" exception '
141 . 'handling this type of brokenness is extremely dangerous on '
142 . 'exception objects, as it may (and often does) result in silent '
143 . '"exception substitution". DBIx::Class tries to work around this '
144 . 'as much as possible, but other parts of your software stack may '
145 . 'not be even aware of this. Please submit a bugreport against the '
146 . 'distribution containing %s and in the meantime apply a fix similar '
147 . 'to the one shown at %s, in order to ensure your exception handling '
148 . 'is saner application-wide. What follows is the actual error text '
149 . "as generated by Perl itself:\n\n%s\n ",
152 'http://v.gd/DBIC_overload_tempfix/',
156 # workaround, keeps spice flowing
157 $not_blank = ("$e" ne '') ? 1 : 0;
160 # not blessed yet failed the 'ne'... this makes 0 sense...
169 sub modver_gt_or_eq ($$) {
170 my ($mod, $ver) = @_;
172 croak "Nonsensical module name supplied"
173 if ! defined $mod or ! length $mod;
175 croak "Nonsensical minimum version supplied"
176 if ! defined $ver or $ver =~ /[^0-9\.\_]/;
178 local $SIG{__WARN__} = sigwarn_silencer( qr/\Qisn't numeric in subroutine entry/ )
179 if SPURIOUS_VERSION_CHECK_WARNINGS;
181 croak "$mod does not seem to provide a version (perhaps it never loaded)"
182 unless $mod->VERSION;
185 eval { $mod->VERSION($ver) } ? 1 : 0;
189 my $list_ctx_ok_stack_marker;
191 sub fail_on_internal_wantarray () {
192 return if $list_ctx_ok_stack_marker;
194 if (! defined wantarray) {
195 croak('fail_on_internal_wantarray() needs a tempvar to save the stack marker guard');
199 while ( ( (caller($cf+1))[3] || '' ) =~ / :: (?:
201 # these are public API parts that alter behavior on wantarray
202 search | search_related | slice | search_literal
206 # these are explicitly prefixed, since we only recognize them as valid
207 # escapes when they come from the guts of CDBICompat
208 CDBICompat .*? :: (?: search_where | retrieve_from_sql | retrieve_all )
214 my ($fr, $want, $argdesc);
217 $fr = [ caller($cf) ];
218 $want = ( caller($cf-1) )[5];
219 $argdesc = ref $DB::args[0]
220 ? DBIx::Class::_Util::refdesc($DB::args[0])
226 $want and $fr->[0] =~ /^(?:DBIx::Class|DBICx::)/
228 DBIx::Class::Exception->throw( sprintf (
229 "Improper use of %s instance in list context at %s line %d\n\n Stacktrace starts",
230 $argdesc, @{$fr}[1,2]
231 ), 'with_stacktrace');
235 weaken ( $list_ctx_ok_stack_marker = $mark );
240 sub fail_on_internal_call {
245 $argdesc = ref $DB::args[0]
246 ? DBIx::Class::_Util::refdesc($DB::args[0])
254 $fr->[0] =~ /^(?:DBIx::Class|DBICx::)/
256 $fr->[1] !~ /\b(?:CDBICompat|ResultSetProxy)\b/ # no point touching there
258 DBIx::Class::Exception->throw( sprintf (
259 "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",
260 $fr->[3], $argdesc, @{$fr}[1,2], ( $fr->[6] || do {
263 B::Deparse->new->coderef2text(\&{$fr->[3]})
265 ), 'with_stacktrace');