File Coverage

blib/lib/XAS/Lib/Stomp/POE/Filter.pm
Criterion Covered Total %
statement 9 35 25.7
branch 0 8 0.0
condition n/a
subroutine 3 8 37.5
pod 5 5 100.0
total 17 56 30.3


line stmt bran cond sub pod time code
1             package XAS::Lib::Stomp::POE::Filter;
2              
3             our $VERSION = '0.03';
4              
5 1     1   4 use XAS::Lib::Stomp::Parser;
  1         1  
  1         26  
6 1     1   4 use XAS::Constants 'CRLF :stomp';
  1         1  
  1         5  
7              
8             use XAS::Class
9 1         7 debug => 0,
10             version => $VERSION,
11             base => 'XAS::Base',
12             accessors => 'filter eol',
13             constant => {
14             LF => "\n",
15             },
16             vars => {
17             PARAMS => {
18             -target => { optional => 1, default => undef, regex => STOMP_LEVELS },
19             }
20             }
21 1     1   239 ;
  1         2  
22              
23             #use Data::Hexdumper;
24              
25             # ---------------------------------------------------------------------
26             # Public methods
27             # ---------------------------------------------------------------------
28              
29             sub get_one_start {
30 0     0 1   my ($self, $buffers) = @_;
31              
32 0           foreach my $buffer (@$buffers) {
33              
34 0 0         if (my $frame = $self->filter->parse($buffer)) {
35              
36 0           push(@{$self->{frames}}, $frame);
  0            
37              
38             }
39              
40             }
41              
42             }
43              
44             sub get_one {
45 0     0 1   my ($self) = shift;
46              
47 0           my @ret;
48              
49 0 0         if (my $frame = shift(@{$self->{frames}})) {
  0            
50              
51 0           push(@ret, $frame);
52              
53             }
54              
55 0           return \@ret;
56              
57             }
58              
59             sub get_pending {
60 0     0 1   my ($self) = shift;
61              
62 0           return $self->filter->get_pending;
63              
64             }
65              
66             sub put {
67 0     0 1   my ($self, $frames) = @_;
68              
69 0           my @ret;
70              
71 0           foreach my $frame (@$frames) {
72              
73 0           my $buffer = $frame->as_string;
74              
75             # $self->log->debug(hexdump($buffer));
76 0           push(@ret, $buffer);
77              
78             }
79              
80 0           return \@ret;
81              
82             }
83              
84             # ---------------------------------------------------------------------
85             # Private methods
86             # ---------------------------------------------------------------------
87              
88             sub init {
89 0     0 1   my $class = shift;
90              
91 0           my $self = $class->SUPER::init(@_);
92              
93 0 0         unless (defined($self->{target})) {
94              
95 0           $self->{target} = $self->env->mqlevel;
96              
97             }
98              
99 0 0         $self->{eol} = ($self->target > 1.1) ? CRLF : LF;
100 0           $self->{filter} = XAS::Lib::Stomp::Parser->new(-target => $self->target);
101              
102 0           return $self;
103              
104             }
105              
106             1;
107              
108             __END__
109              
110             =head1 NAME
111              
112             XAS::Lib::Stomp::POE::Filter - An I/O filter for the POE Environment
113              
114             =head1 SYNOPSIS
115              
116             use XAS::Lib::Stomp::POE::Filter;
117              
118             For a server
119              
120             POE::Component::Server::TCP->new(
121             ...
122             Filter => XAS::Lib::Stomp::POE::Filter->new(),
123             ...
124             );
125              
126             For a client
127              
128             POE::Component::Client::TCP->new(
129             ...
130             Filter => XAS::Lib::Stomp::POE::Filter->new(),
131             ...
132             );
133              
134             =head1 DESCRIPTION
135              
136             This module is a filter for the POE environment. It will translate the input
137             buffer into L<XAS::Lib::Stomp::Frame|XAS::Lib::Stomp::Frame> objects and
138             serialize the output buffer from said object.
139              
140             =head1 METHODS
141              
142             =head2 new
143              
144             This method initializes the module.
145              
146             =head2 get_one_start($buffers)
147              
148             This method parses one frame for a buffer and stores it in an internal frames
149             buffer.
150              
151             =over 4
152              
153             =item B<$buffers>
154              
155             A reference to a buffer.
156              
157             =back
158              
159             =head2 get_one
160              
161             This method returns one frame from the internal buffer.
162              
163             =head2 get_pending
164              
165             This method returns the number of pending frames.
166              
167             =head2 put($buffers)
168              
169             This method pulls frames out of the buffer, stringifies them and places them
170             into a internal array. When done it returns that array.
171              
172             =over 4
173              
174             =item B<$buffers>
175              
176             A reference to a buffer of L<XAS::Lib::Stomp::Frame|XAS::Lib::Stomp::Frame>
177             frames.
178              
179             =back
180              
181             =head1 SEE ALSO
182              
183             =over 4
184              
185             =item L<XAS|XAS>
186              
187             =back
188              
189             See the documentation for L<POE::Filter|https://metacpan.org/pod/POE::Filter> for usage.
190              
191             For more information on the STOMP protocol, please refer to: L<http://stomp.github.io/> .
192              
193             =head1 AUTHOR
194              
195             Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
196              
197             =head1 COPYRIGHT AND LICENSE
198              
199             Copyright (C) 2014 Kevin L. Esteb
200              
201             This is free software; you can redistribute it and/or modify it under
202             the terms of the Artistic License 2.0. For details, see the full text
203             of the license at http://www.perlfoundation.org/artistic_license_2_0.
204              
205             =cut