blib/lib/XAS/Lib/Stomp/POE/Filter.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 49 CC 3 SCAR 13.3
CC
3
Cov
0%
get_one_start
6.0
get_one
6.0
get_pending
2.0
CRAP 3.8
1 package XAS::Lib::Stomp::POE::Filter;
2  
3 our $VERSION = '0.01';
4  
5 use XAS::Lib::Stomp::Parser;
6  
7 use XAS::Class
8 debug => 0,
9 version => $VERSION,
10 base => 'XAS::Base',
11 accessors => 'filter',
12 vars => {
13 PARAMS => {
14 -target => { optional => 1, default => '1.0', regex => qr/(1\.0|1\.1|1\.2)/ },
15 }
16 }
17 ;
18  
19 # ---------------------------------------------------------------------
20 # Public methods
21 # ---------------------------------------------------------------------
22  
23 sub get_one_start {
24 my ($self, $buffers) = @_;
25  
26 foreach my $buffer (@$buffers) {
27  
28 if (my $frame = $self->filter->parse($buffer)) {
29  
30 push(@{$self->{frames}}, $frame);
31  
32 }
33  
34 }
35  
36 }
37  
38 sub get_one {
39 my ($self) = shift;
40  
41 my @ret;
42  
43 if (my $frame = shift(@{$self->{frames}})) {
44  
45 push(@ret, $frame);
46  
47 }
48  
49 return \@ret;
50  
51 }
52  
53 sub get_pending {
54 my ($self) = shift;
55  
56 return $self->filter->get_pending;
57  
58 }
59  
60 sub put {
61 my ($self, $frames) = @_;
62  
63 my @ret;
64  
65 foreach my $frame (@$frames) {
66  
67 my $buffer = $frame->as_string;
68  
69 push(@ret, $buffer);
70  
71 }
72  
73 return \@ret;
74  
75 }
76  
77 # ---------------------------------------------------------------------
78 # Private methods
79 # ---------------------------------------------------------------------
80  
81 sub init {
82 my $class = shift;
83  
84 my $self = $class->SUPER::init(@_);
85  
86 $self->{filter} = XAS::Lib::Stomp::Parser->new(
87 -target => $self->target,
88 -xdebug => $self->xdebug,
89 );
90  
91 return $self;
92  
93 }
94  
95 1;
96  
97 __END__
98  
99 =head1 NAME
100  
101 XAS::Lib::Stomp::POE::Filter - An I/O filter for the POE Environment
102  
103 =head1 SYNOPSIS
104  
105 use XAS::Lib::Stomp::POE::Filter;
106  
107 For a server
108  
109 POE::Component::Server::TCP->new(
110 ...
111 Filter => XAS::Lib::Stomp::POE::Filter->new(-target => '1.0'),
112 ...
113 );
114  
115 For a client
116  
117 POE::Component::Client::TCP->new(
118 ...
119 Filter => XAS::Lib::Stomp::POE::Filter->new(-target => '1.0'),
120 ...
121 );
122  
123 =head1 DESCRIPTION
124  
125 This module is a filter for the POE environment. It will translate the input
126 buffer into XAS::Lib::Stomp::Frame objects and serialize the output buffer
127 from said object.
128  
129 =head1 METHODS
130  
131 =head2 new
132  
133 This method initializes the module. It takes these parameters:
134  
135 =over 4
136  
137 =item B<-target>
138  
139 Specify a STOMP protocol version number. It currently supports 1.0,
140 1.1 and 1.2, defaulting to 1.0.
141  
142 =back
143  
144 =head1 SEE ALSO
145  
146 =over 4
147  
148 =item L<XAS|XAS>
149  
150 =back
151  
152 See the documentation for POE::Filter for usage.
153  
154 For more information on the STOMP protocol, please refer to: L<http://stomp.github.io/> .
155  
156 =head1 AUTHOR
157  
158 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
159  
160 =head1 COPYRIGHT AND LICENSE
161  
162 Copyright (C) 2014 Kevin L. Esteb
163  
164 This library is free software; you can redistribute it and/or modify
165 it under the same terms as Perl itself, either Perl version 5.8.8 or,
166 at your option, any later version of Perl 5 you may have available.
167  
168 See L<http://dev.perl.org/licenses/> for more information.
169  
170 =cut