blib/lib/Plack/Middleware/Camelcadedb.pm

filter: Statementstmt 31.2% 15 / 48 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 3 totaltotal 24.3% 19 / 78 CC 8 SCAR 25.0
CC
8
Cov
24%
import
30.0
__ANON__
12.0
reopen_camelcadedb_connection
6.0
CRAP 12.2
↑ Summary
1 package Plack::Middleware::Camelcadedb;
2  
3 =head1 NAME
4  
5 Plack::Middleware::Camelcadedb - interactive debugging for Plack applications
6  
7 =head1 SYNOPSIS
8  
9 # should be the first/one of the first modules to be loaded
10 use Plack::Middleware::Camelcadedb (
11 remote_host => "localhost:9000",
12 );
13 use Plack::Builder;
14  
15 builder {
16 enable "Camelcadedb";
17 $app;
18 };
19  
20 You will also need to configure remote debugging in IntelliJ as described in the
21 L<Debugging|https://github.com/Camelcade/Perl5-IDEA/wiki/Perl-Debugger>
22 section of the L<Camelcade plugin|https://github.com/Camelcade/Perl5-IDEA/wiki>
23 wiki.
24  
25 =head1 DESCRIPTION
26  
27 This module provides a thin integration layer on top of L<Devel::Camelcadedb>.
28  
29 At the beginning of each request, the middleware connects to IntelliJ to
30 allow remote debugging. If IntelliJ is not running or not set up for debugging,
31 execution continues as normal.
32  
33 =cut
34  
35 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 1 our $VERSION = '0.03';
39  
40 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 DEBUG_SINGLE_STEP_ON => 0x20,
42 DEBUG_USE_SUB_ADDRESS => 0x40,
43 DEBUG_REPORT_GOTO => 0x80,
44 DEBUG_ALL => 0x7ff,
45 1 };
46  
47 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 DEBUG_OFF => 0x0,
49 DEBUG_PREPARE_FLAGS => # 0x73c
50 DEBUG_ALL & ~(DEBUG_USE_SUB_ADDRESS|DEBUG_REPORT_GOTO|DEBUG_SINGLE_STEP_ON),
51 1 };
52  
53 1 our @ISA;
54  
55 0 ▶sub import {
Subroutine import: not called CC=5 SCAR=34.0
56 0 my ($class, %args) = @_;
57  
58 die "Specify 'remote_host'"
59 0 ▶ unless $args{remote_host};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"remote_host"} 0 0 0
60 0 my ($host, $port) = split /:/, $args{remote_host}, 2;
61  
62 0 $ENV{PERL5_DEBUG_HOST} = $host;
63 0 $ENV{PERL5_DEBUG_PORT} = $port;
64 0 $ENV{PERL5_DEBUG_ROLE} = 'client';
65 0 $ENV{PERL5_DEBUG_AUTOSTART} = 0;
66  
67 0 ▶ if ($args{enbugger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"enbugger"}) 0 0 0
68 0 require Enbugger;
69  
70 0 Enbugger->VERSION(2.014);
71 0 Enbugger->load_source;
72 }
73  
74 0 my $inc_path = $args{debug_client_path};
75 0 ▶ unshift @INC, ref $inc_path ? @$inc_path : $inc_path
Branch: 2 branches
BranchTrueFalseTotal
if $inc_path 0 0 0
ref $inc_path ? : 0 0 0
76 if $inc_path;
77 0 require Devel::Camelcadedb;
78  
79 0 $^P = DEBUG_PREPARE_FLAGS;
80  
81 0 require Plack::Middleware;
82 0 require Plack::Request;
83 0 require Plack::Response;
84 0 require Plack::Util;
85  
86 0 @ISA = qw(Plack::Middleware);
87 }
88  
89 0 ▶sub reopen_camelcadedb_connection {
Subroutine reopen_camelcadedb_connection: not called CC=2 SCAR=17.9
Pod undocumented
90 0 DB::connect_or_reconnect();
91 0 ▶ DB::enable() if DB::is_connected();
Branch: 1 branch
BranchTrueFalseTotal
if DB::is_connected() 0 0 0
92 }
93  
94 0 ▶sub close_camelcadedb_connection {
Subroutine close_camelcadedb_connection: not called CC=1 SCAR=6.9
Pod undocumented
95 0 DB::disconnect();
96 0 DB::disable();
97 # this works around uWSGI bug fixed by
98 # https://github.com/unbit/uwsgi/commit/c6f61719106908b82ba2714fd9d2836fb1c27f22
99 0 $^P = DEBUG_OFF;
100 }
101  
102 0 ▶sub call {
Subroutine call: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my($self, $env) = @_;
104  
105 0 reopen_camelcadedb_connection();
106  
107 0 my $res = $self->app->($env);
108 0 ▶ Plack::Util::response_cb($res, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
109 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
110 # use $_[0] to try to avoid a copy
111 0 ▶ if (!defined $_[0] && DB::is_connected()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_[0] and DB::is_connected()) 0 0 0
Condition0%0/3
not defined $_[0] and DB::is_connected()
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $_[0] and DB::is_connected()
not defined $_[0] DB::is_connected()
Truth table0%0/3
not(A) and B
A= not defined $_[0]B= DB::is_connected()
ABresult
0X0
100
111
112 0 close_camelcadedb_connection();
113 }
114  
115 0 return $_[0];
116 0 };
117 0 });
118 }
119  
120 1 1;
121  
122 __END__
↑ Summary