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);
60 our @EXPORT_OK = qw(sigwarn_silencer modver_gt_or_eq fail_on_internal_wantarray refcount hrefaddr is_exception);
62 sub sigwarn_silencer ($) {
65 croak "Expecting a regexp" if ref $pattern ne 'Regexp';
67 my $orig_sig_warn = $SIG{__WARN__} || sub { CORE::warn(@_) };
69 return sub { &$orig_sig_warn unless $_[0] =~ $pattern };
72 sub hrefaddr ($) { sprintf '0x%x', &Scalar::Util::refaddr }
75 croak "Expecting a reference" if ! length ref $_[0];
78 # No tempvars - must operate on $_[0], otherwise the pad
79 # will count as an extra ref
80 B::svref_2object($_[0])->REFCNT;
83 sub is_exception ($) {
86 # this is not strictly correct - an eval setting $@ to undef
87 # is *not* the same as an eval setting $@ to ''
88 # but for the sake of simplicity assume the following for
90 return 0 unless defined $e;
92 my ($not_blank, $suberror);
96 $not_blank = ($e ne '') ? 1 : 0;
101 if (defined $suberror) {
102 if (length (my $class = blessed($e) )) {
103 carp_unique( sprintf(
104 'External exception object %s=%s(%s) implements partial (broken) '
105 . 'overloading preventing it from being used in simple ($x eq $y) '
106 . 'comparisons. Given Perl\'s "globally cooperative" exception '
107 . 'handling this type of brokenness is extremely dangerous on '
108 . 'exception objects, as it may (and often does) result in silent '
109 . '"exception substitution". DBIx::Class tries to work around this '
110 . 'as much as possible, but other parts of your software stack may '
111 . 'not be even aware of this. Please submit a bugreport against the '
112 . 'distribution containing %s and in the meantime apply a fix similar '
113 . 'to the one shown at %s, in order to ensure your exception handling '
114 . 'is saner application-wide. What follows is the actual error text '
115 . "as generated by Perl itself:\n\n%s\n ",
120 'http://v.gd/DBIC_overload_tempfix/',
124 # workaround, keeps spice flowing
125 $not_blank = ("$e" ne '') ? 1 : 0;
128 # not blessed yet failed the 'ne'... this makes 0 sense...
137 sub modver_gt_or_eq ($$) {
138 my ($mod, $ver) = @_;
140 croak "Nonsensical module name supplied"
141 if ! defined $mod or ! length $mod;
143 croak "Nonsensical minimum version supplied"
144 if ! defined $ver or $ver =~ /[^0-9\.\_]/;
146 local $SIG{__WARN__} = sigwarn_silencer( qr/\Qisn't numeric in subroutine entry/ )
147 if SPURIOUS_VERSION_CHECK_WARNINGS;
150 eval { $mod->VERSION($ver) } ? 1 : 0;
154 my $list_ctx_ok_stack_marker;
156 sub fail_on_internal_wantarray {
157 return if $list_ctx_ok_stack_marker;
159 if (! defined wantarray) {
160 croak('fail_on_internal_wantarray() needs a tempvar to save the stack marker guard');
164 while ( ( (caller($cf+1))[3] || '' ) =~ / :: (?:
166 # these are public API parts that alter behavior on wantarray
167 search | search_related | slice | search_literal
171 # these are explicitly prefixed, since we only recognize them as valid
172 # escapes when they come from the guts of CDBICompat
173 CDBICompat .*? :: (?: search_where | retrieve_from_sql | retrieve_all )
180 (caller($cf))[0] =~ /^(?:DBIx::Class|DBICx::)/
184 DBIx::Class::Exception->throw( sprintf (
185 "Improper use of %s(%s) instance in list context at %s line %d\n\n\tStacktrace starts",
186 ref($obj), hrefaddr($obj), (caller($cf))[1,2]
187 ), 'with_stacktrace');
191 weaken ( $list_ctx_ok_stack_marker = $mark );