lib/Quancom/Result.pm
changeset 4 6f1e9c4bee3c
parent 3 200d69222aed
child 7 9c3e112933ae
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Quancom/Result.pm	Tue Dec 09 16:04:23 2008 +0100
@@ -0,0 +1,82 @@
+package Quancom::Result;
+
+use strict;
+use warnings;
+
+sub new {
+    my $class = ref $_[0] ? ref shift : shift;
+    return bless {} => $class;
+}
+
+sub ok {
+    my $self = shift;
+    return $self->{ok};
+}
+
+sub result {
+    my $self = shift;
+    return undef if not $self->{ok};
+    return $self->{result};
+}
+
+sub error {
+    my $self = shift;
+    return undef if $self->{ok};
+    return $self->{error_code};
+}
+
+sub error_message {
+    my $self = shift;
+
+    return undef if !@_ and $self->{ok};
+
+    return ("checksum error", "character error", "invalid command",
+        "invalid width")[ @_ ? $_[0] : $self->{error_code} ];
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Quancom::Result - perl module to access the usb opto quancom device result
+
+=head1 SYNOPSIS
+
+    use Quancom;
+
+    my $q = new Quancom 172.16.0.22;
+    my $r = $q->cmd("xxxxxx") 
+	or die $r->error_message;
+
+=head1 METHODS
+
+=over
+
+=item B<ok> ( )
+
+Use this method to query the last operations status.
+
+=item B<result> ( )
+
+Returns the last result. This is valid only if the last status is ok,
+otherwise you'll get "undef".
+
+=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> ( )
+
+Returns the last error code (numerical).
+
+=back
+
+=head1 AUTHOR
+
+    Maik Schueller
+    Heiko Schlittermann
+
+=cut