blib/lib/POE/Filter/EPPTCP.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 84 SCAR 37.4
CC
6
Cov
0%
get_one
30.0
get_one_start
6.0
put
2.0
CRAP 42.0
1 package POE::Filter::EPPTCP;
2  
3 our $VERSION = '1.000';
4  
5 use 5.024;
6 use utf8;
7 use strictures 2;
8  
9 use English qw(-no_match_vars);
10  
11 #ABSTRACT: EPP Frame parsing for POE
12  
13 use Moose qw(has extends);
14 use MooseX::NonMoose;
15  
16 extends 'Moose::Object', 'POE::Filter';
17  
18 has 'buffer' => (
19 'is' => 'ro',
20 'traits' => ['Array'],
21 'isa' => 'ArrayRef',
22 'lazy' => 1,
23 'clearer' => '_clear_buffer',
24 'default' => sub { [] },
25 'handles' => {
26 'has_buffer' => 'count',
27 'all_buffer' => 'elements',
28 'push_buffer' => 'push',
29 'shift_buffer' => 'shift',
30 'unshift_buffer' => 'unshift',
31 'join_buffer' => 'join',
32 },
33 );
34  
35 sub get_one_start {
36 my ($self, $raw) = @_;
37  
38 if (defined $raw) {
39 foreach my $raw_data (@{$raw}) {
40 $self->push_buffer($raw_data);
41 }
42 }
43  
44 return;
45 } ## end sub get_one_start
46  
47 sub get_one {
48  
49 my ($self) = @_;
50  
51 my $buf = q{};
52  
53 my $frames = [];
54  
55 BUFFER_LOOP: while ($self->has_buffer()) {
56 my ($len, $eppframe) = (0, undef);
57  
58 $buf .= $self->shift_buffer();
59  
60 if (4 < length $buf) {
61 my $lenbuf = substr $buf, 0, 4;
62 ($len) = unpack 'N', $lenbuf;
63  
64 if ($len <= length $buf) {
65  
66 # Get the whole frame, and remove it from $buf
67 $eppframe = substr $buf, 0, $len, q{};
68  
69 # Remove the header from the frame.
70 substr $eppframe, 0, 4, q{};
71 } ## end if ($len <= length $buf)
72 } ## end if (4 < length $buf)
73  
74 if (defined $eppframe) {
75 push @{$frames}, $eppframe;
76  
77 last BUFFER_LOOP;
78 }
79 } ## end BUFFER_LOOP: while ($self->has_buffer())
80  
81 # If we have some remaining buffer, put it back into the buffer ring, at the beginning.
82 if (length $buf > 0) {
83 $self->unshift_buffer($buf);
84 }
85  
86 return $frames;
87 } ## end sub get_one
88  
89 sub put {
90 my ($self, $frames) = @_;
91 my $output = [];
92  
93 foreach my $frame (@{$frames}) {
94 push @{$output}, pack('N', 4 + length $frame) . $frame;
95 }
96  
97 return $output;
98 } ## end sub put
99  
100 no Moose;
101 __PACKAGE__->meta()->make_immutable();
102  
103 1;
104  
105 =pod
106 =encoding utf8
107  
108 =head1 NAME
109  
110 POE::Filter::EPPTCP - Parsing EPP-TCP Frames for the POE framework
111  
112 =head1 VERSION
113  
114 version 1.140700
115  
116 =head1 SYNOPSIS
117  
118 use POE::Filter::EPPTCP;
119 my $filter = POE::Filter::EPPTCP->new();
120  
121 my $wheel = POE::Wheel:ReadWrite->new(
122 Filter => $filter,
123 InputEvent => 'input_event',
124 );
125  
126 =head1 DESCRIPTION
127  
128 POE::Filter::EPPTCP provides POE with a completely encapsulated EPP over TCP
129 parsing strategy for POE::Wheels that will be dealing with EPP over TCP streams.
130  
131 It returns complete frames, which should be XML, but the parsing of the XML
132 is left to the consumer.
133  
134 =head1 PRIVATE_ATTRIBUTES
135  
136 =head2 buffer
137  
138 is: ro, isa: ArrayRef, traits: Array
139  
140 buffer holds the raw data to be parsed. Raw data should be split on network
141 new lines before being added to the buffer. Access to this attribute is
142 provided by the following methods:
143  
144 handles =>
145 {
146 has_buffer => 'count',
147 all_buffer => 'elements',
148 push_buffer => 'push',
149 shift_buffer => 'shift',
150 unshift_buffer => 'unshift',
151 join_buffer => 'join',
152 }
153  
154 =head1 PUBLIC_METHODS
155  
156 =head2 get_one_start
157  
158 (ArrayRef $raw?)
159  
160 This method is part of the POE::Filter API. See L<POE::Filter/get_one_start>
161 for an explanation of its usage.
162  
163 =head2 get_one
164  
165 returns (ArrayRef)
166  
167 This method is part of the POE::Filter API. See L<POE::Filter/get_one> for an
168 explanation of its usage.
169  
170 =head2 put
171  
172 (ArrayRef $nodes) returns (ArrayRef)
173  
174 This method is part of the POE::Filter API. See L<POE::Filter/put> for an
175 explanation of its usage.
176  
177 =head1 AUTHOR
178  
179 Mathieu Arnold <mat@cpan.org>
180  
181 =head1 COPYRIGHT AND LICENSE
182  
183 This software is copyright (c) 2021 by Mathieu Arnold <mat@cpan.org>
184  
185 This is free software; you can redistribute it and/or modify it under
186 the same terms as the Perl 5 programming language system itself.
187  
188 =cut
189  
190 __END__
191