File Coverage

blib/lib/Puncheur/Lite.pm
Criterion Covered Total %
statement 82 82 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 19 19 100.0
pod n/a
total 103 106 97.1


line stmt bran cond sub pod time code
1             package Puncheur::Lite;
2 1     1   25 use 5.010;
  1         3  
  1         31  
3 1     1   4 use strict;
  1         1  
  1         22  
4 1     1   5 use warnings;
  1         1  
  1         25  
5              
6 1     1   5 use File::Spec;
  1         1  
  1         24  
7 1     1   693 use Data::Section::Simple ();
  1         494  
  1         14  
8              
9 1     1   480 use Puncheur ();
  1         4  
  1         23  
10 1     1   792 use Puncheur::Dispatcher::Lite ();
  1         5  
  1         49  
11              
12             sub import {
13 1     1   3 my ($class) = @_;
14 1         5 my $caller = caller;
15              
16             {
17 1     1   6 no strict 'refs';
  1         2  
  1         66  
  1         2  
18 1         2 push @{"$caller\::ISA"}, 'Puncheur';
  1         16  
19              
20 1         11 $caller->load_plugin('HandleStatic');
21 1         16 my $to_psgi = $caller->can('to_psgi');
22              
23 1     1   7 no warnings 'redefine';
  1         2  
  1         72  
24 1         5 *{"$caller\::to_psgi"} = sub {
25 1     1   6 use strict 'refs';
  1         2  
  1         45  
26 1     1   6 my $app = $to_psgi->(@_);
27             {
28 1     1   5 no strict 'refs';
  1         2  
  1         57  
  1         3  
29 1 50       3 if (my @middlewares = @{"$caller\::_MIDDLEWARES"}) {
  1         9  
30 1     1   5 use strict 'refs';
  1         2  
  1         189  
31 1         3 for my $middleware (@middlewares) {
32 1         4 my ($klass, $args) = @$middleware;
33 1         8 $klass = Plack::Util::load_class($klass, 'Plack::Middleware');
34 1         54 $app = $klass->wrap($app, %$args);
35             }
36             }
37             }
38 1         1502 $app;
39 1         8 };
40              
41 1         47 *{"$caller\::enable_middleware"} = sub {
42 1     1   5 my ($klass, %args) = @_;
43 1         2 push @{"$caller\::_MIDDLEWARES"}, [$klass, \%args];
  1         9  
44 1         6 };
45 1         8 *{"$caller\::enable_session"} = sub {
46 1     1   5 use strict 'refs';
  1         3  
  1         308  
47 1     1   2 my (%args) = @_;
48 1   33     6 $args{state} ||= do {
49 1         976 require Plack::Session::State::Cookie;
50 1         6141 Plack::Session::State::Cookie->new(httponly => 1); # for security
51             };
52 1         827 require Plack::Middleware::Session;
53              
54 1         2988 my $func = $caller->can('enable_middleware');
55 1         7 $func->('Plack::Middleware::Session', %args);
56 1         5 };
57             }
58              
59             my $tmpl = sub {
60 1     1   10 File::Spec->catdir($caller->asset_dir, 'tmpl');
61 1         11 };
62 1     1   11 $caller->setting(
63 1         12 template_dir => [sub {Data::Section::Simple->new($caller)->get_data_section}, $tmpl],
64             );
65              
66 1         14 strict->import;
67 1         12 warnings->import;
68 1         7 utf8->import;
69 1         9 require feature;
70 1         113 feature->import(':5.10');
71              
72 1         2 goto do { Puncheur::Dispatcher::Lite->can('import') };
  1         19  
73             }
74              
75             1;