File Coverage

lib/POE/Filter/EPPTCP.pm
Criterion Covered Total %
statement 51 51 100.0
branch 6 6 100.0
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 70 70 100.0


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