| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::HTTP::Spore::Role::Middleware; | 
| 2 |  |  |  |  |  |  | $Net::HTTP::Spore::Role::Middleware::VERSION = '0.08'; | 
| 3 | 22 |  |  | 22 |  | 9571 | use Moose::Role; | 
|  | 22 |  |  |  |  | 54 |  | 
|  | 22 |  |  |  |  | 211 |  | 
| 4 | 22 |  |  | 22 |  | 109325 | use Class::Load; | 
|  | 22 |  |  |  |  | 56 |  | 
|  | 22 |  |  |  |  | 1121 |  | 
| 5 | 22 |  |  | 22 |  | 133 | use Scalar::Util qw/blessed/; | 
|  | 22 |  |  |  |  | 50 |  | 
|  | 22 |  |  |  |  | 9197 |  | 
| 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 |  | 218 | my ( $self, $mw, $cond, @args ) = @_; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 43 | 100 |  |  |  | 393 | Class::Load::load_class($mw) unless blessed($mw); | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 41 |  |  |  |  | 1623 | my $code = $mw->wrap( $cond, @args ); | 
| 23 | 41 |  |  |  |  | 539 | $self->_trace_msg('== enabling middleware %s', $mw); | 
| 24 | 41 |  |  |  |  | 1718 | $self->_add_middleware($code); | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub _complete_mw_name { | 
| 28 | 41 |  |  | 41 |  | 139 | my ($self, $mw) = @_; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 41 | 100 |  |  |  | 228 | if ($mw =~ /^\+/) { | 
|  |  | 50 |  |  |  |  |  | 
| 31 | 1 |  |  |  |  | 5 | $mw =~ s/^\+//; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  | elsif ($mw !~ /Net\:\:HTTP\:\:Spore\:\:Middleware/) { | 
| 34 | 40 |  |  |  |  | 179 | $mw = "Net::HTTP::Spore::Middleware::".$mw; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 41 |  |  |  |  | 131 | return $mw; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | sub enable { | 
| 41 | 43 |  |  | 43 | 0 | 786 | my ($self, $mw, @args) = @_; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 43 | 100 |  |  |  | 217 | confess "middleware name is missing" unless $mw; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 42 |  |  | 43 |  | 383 | $self->enable_if(sub{1}, $mw, @args); | 
|  | 43 |  |  |  |  | 225 |  | 
| 46 | 40 |  |  |  |  | 145 | $self; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub enable_if { | 
| 50 | 44 |  |  | 44 | 0 | 978 | my ($self, $cond, $mw, @args) = @_; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 44 | 100 | 66 |  |  | 404 | confess "condition must be a code ref" if (!$cond || ref $cond ne 'CODE'); | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 43 | 100 |  |  |  | 182 | if(ref($mw) eq 'CODE'){ # anonymous middleware | 
| 55 | 2 |  |  |  |  | 8 | Class::Load::load_class('Net::HTTP::Spore::Middleware'); | 
| 56 | 2 |  |  |  |  | 61 | my $anon = Class::MOP::Class->create_anon_class( | 
| 57 |  |  |  |  |  |  | superclasses => ['Net::HTTP::Spore::Middleware'], | 
| 58 |  |  |  |  |  |  | methods => { | 
| 59 |  |  |  |  |  |  | call => $mw | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | ); | 
| 62 | 2 |  |  |  |  | 1834 | $mw = $anon->new_object; | 
| 63 |  |  |  |  |  |  | } else { | 
| 64 | 41 |  |  |  |  | 243 | $mw = $self->_complete_mw_name($mw); | 
| 65 |  |  |  |  |  |  | } | 
| 66 | 43 |  |  |  |  | 632 | $self->_load_middleware($mw, $cond, @args); | 
| 67 | 41 |  |  |  |  | 116 | $self; | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub reset_middlewares { | 
| 71 | 1 |  |  | 1 | 0 | 3 | 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.08 | 
| 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 |