Slackget/Network/Message.pm

filter: Statementstmt 15.0% 8 / 53 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 16.6% 2 / 12 Podpod 100% 10 / 10 totaltotal 19.8% 20 / 101 CC 11 SCAR 22.9
CC
11
Cov
11%
action
20.0
action_id
20.0
is_success
6.0
CRAP 9.9
« Slackget/Network/Backend/Gzip.pm ↑ Summary Slackget/Status.pm »
1 package Slackware::Slackget::Network::Message ;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Slackware::Slackget::Network::Message - The response object for Slackware::Slackget::Network class
9  
10 =head1 VERSION
11  
12 Version 1.0.0
13  
14 =cut
15  
16 2 our $VERSION = '0.9.1';
17  
18 =head1 SYNOPSIS
19  
20 This class is the message object used by the Slackware::Slackget::Network class to return informations from the network connection.
21  
22 This module is the evolution of the old Slackware::Slackget::Network::Response.
23  
24 =cut
25  
26 =head2 new
27  
28 the constructor require no argument. But store every given argument in the object (which is a hashref).
29  
30 my $msg = new Slackware::Slackget::Network::Message ;
31  
32 =cut
33  
34 sub new
35 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
36 0 my $class = shift;
37 0 my $self = {@_};
38 0 bless($self,$class);
39 0 return $self;
40 }
41  
42 =head2 new_from_data
43  
44 This is an alternative constructor to create a Slackware::Slackget::Network::Message with the whole slack-get protocol compatible data structure.
45  
46 You must provide the following arguments :
47  
48 * an action id (integer)
49 * a action (string)
50 * some data
51  
52 Here is a little example :
53  
54 my $msg = Slackware::Slackget::Network::Message->new(
55 123456789,
56 'search',
57 @keywords,
58 );
59  
60 =cut
61  
62 0 ▶sub new_from_data {
Subroutine new_from_data: not called CC=1 SCAR=6.9
Pod documented
63 0 my $class = shift;
64 0 my $action_id = shift;
65 0 my $action = shift;
66 0 my @data = @_;
67 0 my $self = {};
68 # my $self = {
69 # raw_data => {
70 # Enveloppe => {
71 # Action => {
72 # id => $action_id ,
73 # content => $action,
74 # },
75 # Data => {
76 # content => join('',@_),
77 # },
78 # }
79 # }
80 # };
81 0 bless($self,$class);
82 0 $self->create_enveloppe();
83 0 $self->{raw_data}->{Enveloppe}->{Action}->{id} = $action_id;
84 0 $self->{raw_data}->{Enveloppe}->{Action}->{content} = $action;
85 0 $self->{raw_data}->{Enveloppe}->{Data}->{content} = join('',@data);
86 0 return $self;
87 }
88  
89 =head2 create_enveloppe
90  
91 Create a base enveloppe for the SlackGetProtocol in the raw_data section. This method access directly to the object's data structure.
92  
93 Be carefull not to use it on an already initialized object. Else all "raw_data" will be lost.
94  
95 $self = {
96 action => 0,
97 action_id => 0,
98 raw_data => {
99 Enveloppe => {
100 Action => {
101 id => 0 ,
102 content => 0,
103 },
104 Data => {},
105 }
106 }
107 };
108  
109 =cut
110  
111 0 ▶sub create_enveloppe {
Subroutine create_enveloppe: not called CC=1 SCAR=6.9
Pod documented
112 0 my $self = shift;
113 0 $self->action(0);
114 0 $self->action_id(0);
115 $self->{raw_data} = {
116 0 Enveloppe => {
117 Action => {
118 id => 0 ,
119 content => 0,
120 },
121 Data => {},
122 }
123 };
124 }
125  
126 =head2 is_success
127  
128 true if the operation is a success
129  
130 =cut
131  
132 0 ▶sub is_success {
Subroutine is_success: not called CC=2 SCAR=17.9
Pod documented
133 0 my $self = shift;
134 0 my $data = shift;
135 0 ▶ return $data ? $self->{is_success}=$data : $self->{is_success};
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 0 0 0
136 }
137  
138 =head2 is_error
139  
140 true if the operation is an error
141  
142 =cut
143  
144 0 ▶sub is_error {
Subroutine is_error: not called CC=1 SCAR=6.9
Pod documented
145 0 my $self = shift;
146 0 return !$self->{is_success} ;
147 }
148  
149 =head2 error_msg
150  
151 return a string containing an error message. Works only if $response->is_error() is true.
152  
153 =cut
154  
155 0 ▶sub error_msg {
Subroutine error_msg: not called CC=2 SCAR=17.9
Pod documented
156 0 my $self = shift;
157 0 my $data = shift;
158 0 ▶ return $data ? $self->{error_msg}=$data : $self->{error_msg};
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 0 0 0
159 }
160  
161 =head2 have_choice
162  
163 true if the daemon return a choice
164  
165 =cut
166  
167 0 ▶sub have_choice {
Subroutine have_choice: not called CC=2 SCAR=17.9
Pod documented
168 0 my $self = shift;
169 0 my $data = shift;
170 0 ▶ return $data ? $self->{have_choice}=$data : $self->{have_choice};
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 0 0 0
171 }
172  
173 =head2 data
174  
175 return all raw data returned by the remote daemon
176  
177 =cut
178  
179 0 ▶sub data {
Subroutine data: not called CC=2 SCAR=17.9
Pod documented
180 0 my $self = shift;
181 0 my $data = shift;
182 0 ▶ return $data ? $self->{raw_data}=$data : $self->{raw_data};
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 0 0 0
183 }
184  
185 =head2 action
186  
187 return (or set) the action of the message (all network messages must have an action).
188  
189 =cut
190  
191 0 ▶sub action{
Subroutine action: not called CC=4 SCAR=30.0
Pod documented
192 0 my $self = shift;
193 0 my $data = shift;
194 0 ▶ if($data){
Branch: 1 branch
BranchTrueFalseTotal
if ($data) { } 0 0 0
195 0 ▶ $self->{raw_data}->{Enveloppe}->{Action}->{content} = $data if(exists($self->{raw_data}->{Enveloppe}->{Action}) && ref($self->{raw_data}->{Enveloppe}->{Action}) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"raw_data"}{"Enveloppe"}{"Action"} and ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH" 0 0 0
Condition0%0/3
exists $self->{"raw_data"}{"Enveloppe"}{"Action"} and ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"raw_data"}{"Enveloppe"}{"Action"} and ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH"
exists $self->{"raw_data"}{"Enveloppe"}{"Action"} ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH"
Truth table0%0/3
A and B
A= exists $self->{"raw_data"}{"Enveloppe"}{"Action"}B= ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH"
ABresult
0X0
100
111
196 0 $self->{action}=$data
197 }else{
198 0 return $self->{action};
199 }
200 }
201  
202 =head2 action_id
203  
204 return (or set) the action ID of the message (all network messages must have an action id).
205  
206 =cut
207  
208 0 ▶sub action_id{
Subroutine action_id: not called CC=4 SCAR=30.0
Pod documented
209 0 my $self = shift;
210 0 my $data = shift;
211 0 ▶ if($data){
Branch: 1 branch
BranchTrueFalseTotal
if ($data) { } 0 0 0
212 0 ▶ $self->{raw_data}->{Enveloppe}->{Action}->{id} = $data if(exists($self->{raw_data}->{Enveloppe}->{Action}) && ref($self->{raw_data}->{Enveloppe}->{Action}) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"raw_data"}{"Enveloppe"}{"Action"} and ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH" 0 0 0
Condition0%0/3
exists $self->{"raw_data"}{"Enveloppe"}{"Action"} and ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"raw_data"}{"Enveloppe"}{"Action"} and ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH"
exists $self->{"raw_data"}{"Enveloppe"}{"Action"} ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH"
Truth table0%0/3
A and B
A= exists $self->{"raw_data"}{"Enveloppe"}{"Action"}B= ref $self->{"raw_data"}{"Enveloppe"}{"Action"} eq "HASH"
ABresult
0X0
100
111
213 0 $self->{action_id}=$data
214 }else{
215 0 return $self->{action_id};
216 }
217 }
218  
219  
220 =head1 AUTHOR
221  
222 DUPUIS Arnaud, C<< <a.dupuis@infinityperl.org> >>
223  
224 =head1 BUGS
225  
226 Please report any bugs or feature requests to
227 C<bug-Slackware-Slackget@rt.cpan.org>, or through the web interface at
228 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget>.
229 I will be notified, and then you'll automatically be notified of progress on
230 your bug as I make changes.
231  
232 =head1 SUPPORT
233  
234 You can find documentation for this module with the perldoc command.
235  
236 perldoc Slackware::Slackget
237  
238  
239 You can also look for information at:
240  
241 =over 4
242  
243 =item * Infinity Perl website
244  
245 L<http://www.infinityperl.org/category/slack-get>
246  
247 =item * slack-get specific website
248  
249 L<http://slackget.infinityperl.org>
250  
251 =item * RT: CPAN's request tracker
252  
253 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget>
254  
255 =item * AnnoCPAN: Annotated CPAN documentation
256  
257 L<http://annocpan.org/dist/Slackware-Slackget>
258  
259 =item * CPAN Ratings
260  
261 L<http://cpanratings.perl.org/d/Slackware-Slackget>
262  
263 =item * Search CPAN
264  
265 L<http://search.cpan.org/dist/Slackware-Slackget>
266  
267 =back
268  
269 =head1 ACKNOWLEDGEMENTS
270  
271 Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.
272  
273 =head1 COPYRIGHT & LICENSE
274  
275 Copyright 2005 DUPUIS Arnaud, All Rights Reserved.
276  
277 This program is free software; you can redistribute it and/or modify it
278 under the same terms as Perl itself.
279  
280 =cut
281  
282 2 1; # End of Slackware::Slackget::Network::Message
« Slackget/Network/Backend/Gzip.pm ↑ Summary Slackget/Status.pm »