Middleware/Profile.pm

filter: Statementstmt 100% 27 / 27 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 97.3% 36 / 37 SCAR 11.0
CC
3
Cov
97%
_build_profiler
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« Middleware/MobileAttribute.pm ↑ Summary Middleware/ModuleReload.pm »
1 package HTTP::Engine::Middleware::Profile;
2 2 ▶use HTTP::Engine::Middleware;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 with 'HTTP::Engine::Middleware::Role::Logger';
5  
6 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 has profiler_class => (
9 is => 'ro',
10 default => 'Runtime',
11 );
12  
13 2 has 'profiler' => (
14 is => 'rw',
15 required => 1,
16 lazy_build => 1,
17 );
18  
19 has 'config' => (
20 is => 'rw',
21 isa => 'HashRef',
22 1 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
23 2 );
24  
25 sub _build_profiler {
26 2 ▶ my $self = shift;
Subroutine _build_profiler: called CC=3 SCAR=11.0
27 2 my $class = $self->profiler_class;
28 2 ▶ $class = "HTTP::Engine::Middleware::Profile::$class"
Branch: 1 branch
BranchTrueFalseTotal
unless $class =~ s/^\+// 1 1 2
29 unless $class =~ s/^\+//;
30 2 Any::Moose::load_class($class);
31 2 ▶ $@ and Carp::croak($@);
Branch: 1 branch
BranchTrueFalseTotal
$@ and Carp::croak($@) 0 2 2
32 2 $class->new($self->config);
33 }
34  
35  
36 before_handle {
37 2 ▶ my ( $c, $self, $req ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
38 2 $self->profiler->start(@_);
39 2 $req;
40 2 };
41  
42 after_handle {
43 2 ▶ my ( $c, $self, $req, $res ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
44 2 $self->profiler->end(@_);
45 2 $self->profiler->report(@_);
46 2 $res;
47 2 };
48  
49 2 __MIDDLEWARE__
50  
51 __END__
52  
53 =head1 NAME
54  
55 HTTP::Engine::Middleware::Profile - stopwatch for request processing time
56  
57 =head1 SYNOPSIS
58  
59 my $mw = HTTP::Engine::Middleware->new;
60 $mw->install( 'HTTP::Engine::Middleware::Profile' => {
61 logger => sub {
62 warn @_;
63 },
64 });
65 HTTP::Engine->new(
66 interface => {
67 module => 'YourFavoriteInterfaceHere',
68 request_handler => $mw->handler( \&handler ),
69 }
70 )->run();
71  
72 =head1 DESCRIPTION
73  
74 This module profile request processing time.
75  
76 =head1 AUTHORS
77  
78 dann
79  
80 =cut
« Middleware/MobileAttribute.pm ↑ Summary Middleware/ModuleReload.pm »