1 package DBIx::Class::Carp;
7 use namespace::clean ();
10 my ($skip_pattern, $class) = @_;
12 my $skip_class_data = $class->_skip_namespace_frames
13 if ($class and $class->can('_skip_namespace_frames'));
15 $skip_pattern = qr/$skip_pattern|$skip_class_data/
18 my $fr_num = 1; # skip us and the calling carp*
20 while (@f = caller($fr_num++)) {
21 last unless $f[0] =~ $skip_pattern;
24 my ($ln, $calling) = @f # if empty - nothing matched - full stack
25 ? ( "at $f[1] line $f[2]", $f[3] )
26 : ( Carp::longmess(), '{UNKNOWN}' )
31 $calling =~ /::/ ? "$calling(): " : "$calling: ", # cargo-cult from Carp::Clan
37 @warn = "Warning: something's wrong" unless @warn;
39 # back-compat with Carp::Clan - a warning ending with \n does
40 # not include caller info
43 $warn[-1] =~ /\n$/ ? '' : " $ln\n"
48 my (undef, $skip_pattern) = @_;
51 $skip_pattern = $skip_pattern
52 ? qr/ ^ $into $ | $skip_pattern /xo
58 *{"${into}::carp"} = sub {
60 __find_caller($skip_pattern, $into),
66 *{"${into}::carp_once"} = sub {
71 __find_caller($skip_pattern, $into),
77 *{"${into}::carp_unique"} = sub {
78 my ($ln, $calling) = __find_caller($skip_pattern, $into);
79 my $msg = join ('', $calling, @_);
81 # unique carping with a hidden caller makes no sense
84 return if $seen->{$ln}{$msg};
85 $seen->{$ln}{$msg} = 1;
93 # cleanup after ourselves
94 namespace::clean->import(-cleanee => $into, qw/carp carp_once carp_unique/);
98 die (__PACKAGE__ . " does not implement unimport yet\n");
105 DBIx::Class::Carp - Provides advanced Carp::Clan-like warning functions for DBIx::Class internals
109 Documentation is lacking on purpose - this an experiment not yet fit for
110 mass consumption. If you use this do not count on any kind of stability,
111 in fact don't even count on this module's continuing existence (it has
112 been noindexed for a reason).
114 In addition to the classic interface:
116 use DBIx::Class::Carp '^DBIx::Class'
118 this module also supports a class-data based way to specify the exclusion
119 regex. A message is only carped from a callsite that matches neither the
120 closed over string, nor the value of L</_skip_namespace_frames> as declared
121 on the B<first> callframe origin.
123 =head1 CLASS ATTRIBUTES
125 =head2 _skip_namespace_frames
127 A classdata attribute holding the stringified regex matching callsites that
128 should be skipped by the carp methods below. An empty string C<q{}> is treated
129 like no setting/C<undef> (the distinction is necessary due to semantics of the
130 class data accessors provided by L<Class::Accessor::Grouped>)
132 =head1 EXPORTED FUNCTIONS
134 This module export the following 3 functions. Only warning related C<carp*>
135 is being handled here, for C<croak>-ing you must use
136 L<DBIx::Class::Schema/throw_exception> or L<DBIx::Class::Exception>.
140 Carps message with the file/line of the first callsite not matching
141 L</_skip_namespace_frames> nor the closed-over arguments to
142 C<use DBIx::Class::Carp>.
146 Like L</carp> but warns once for every distinct callsite (subject to the
147 same ruleset as L</carp>).
151 Like L</carp> but warns only once for the life of the perl interpreter
152 (regardless of callsite).