Codebase list libdbix-class-perl / 7f9a3f7
Standardize the Moo import block, move quote_sub/qsub into ::_Util This way we will have less boilerplate in subsequent commits where we will use quote_sub standalone Add yet another test to make absolutely sure quote_sub won't leak any of the strictures insanity Peter Rabbitson 9 years ago
5 changed file(s) with 82 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
00 package # hide from pause until we figure it all out
11 DBIx::Class::Storage::BlockRunner;
22
3 use warnings;
34 use strict;
5
6 # DO NOT edit away without talking to riba first, he will just put it back
7 # BEGIN pre-Moo2 import block
8 BEGIN {
9 my $initial_fatal_bits = (${^WARNING_BITS}||'') & $warnings::DeadBits{all};
10 local $ENV{PERL_STRICTURES_EXTRA} = 0;
11 require Moo; Moo->import;
12 ${^WARNING_BITS} &= ( $initial_fatal_bits | ~ $warnings::DeadBits{all} );
13 }
14 # END pre-Moo2 import block
415
516 use DBIx::Class::Exception;
617 use DBIx::Class::Carp;
718 use Context::Preserve 'preserve_context';
8 use DBIx::Class::_Util 'is_exception';
19 use DBIx::Class::_Util qw(is_exception qsub);
920 use Scalar::Util qw(weaken blessed reftype);
1021 use Try::Tiny;
1122
12 # DO NOT edit away without talking to riba first, he will just put it back
13 BEGIN {
14 local $ENV{PERL_STRICTURES_EXTRA} = 0;
15 require Moo; Moo->import;
16 require Sub::Quote; Sub::Quote->import('quote_sub');
17 }
18 use warnings NONFATAL => 'all';
1923 use namespace::clean;
2024
2125 =head1 NAME
4246 has retry_handler => (
4347 is => 'ro',
4448 required => 1,
45 isa => quote_sub( q{
49 isa => qsub q{
4650 (Scalar::Util::reftype($_[0])||'') eq 'CODE'
4751 or DBIx::Class::Exception->throw('retry_handler must be a CODE reference')
48 }),
52 },
4953 );
5054
5155 has retry_debug => (
5256 is => 'rw',
5357 # use a sub - to be evaluated on the spot lazily
54 default => quote_sub( '$ENV{DBIC_STORAGE_RETRY_DEBUG}' ),
58 default => qsub '$ENV{DBIC_STORAGE_RETRY_DEBUG}',
5559 lazy => 1,
5660 );
5761
6670 writer => '_set_failed_attempt_count',
6771 default => 0,
6872 lazy => 1,
69 trigger => quote_sub(q{
73 trigger => qsub q{
7074 $_[0]->throw_exception( sprintf (
7175 'Reached max_attempts amount of %d, latest exception: %s',
7276 $_[0]->max_attempts, $_[0]->last_exception
7377 )) if $_[0]->max_attempts <= ($_[1]||0);
74 }),
78 },
7579 );
7680
7781 has exception_stack => (
7882 is => 'ro',
7983 init_arg => undef,
8084 clearer => '_reset_exception_stack',
81 default => quote_sub(q{ [] }),
85 default => qsub q{ [] },
8286 lazy => 1,
8387 );
8488
00 package DBIx::Class::Storage::Statistics;
1
12 use strict;
23 use warnings;
34
45 # DO NOT edit away without talking to riba first, he will just put it back
56 # BEGIN pre-Moo2 import block
67 BEGIN {
7 require warnings;
88 my $initial_fatal_bits = (${^WARNING_BITS}||'') & $warnings::DeadBits{all};
99 local $ENV{PERL_STRICTURES_EXTRA} = 0;
1010 require Moo; Moo->import;
11 require Sub::Quote; Sub::Quote->import('quote_sub');
1211 ${^WARNING_BITS} &= ( $initial_fatal_bits | ~ $warnings::DeadBits{all} );
1312 }
1413 # END pre-Moo2 import block
1514
1615 extends 'DBIx::Class';
17 use DBIx::Class::_Util 'sigwarn_silencer';
16 use DBIx::Class::_Util qw(sigwarn_silencer qsub);
1817 use namespace::clean;
1918
2019 =head1 NAME
6362 has _debugfh => (
6463 is => 'rw',
6564 lazy => 1,
66 trigger => quote_sub( '$_[0]->_defaulted_to_stderr(undef)' ),
65 trigger => qsub '$_[0]->_defaulted_to_stderr(undef)',
6766 builder => '_build_debugfh',
6867 );
6968
5353 use Carp 'croak';
5454 use Scalar::Util qw(weaken blessed reftype);
5555 use List::Util qw(first);
56
57 # DO NOT edit away without talking to riba first, he will just put it back
58 # BEGIN pre-Moo2 import block
59 BEGIN {
60 my $initial_fatal_bits = (${^WARNING_BITS}||'') & $warnings::DeadBits{all};
61 local $ENV{PERL_STRICTURES_EXTRA} = 0;
62 require Sub::Quote; Sub::Quote->import('quote_sub');
63 ${^WARNING_BITS} &= ( $initial_fatal_bits | ~ $warnings::DeadBits{all} );
64 }
65 sub qsub ($) { goto &quote_sub } # no point depping on new Moo just for this
66 # END pre-Moo2 import block
5667
5768 use base 'Exporter';
5869 our @EXPORT_OK = qw(
5970 sigwarn_silencer modver_gt_or_eq
6071 fail_on_internal_wantarray fail_on_internal_call
6172 refdesc refcount hrefaddr is_exception
62 perlstring
73 quote_sub qsub perlstring
6374 UNRESOLVABLE_CONDITION
6475 );
6576
9898 namespace::clean
9999 Try::Tiny
100100 Sub::Name
101 Sub::Quote
101102
102103 Scalar::Util
103104 List::Util
116117 {
117118 register_lazy_loadable_requires(qw(
118119 Moo
119 Sub::Quote
120120 Context::Preserve
121121 ));
122122
0 use warnings;
1 use strict;
2
3 use Test::More;
4 use Test::Warn;
5
6 use DBIx::Class::_Util 'quote_sub';
7
8 my $q = do {
9 no strict 'vars';
10 quote_sub '$x = $x . "buh"; $x += 42';
11 };
12
13 warnings_exist {
14 is $q->(), 42, 'Expected result after uninit and string/num conversion'
15 } [
16 qr/Use of uninitialized value/i,
17 qr/isn't numeric in addition/,
18 ], 'Expected warnings, strict did not leak inside the qsub'
19 or do {
20 require B::Deparse;
21 diag( B::Deparse->new->coderef2text( Sub::Quote::unquote_sub($q) ) )
22 }
23 ;
24
25 my $no_nothing_q = do {
26 no strict;
27 no warnings;
28 quote_sub <<'EOC';
29 my $n = "Test::Warn::warnings_exist";
30 warn "-->@{[ *{$n}{CODE} ]}<--\n";
31 warn "-->@{[ ${^WARNING_BITS} || '' ]}<--\n";
32 EOC
33 };
34
35 my $we_cref = Test::Warn->can('warnings_exist');
36
37 warnings_exist { $no_nothing_q->() } [
38 qr/^\Q-->$we_cref<--\E$/m,
39 qr/^\-\-\>\0*\<\-\-$/m, # some perls have a string of nulls, some just an empty string
40 ], 'Expected warnings, strict did not leak inside the qsub'
41 or do {
42 require B::Deparse;
43 diag( B::Deparse->new->coderef2text( Sub::Quote::unquote_sub($no_nothing_q) ) )
44 }
45 ;
46
47 done_testing;