--- a/lib/Quancom/Result.pm Tue Dec 16 16:08:43 2008 +0100
+++ b/lib/Quancom/Result.pm Wed Dec 17 23:31:39 2008 +0100
@@ -5,7 +5,23 @@
sub new {
my $class = ref $_[0] ? ref shift : shift;
- return bless {} => $class;
+ my $self = bless {} => $class;
+ my $r = shift;
+ $r = s/\s*$//; # should match any \r or \n too
+
+ # decode the status
+ if (($self->{error_code}) = $r =~ /^E(.)/) {
+ $self->{ok} = 0;
+ }
+ elsif (my ($jobid, $data, $csum) = $r =~ /^[DO](..)(.*)(..)$/) {
+ $self->{ok} = 1;
+ $self->{data} = defined $data ? $data : "";
+ }
+ else {
+ die "unknown response $r";
+ }
+
+ return $self;
}
sub ok {
@@ -13,7 +29,7 @@
return $self->{ok};
}
-sub result {
+sub data {
my $self = shift;
return undef if not $self->{ok};
return $self->{result};
@@ -21,8 +37,7 @@
sub error {
my $self = shift;
- return undef if $self->{ok};
- return $self->{error_code};
+ return $self->{ok} ? undef : $self->{error_code};
}
sub error_message {
@@ -46,34 +61,44 @@
use Quancom;
- my $q = new Quancom 172.16.0.22;
- my $r = $q->cmd("xxxxxx")
- or die $r->error_message;
+ my $quancom = new Quancom 172.16.0.22;
+ my $result = $q->cmd("xxxxxx");
+
+ if ($result->error) { die $result->error_message }
+ else { print $result->data, "\n" }
=head1 METHODS
=over
-=item B<ok> ( )
+=item constructor B<new> ( )
-Use this method to query the last operations status.
+Probably you'll never use this.
-=item B<result> ( )
+=item B<data> ( )
Returns the last result. This is valid only if the last status is ok,
otherwise you'll get "undef".
+=item B<error> ( )
+
+Returns the error code - if any - or 'undef' if there was no error.
+
=item B<error_message> ( [I<error code>] )
Returns a message describing the last error. Of if you pass an error
code it will the return the associated message.
-=item B<error> ( )
+=item B<ok> ( )
-Returns the last error code (numerical).
+Use this method to query the last operations status.
=back
+=head1 SEE ALSO
+
+L<Quancom>
+
=head1 AUTHOR
Maik Schueller