File Coverage

blib/lib/Plack/Component.pm
Criterion Covered Total %
statement 33 37 89.1
branch 3 4 75.0
condition 4 11 36.3
subroutine 11 12 91.6
pod 4 6 66.6
total 55 70 78.5


line stmt bran cond sub pod time code
1             package Plack::Component;
2 103     103   125673 use strict;
  103         153  
  103         2627  
3 103     103   350 use warnings;
  103         149  
  103         3193  
4 103     103   427 use Carp ();
  103         530  
  103         1514  
5 103     103   21294 use Plack::Util;
  103         214  
  103         3781  
6 103     103   417 use overload '&{}' => \&to_app_auto, fallback => 1;
  103         90  
  103         1091  
7              
8             sub new {
9 283     283 1 2225900 my $proto = shift;
10 283   33     2354 my $class = ref $proto || $proto;
11              
12 283         416 my $self;
13 283 100 66     2076 if (@_ == 1 && ref $_[0] eq 'HASH') {
14 208         409 $self = bless {%{$_[0]}}, $class;
  208         1047  
15             } else {
16 75         174 $self = bless {@_}, $class;
17             }
18              
19 283         897 $self;
20             }
21              
22             sub to_app_auto {
23 131     131 0 145 my $self = shift;
24 131 50 50     529 if (($ENV{PLACK_ENV} || '') eq 'development') {
25 0         0 my $class = ref($self);
26 0         0 warn "WARNING: Automatically converting $class instance to a PSGI code reference. " .
27             "If you see this warning for each request, you probably need to explicitly call " .
28             "to_app() i.e. $class->new(...)->to_app in your PSGI file.\n";
29             }
30 131         358 $self->to_app(@_);
31             }
32              
33             # NOTE:
34             # this is for back-compat only,
35             # future modules should use
36             # Plack::Util::Accessor directly
37             # or their own favorite accessor
38             # generator.
39             # - SL
40             sub mk_accessors {
41 0     0 0 0 my $self = shift;
42 0   0     0 Plack::Util::Accessor::mk_accessors( ref( $self ) || $self, @_ )
43             }
44              
45 289     289 1 380 sub prepare_app { return }
46              
47             sub to_app {
48 344     344 1 913 my $self = shift;
49 344         1516 $self->prepare_app;
50 344     1097   4403 return sub { $self->call(@_) };
  1097         4592  
51             }
52              
53              
54             sub response_cb {
55 761     761 1 4806 my($self, $res, $cb) = @_;
56 761         11963 Plack::Util::response_cb($res, $cb);
57             }
58              
59             1;
60              
61             __END__