15731346b979d2a5c96e7bcfceb267c8a6fdb7b8
[Biblio-RFID.git] / lib / RFID / Biblio / Readers.pm
1 package RFID::Biblio::Readers;
2
3 =head1 NAME
4
5 RFID::Biblio::Readers - autodetect supported readers
6
7 =head1 FUNCTIONS
8
9 =head2 available
10
11 Probe each RFID reader supported and returns succefull ones
12
13   my @rfid = RFID::Biblio::Readers->available( $regex_filter );
14
15 =head1 SEE ALSO
16
17 =head2 RFID reader implementations
18
19 L<RFID::Biblio::3M810>
20
21 L<RFID::Biblio::CPRM02>
22
23 L<RFID::Biblio::librfid>
24
25 =cut
26
27 use warnings;
28 use strict;
29
30 use lib 'lib';
31
32 my @readers = ( '3M810', 'CPRM02', 'librfid' );
33
34 sub available {
35         my ( $self, $filter ) = @_;
36
37         my @rfid;
38
39         foreach my $reader ( @readers ) {
40                 next if $reader !~ /$filter/i;
41                 my $module = "RFID::Biblio::$reader";
42                 eval "use $module";
43                 die $@ if $@;
44                 if ( my $rfid = $module->new( device => '/dev/ttyUSB0' ) ) {
45                         push @rfid, $rfid;
46                         warn "# added $module\n";
47                 } else {
48                         warn "# ignored $module\n";
49                 }
50         }
51
52         die "no readers found" unless @rfid;
53
54         return @rfid;
55 }
56