equal
deleted
inserted
replaced
3 use strict; |
3 use strict; |
4 use warnings; |
4 use warnings; |
5 |
5 |
6 sub new { |
6 sub new { |
7 my $class = ref $_[0] ? ref shift : shift; |
7 my $class = ref $_[0] ? ref shift : shift; |
8 return bless {} => $class; |
8 my $self = bless {} => $class; |
|
9 my $r = shift; |
|
10 $r = s/\s*$//; # should match any \r or \n too |
|
11 |
|
12 # decode the status |
|
13 if (($self->{error_code}) = $r =~ /^E(.)/) { |
|
14 $self->{ok} = 0; |
|
15 } |
|
16 elsif (my ($jobid, $data, $csum) = $r =~ /^[DO](..)(.*)(..)$/) { |
|
17 $self->{ok} = 1; |
|
18 $self->{data} = defined $data ? $data : ""; |
|
19 } |
|
20 else { |
|
21 die "unknown response $r"; |
|
22 } |
|
23 |
|
24 return $self; |
9 } |
25 } |
10 |
26 |
11 sub ok { |
27 sub ok { |
12 my $self = shift; |
28 my $self = shift; |
13 return $self->{ok}; |
29 return $self->{ok}; |
14 } |
30 } |
15 |
31 |
16 sub result { |
32 sub data { |
17 my $self = shift; |
33 my $self = shift; |
18 return undef if not $self->{ok}; |
34 return undef if not $self->{ok}; |
19 return $self->{result}; |
35 return $self->{result}; |
20 } |
36 } |
21 |
37 |
22 sub error { |
38 sub error { |
23 my $self = shift; |
39 my $self = shift; |
24 return undef if $self->{ok}; |
40 return $self->{ok} ? undef : $self->{error_code}; |
25 return $self->{error_code}; |
|
26 } |
41 } |
27 |
42 |
28 sub error_message { |
43 sub error_message { |
29 my $self = shift; |
44 my $self = shift; |
30 |
45 |
44 |
59 |
45 =head1 SYNOPSIS |
60 =head1 SYNOPSIS |
46 |
61 |
47 use Quancom; |
62 use Quancom; |
48 |
63 |
49 my $q = new Quancom 172.16.0.22; |
64 my $quancom = new Quancom 172.16.0.22; |
50 my $r = $q->cmd("xxxxxx") |
65 my $result = $q->cmd("xxxxxx"); |
51 or die $r->error_message; |
66 |
|
67 if ($result->error) { die $result->error_message } |
|
68 else { print $result->data, "\n" } |
52 |
69 |
53 =head1 METHODS |
70 =head1 METHODS |
54 |
71 |
55 =over |
72 =over |
56 |
73 |
57 =item B<ok> ( ) |
74 =item constructor B<new> ( ) |
58 |
75 |
59 Use this method to query the last operations status. |
76 Probably you'll never use this. |
60 |
77 |
61 =item B<result> ( ) |
78 =item B<data> ( ) |
62 |
79 |
63 Returns the last result. This is valid only if the last status is ok, |
80 Returns the last result. This is valid only if the last status is ok, |
64 otherwise you'll get "undef". |
81 otherwise you'll get "undef". |
|
82 |
|
83 =item B<error> ( ) |
|
84 |
|
85 Returns the error code - if any - or 'undef' if there was no error. |
65 |
86 |
66 =item B<error_message> ( [I<error code>] ) |
87 =item B<error_message> ( [I<error code>] ) |
67 |
88 |
68 Returns a message describing the last error. Of if you pass an error |
89 Returns a message describing the last error. Of if you pass an error |
69 code it will the return the associated message. |
90 code it will the return the associated message. |
70 |
91 |
71 =item B<error> ( ) |
92 =item B<ok> ( ) |
72 |
93 |
73 Returns the last error code (numerical). |
94 Use this method to query the last operations status. |
74 |
95 |
75 =back |
96 =back |
|
97 |
|
98 =head1 SEE ALSO |
|
99 |
|
100 L<Quancom> |
76 |
101 |
77 =head1 AUTHOR |
102 =head1 AUTHOR |
78 |
103 |
79 Maik Schueller |
104 Maik Schueller |
80 Heiko Schlittermann |
105 Heiko Schlittermann |