File Coverage

blib/lib/DB/Pluggable.pm
Criterion Covered Total %
statement 25 50 50.0
branch 0 8 0.0
condition n/a
subroutine 8 15 53.3
pod 5 7 71.4
total 38 80 47.5


line stmt bran cond sub pod time code
1             package DB::Pluggable;
2 1     1   41483 use strict;
  1         4  
  1         38  
3 1     1   5 use warnings;
  1         2  
  1         28  
4 1     1   30 use 5.010;
  1         3  
  1         44  
5 1     1   1377 use Brickyard::Accessor new => 1, rw => [qw(brickyard)];
  1         1291  
  1         11  
6 1     1   1218 use Brickyard 1.111750;
  1         3142  
  1         207  
7             our $VERSION = '1.112001';
8              
9             sub run_with_config {
10 0     0 1 0 my $file = $_[1];
11 0         0 __PACKAGE__->new->init_from_config($file)->run;
12             }
13              
14             sub plugins_with {
15 0     0 1 0 my ($self, $role) = @_;
16 0         0 $self->brickyard->plugins_with($role);
17             }
18              
19             sub init_from_config {
20 1     1 1 21 my $self = shift;
21 1         8 $self->brickyard(Brickyard->new(base_package => 'DB::Pluggable'));
22 1         24 $self->brickyard->init_from_config(@_);
23 1         54 $self;
24             }
25              
26             sub enable_watchfunction {
27 0     0 1   my $self = shift;
28 1     1   8 no warnings 'once';
  1         2  
  1         974  
29 0           $DB::trace |= 4; # Enable watchfunction
30             }
31              
32             sub run {
33 0     0 1   my $self = shift;
34 0           $DB::Pluggable::HANDLER = $self;
35 0           $_->initialize for $self->plugins_with(-Initializer);
36             }
37             1;
38              
39             # switch package so as to get the desired stack trace
40             package # hide from PAUSE indexer
41             DB;
42              
43             sub watchfunction {
44 0 0   0 0   return unless defined $DB::Pluggable::HANDLER;
45 0           my $depth = 1;
46 0           while (1) {
47 0           my ($package, $file, $line, $sub) = caller $depth;
48 0 0         last unless defined $package;
49 0 0         return if $sub =~ /::DESTROY$/;
50 0           $depth++;
51             }
52 0           $_->watchfunction for $DB::Pluggable::HANDLER->plugins_with(-WatchFunction);
53             }
54              
55             sub afterinit {
56 0 0   0 0   return unless defined $DB::Pluggable::HANDLER;
57 0           $_->afterinit for $DB::Pluggable::HANDLER->plugins_with(-AfterInit);
58             }
59 1     1   8 no warnings 'redefine';
  1         3  
  1         302  
60             my $DB_eval = \&DB::eval;
61             *eval = sub {
62 0     0     my @result;
63 0           for my $plugin ($DB::Pluggable::HANDLER->plugins_with(-Eval)) {
64 0           push @result => $plugin->eval;
65             }
66 0           &$DB_eval; # XXX Why doesn't this work if called from the plugin?
67 0           $_->() for grep { ref eq 'CODE' } @result;
  0            
68             };
69             1;
70              
71             =pod
72              
73             =for test_synopsis 1;
74             __END__