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
26 # add an escape for these perls ON SMOKERS - a user will still get death
27 PEEPEENESS => ( eval { DBICTest::RunMode->is_smoker } && ($] >= 5.013005 and $] <= 5.013006) ),
29 SHUFFLE_UNORDERED_RESULTSETS => $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} ? 1 : 0,
31 ASSERT_NO_INTERNAL_WANTARRAY => $ENV{DBIC_ASSERT_NO_INTERNAL_WANTARRAY} ? 1 : 0,
33 IV_SIZE => $Config{ivsize},
40 constant->import( OLD_MRO => 1 );
44 constant->import( OLD_MRO => 0 );
48 # FIXME - this is not supposed to be here
49 # Carp::Skip to the rescue soon
50 use DBIx::Class::Carp '^DBIx::Class|^DBICTest';
53 use Scalar::Util qw(weaken blessed reftype);
54 use List::Util qw(first);
59 sigwarn_silencer modver_gt_or_eq fail_on_internal_wantarray
60 refcount hrefaddr is_exception
61 is_plain_value is_literal_value
64 sub sigwarn_silencer ($) {
67 croak "Expecting a regexp" if ref $pattern ne 'Regexp';
69 my $orig_sig_warn = $SIG{__WARN__} || sub { CORE::warn(@_) };
71 return sub { &$orig_sig_warn unless $_[0] =~ $pattern };
74 sub hrefaddr ($) { sprintf '0x%x', &Scalar::Util::refaddr }
77 croak "Expecting a reference" if ! length ref $_[0];
80 # No tempvars - must operate on $_[0], otherwise the pad
81 # will count as an extra ref
82 B::svref_2object($_[0])->REFCNT;
85 sub is_exception ($) {
88 # this is not strictly correct - an eval setting $@ to undef
89 # is *not* the same as an eval setting $@ to ''
90 # but for the sake of simplicity assume the following for
92 return 0 unless defined $e;
94 my ($not_blank, $suberror);
98 $not_blank = ($e ne '') ? 1 : 0;
103 if (defined $suberror) {
104 if (length (my $class = blessed($e) )) {
105 carp_unique( sprintf(
106 'External exception object %s=%s(%s) implements partial (broken) '
107 . 'overloading preventing it from being used in simple ($x eq $y) '
108 . 'comparisons. Given Perl\'s "globally cooperative" exception '
109 . 'handling this type of brokenness is extremely dangerous on '
110 . 'exception objects, as it may (and often does) result in silent '
111 . '"exception substitution". DBIx::Class tries to work around this '
112 . 'as much as possible, but other parts of your software stack may '
113 . 'not be even aware of this. Please submit a bugreport against the '
114 . 'distribution containing %s and in the meantime apply a fix similar '
115 . 'to the one shown at %s, in order to ensure your exception handling '
116 . 'is saner application-wide. What follows is the actual error text '
117 . "as generated by Perl itself:\n\n%s\n ",
122 'http://v.gd/DBIC_overload_tempfix/',
126 # workaround, keeps spice flowing
127 $not_blank = ("$e" ne '') ? 1 : 0;
130 # not blessed yet failed the 'ne'... this makes 0 sense...
139 sub modver_gt_or_eq ($$) {
140 my ($mod, $ver) = @_;
142 croak "Nonsensical module name supplied"
143 if ! defined $mod or ! length $mod;
145 croak "Nonsensical minimum version supplied"
146 if ! defined $ver or $ver =~ /[^0-9\.\_]/;
148 local $SIG{__WARN__} = sigwarn_silencer( qr/\Qisn't numeric in subroutine entry/ )
149 if SPURIOUS_VERSION_CHECK_WARNINGS;
151 croak "$mod does not seem to provide a version (perhaps it never loaded)"
152 unless $mod->VERSION;
155 eval { $mod->VERSION($ver) } ? 1 : 0;
158 sub is_literal_value ($) {
160 ref $_[0] eq 'SCALAR'
162 ( ref $_[0] eq 'REF' and ref ${$_[0]} eq 'ARRAY' )
166 # FIXME XSify - this can be done so much more efficiently
167 sub is_plain_value ($) {
176 # deliberately not using Devel::OverloadInfo - the checks we are
177 # intersted in are much more limited than the fullblown thing, and
178 # this is a relatively hot piece of code
180 # FIXME - DBI needs fixing to stringify regardless of DBD
182 # either has stringification which DBI SHOULD prefer out of the box
183 #first { *{$_ . '::(""'}{CODE} } @{ mro::get_linear_isa( ref $_[0] ) }
184 overload::Method($_[0], '""')
186 # has nummification and fallback is *not* disabled
188 $_[1] = first { *{"${_}::(0+"}{CODE} } @{ mro::get_linear_isa( ref $_[0] ) }
190 ( ! defined ${"$_[1]::()"} or ${"$_[1]::()"} )
198 my $list_ctx_ok_stack_marker;
200 sub fail_on_internal_wantarray {
201 return if $list_ctx_ok_stack_marker;
203 if (! defined wantarray) {
204 croak('fail_on_internal_wantarray() needs a tempvar to save the stack marker guard');
208 while ( ( (caller($cf+1))[3] || '' ) =~ / :: (?:
210 # these are public API parts that alter behavior on wantarray
211 search | search_related | slice | search_literal
215 # these are explicitly prefixed, since we only recognize them as valid
216 # escapes when they come from the guts of CDBICompat
217 CDBICompat .*? :: (?: search_where | retrieve_from_sql | retrieve_all )
224 (caller($cf))[0] =~ /^(?:DBIx::Class|DBICx::)/
228 DBIx::Class::Exception->throw( sprintf (
229 "Improper use of %s(%s) instance in list context at %s line %d\n\n\tStacktrace starts",
230 ref($obj), hrefaddr($obj), (caller($cf))[1,2]
231 ), 'with_stacktrace');
235 weaken ( $list_ctx_ok_stack_marker = $mark );