blib/lib/POE/Filter/SSL/PreFilter.pm

filter: Statementstmt 44.4% 32 / 72 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 7 / 14 Podpod n/a totaltotal 41.4% 39 / 94 CC 5 SCAR 18.1
CC
5
Cov
40%
__ANON__
20.0
__ANON__
6.0
__ANON__
2.0
CRAP 6.1
« blib/lib/POE/Filter/SSL.pm ↑ Summary SSL.xs »
1 package POE::Filter::SSL::PreFilter;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use POE qw (Filter::HTTPD Filter::Stackable Wheel::ReadWrite);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $globalinfos = {};
9  
10 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=3.7
11 1 our $PATCH = 18;
12 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 my $old_set_input_filter = \&POE::Wheel::ReadWrite::set_input_filter;
14 0 ▶ *POE::Wheel::ReadWrite::set_input_filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
15 0 my $self = shift;
16 0 my $new_filter = shift;
17 0 my $unique_id = $self->[POE::Wheel::ReadWrite::UNIQUE_ID()];
18 0 my $ret = $old_set_input_filter->($self, $new_filter, @_);
19 0 $poe_kernel->yield(ref($self) . "($unique_id) -> ssl patch" => "input" => $self);
20 0 return $ret;
21 1 };
22 1 my $old_set_output_filter = \&POE::Wheel::ReadWrite::set_output_filter;
23 0 ▶ *POE::Wheel::ReadWrite::set_output_filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 my $self = shift;
25 0 my $new_filter = shift;
26 0 my $unique_id = $self->[POE::Wheel::ReadWrite::UNIQUE_ID()];
27 0 my $ret = $old_set_output_filter->($self, $new_filter, @_);
28 0 $poe_kernel->yield(ref($self) . "($unique_id) -> ssl patch" => "output" => $self);
29 0 return $ret;
30 1 };
31 1 my $old_new = \&POE::Wheel::ReadWrite::new;
32 0 ▶ *POE::Wheel::ReadWrite::new = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 my $class = shift;
34 0 my %arg = @_;
35 0 my $self = $old_new->($class,%arg);
36 0 my $unique_id = $self->[POE::Wheel::ReadWrite::UNIQUE_ID];
37 $poe_kernel->state(
38 $self->[$PATCH] = ref($self) . "($unique_id) -> ssl patch",
39 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
40 0 my $type = $_[ARG0];
41 0 my $self = $_[ARG1];
42 0 ▶ if ($_[HEAP]->{self}->{PreFilter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[3]{"self"}{"PreFilter"}) 0 0 0
43 $_[HEAP]->{self}->{"PreFilter".ref($self).$self->[POE::Wheel::ReadWrite::UNIQUE_ID()]} = $_[HEAP]->{self}->{PreFilter}->clone()
44 0 ▶ unless ($_[HEAP]->{self}->{"PreFilter".ref($self).$self->[POE::Wheel::ReadWrite::UNIQUE_ID()]});
Branch: 1 branch
BranchTrueFalseTotal
unless $_[3]{"self"}{'PreFilter' . ref($self) . $self->[16]} 0 0 0
45 0 ▶ if ($type eq "input") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'input') { } 0 0 0
46 $old_set_input_filter->($self, POE::Filter::Stackable->new(
47 Filters => [
48 0 $_[HEAP]->{self}->{"PreFilter".ref($self).$self->[POE::Wheel::ReadWrite::UNIQUE_ID()]},
49 $self->get_input_filter()
50 ]
51 ));
52 } else {
53 $old_set_output_filter->($self, POE::Filter::Stackable->new(
54 Filters => [
55 0 $_[HEAP]->{self}->{"PreFilter".ref($self).$self->[POE::Wheel::ReadWrite::UNIQUE_ID()]},
56 $self->get_output_filter()
57 ]
58 ));
59 }
60 }
61 }
62 0 );
63 0 $poe_kernel->yield(ref($self) . "($unique_id) -> ssl patch" => "input" => $self);
64 0 $poe_kernel->yield(ref($self) . "($unique_id) -> ssl patch" => "output" => $self);
65 0 return $self;
66 1 };
67 1 my $old_set_filter = \&POE::Wheel::ReadWrite::set_filter;
68 0 ▶ *POE::Wheel::ReadWrite::set_filter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 my $self = shift;
70 0 my $new_filter = shift;
71 0 my $unique_id = $self->[POE::Wheel::ReadWrite::UNIQUE_ID()];
72 0 my $ret = $old_set_filter->($self, $new_filter, @_);
73 0 $poe_kernel->yield(ref($self) . "($unique_id) -> ssl patch" => "input" => $self);
74 0 $poe_kernel->yield(ref($self) . "($unique_id) -> ssl patch" => "output" => $self);
75 0 return $ret;
76 1 };
77 1 my $old_destroy = \&POE::Wheel::ReadWrite::DESTROY;
78 0 ▶ *POE::Wheel::ReadWrite::DESTROY = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
79 0 my $self = shift;
80 0 ▶ if ($self->[$PATCH]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$POE::Filter::SSL::PreFilter::PATCH]) 0 0 0
81 0 $poe_kernel->state($self->[$PATCH]);
82 0 $self->[$PATCH] = undef;
83 }
84 0 return $old_destroy->($self, @_);
85 1 };
86 0 ▶ *POE::Filter::HTTPD::get_pending = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 0 return undef;
88 1 };
89 1 ▶ use warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 }
91  
92  
93 =head1 NAME
94  
95 POE::Filter::SSL::Prefilter - Allow to add a PreFilter on Compontents using Wheels
96  
97 =head1 VERSION
98  
99 Version 0.39
100  
101 =head1 DESCRIPTION
102  
103 This is an extension for some POE::Component::Server modules to use POE::Filters in front of their own used Filters
104  
105 =back
106  
107 =head1 SYNOPSIS
108  
109 By default filters like I<POE::Filter::SSL> can only be used if you specify the filters by
110 manualy creating the POE::Wheel by our own. This allows this to be done if a compontent is doing this.
111  
112 =over 2
113  
114 =item HTTPS-Server
115  
116 use POE::Filter::SSL;
117 use POE::Component::Server::HTTP;
118 use HTTP::Status;
119 my $aliases = POE::Component::Server::HTTP->new(
120 Port => 443,
121 ContentHandler => {
122 '/' => \&handler,
123 '/dir/' => sub { return; },
124 '/file' => sub { return; }
125 },
126 Headers => { Server => 'My Server' },
127 PreFilter => POE::Filter::SSL->new(
128 crt => 'server.crt',
129 key => 'server.key',
130 cacrt => 'ca.crt'
131 )
132 );
133  
134 sub handler {
135 my ($request, $response) = @_;
136 $response->code(RC_OK);
137 $response->content("Hi, you fetched ". $request->uri);
138 return RC_OK;
139 }
140  
141 POE::Kernel->run();
142 POE::Kernel->call($aliases->{httpd}, "shutdown");
143 # next line isn't really needed
144 POE::Kernel->call($aliases->{tcp}, "shutdown");
145  
146 =back
147  
148 =head1 COPYRIGHT & LICENSE
149  
150 Copyright 2010-2017 Markus Schraeder, CryptoMagic GmbH, all rights reserved.
151  
152 This program is free software; you can redistribute it and/or modify it
153 under the same terms as Perl itself.
154  
155 =cut
156  
157 1 1; # End of POE::Filter::SSL::PreFilter
« blib/lib/POE/Filter/SSL.pm ↑ Summary SSL.xs »