Quancom/Result.pm
changeset 3 200d69222aed
equal deleted inserted replaced
2:a19ea3b8c48d 3:200d69222aed
       
     1 package Quancom::Result;
       
     2 
       
     3 use strict;
       
     4 use warnings;
       
     5 
       
     6 sub new {
       
     7     my $class = ref $_[0] ? ref shift : shift;
       
     8     return bless {} => $class;
       
     9 }
       
    10 
       
    11 sub ok {
       
    12     my $self = shift;
       
    13     return $self->{ok};
       
    14 }
       
    15 
       
    16 sub result {
       
    17     my $self = shift;
       
    18     return undef if not $self->{ok};
       
    19     return $self->{result};
       
    20 }
       
    21 
       
    22 sub error {
       
    23     my $self = shift;
       
    24     return undef if $self->{ok};
       
    25     return $self->{error_code};
       
    26 }
       
    27 
       
    28 sub error_message {
       
    29     my $self = shift;
       
    30 
       
    31     return undef if !@_ and $self->{ok};
       
    32 
       
    33     return ("checksum error", "character error", "invalid command",
       
    34         "invalid width")[ @_ ? $_[0] : $self->{error_code} ];
       
    35 }
       
    36 
       
    37 1;
       
    38 
       
    39 __END__
       
    40 
       
    41 =head1 NAME
       
    42 
       
    43 Quancom::Result - perl module to access the usb opto quancom device result
       
    44 
       
    45 =head1 SYNOPSIS
       
    46 
       
    47     use Quancom;
       
    48 
       
    49     my $q = new Quancom 172.16.0.22;
       
    50     my $r = $q->cmd("xxxxxx") 
       
    51 	or die $r->error_message;
       
    52 
       
    53 =head1 METHODS
       
    54 
       
    55 =over
       
    56 
       
    57 =item B<ok> ( )
       
    58 
       
    59 Use this method to query the last operations status.
       
    60 
       
    61 =item B<result> ( )
       
    62 
       
    63 Returns the last result. This is valid only if the last status is ok,
       
    64 otherwise you'll get "undef".
       
    65 
       
    66 =item B<error_message> ( [I<error code>] )
       
    67 
       
    68 Returns a message describing the last error. Of if you pass an error
       
    69 code it will the return the associated message.
       
    70 
       
    71 =item B<error> ( )
       
    72 
       
    73 Returns the last error code (numerical).
       
    74 
       
    75 =back
       
    76 
       
    77 =head1 AUTHOR
       
    78 
       
    79     Maik Schueller
       
    80     Heiko Schlittermann
       
    81 
       
    82 =cut