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 101     101   91124 use strict;
  101         198  
  101         2382  
3 101     101   362 use warnings;
  101         189  
  101         1768  
4 101     101   394 use Carp ();
  101         183  
  101         1262  
5 101     101   21074 use Plack::Util;
  101         217  
  101         3946  
6 101     101   542 use overload '&{}' => \&to_app_auto, fallback => 1;
  101         176  
  101         1066  
7              
8             sub new {
9 283     283 1 4738 my $proto = shift;
10 283   33     1958 my $class = ref $proto || $proto;
11              
12 283         401 my $self;
13 283 100 66     2312 if (@_ == 1 && ref $_[0] eq 'HASH') {
14 208         343 $self = bless {%{$_[0]}}, $class;
  208         1019  
15             } else {
16 75         205 $self = bless {@_}, $class;
17             }
18              
19 283         878 $self;
20             }
21              
22             sub to_app_auto {
23 131     131 0 225 my $self = shift;
24 131 50 50     572 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         339 $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 395 sub prepare_app { return }
46              
47             sub to_app {
48 344     344 1 714 my $self = shift;
49 344         2064 $self->prepare_app;
50 344     1097   2321 return sub { $self->call(@_) };
  1097         10164  
51             }
52              
53              
54             sub response_cb {
55 761     761 1 6059 my($self, $res, $cb) = @_;
56 761         12528 Plack::Util::response_cb($res, $cb);
57             }
58              
59             1;
60              
61             __END__