line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::HTTP::Spore::Role::Middleware; |
2
|
|
|
|
|
|
|
$Net::HTTP::Spore::Role::Middleware::VERSION = '0.09'; |
3
|
22
|
|
|
22
|
|
9742
|
use Moose::Role; |
|
22
|
|
|
|
|
57
|
|
|
22
|
|
|
|
|
188
|
|
4
|
22
|
|
|
22
|
|
111145
|
use Class::Load; |
|
22
|
|
|
|
|
52
|
|
|
22
|
|
|
|
|
1076
|
|
5
|
22
|
|
|
22
|
|
129
|
use Scalar::Util qw/blessed/; |
|
22
|
|
|
|
|
45
|
|
|
22
|
|
|
|
|
9854
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has middlewares => ( |
8
|
|
|
|
|
|
|
is => 'rw', |
9
|
|
|
|
|
|
|
isa => 'ArrayRef', |
10
|
|
|
|
|
|
|
traits => ['Array'], |
11
|
|
|
|
|
|
|
lazy => 1, |
12
|
|
|
|
|
|
|
default => sub { [] }, |
13
|
|
|
|
|
|
|
auto_deref => 1, |
14
|
|
|
|
|
|
|
handles => { _add_middleware => 'push', _filter_middlewares => 'grep' }, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _load_middleware { |
18
|
43
|
|
|
43
|
|
212
|
my ( $self, $mw, $cond, @args ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
43
|
100
|
|
|
|
372
|
Class::Load::load_class($mw) unless blessed($mw); |
21
|
|
|
|
|
|
|
|
22
|
41
|
|
|
|
|
1482
|
my $code = $mw->wrap( $cond, @args ); |
23
|
41
|
|
|
|
|
528
|
$self->_trace_msg('== enabling middleware %s', $mw); |
24
|
41
|
|
|
|
|
1607
|
$self->_add_middleware($code); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _complete_mw_name { |
28
|
41
|
|
|
41
|
|
127
|
my ($self, $mw) = @_; |
29
|
|
|
|
|
|
|
|
30
|
41
|
100
|
|
|
|
212
|
if ($mw =~ /^\+/) { |
|
|
50
|
|
|
|
|
|
31
|
1
|
|
|
|
|
4
|
$mw =~ s/^\+//; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif ($mw !~ /Net\:\:HTTP\:\:Spore\:\:Middleware/) { |
34
|
40
|
|
|
|
|
161
|
$mw = "Net::HTTP::Spore::Middleware::".$mw; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
41
|
|
|
|
|
124
|
return $mw; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub enable { |
41
|
43
|
|
|
43
|
0
|
755
|
my ($self, $mw, @args) = @_; |
42
|
|
|
|
|
|
|
|
43
|
43
|
100
|
|
|
|
169
|
confess "middleware name is missing" unless $mw; |
44
|
|
|
|
|
|
|
|
45
|
42
|
|
|
43
|
|
422
|
$self->enable_if(sub{1}, $mw, @args); |
|
43
|
|
|
|
|
188
|
|
46
|
40
|
|
|
|
|
140
|
$self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub enable_if { |
50
|
44
|
|
|
44
|
0
|
932
|
my ($self, $cond, $mw, @args) = @_; |
51
|
|
|
|
|
|
|
|
52
|
44
|
100
|
66
|
|
|
396
|
confess "condition must be a code ref" if (!$cond || ref $cond ne 'CODE'); |
53
|
|
|
|
|
|
|
|
54
|
43
|
100
|
|
|
|
187
|
if(ref($mw) eq 'CODE'){ # anonymous middleware |
55
|
2
|
|
|
|
|
8
|
Class::Load::load_class('Net::HTTP::Spore::Middleware'); |
56
|
2
|
|
|
|
|
58
|
my $anon = Class::MOP::Class->create_anon_class( |
57
|
|
|
|
|
|
|
superclasses => ['Net::HTTP::Spore::Middleware'], |
58
|
|
|
|
|
|
|
methods => { |
59
|
|
|
|
|
|
|
call => $mw |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
); |
62
|
2
|
|
|
|
|
1765
|
$mw = $anon->new_object; |
63
|
|
|
|
|
|
|
} else { |
64
|
41
|
|
|
|
|
222
|
$mw = $self->_complete_mw_name($mw); |
65
|
|
|
|
|
|
|
} |
66
|
43
|
|
|
|
|
585
|
$self->_load_middleware($mw, $cond, @args); |
67
|
41
|
|
|
|
|
108
|
$self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub reset_middlewares { |
71
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
72
|
1
|
|
|
|
|
35
|
$self->middlewares([]); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=pod |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=encoding UTF-8 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Net::HTTP::Spore::Role::Middleware |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 VERSION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
version 0.09 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHORS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Franck Cuny <franck.cuny@gmail.com> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Ash Berlin <ash@cpan.org> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item * |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Ahmad Fatoum <athreef@cpan.org> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=back |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Linkfluence. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
114
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |