_invalidate_tag when it leaves reader range
[Biblio-RFID.git] / lib / RFID / Biblio / Reader.pm
index 9b3e5cc..e99a35f 100644 (file)
@@ -10,7 +10,12 @@ use RFID::Biblio;
 
 =head1 NAME
 
-RFID::Biblio::Reader - autodetect supported readers
+RFID::Biblio::Reader - simple way to write RFID applications in perl
+
+=head1 DESCRIPTION
+
+This module will probe all available readers and use calls from
+L<RFID::Biblio::Reader::API> to invoke correct reader.
 
 =head1 FUNCTIONS
 
@@ -61,6 +66,7 @@ sub tags {
 
                foreach my $tag ( grep { $self->{inventory}->{$_} == 0 } keys %{ $self->{inventory} } ) {
                        $triggers->{leave}->( $self, $tag ) if $triggers->{leave};
+                       $self->_invalidate_tag( $tag );
                }
 
        }
@@ -85,6 +91,20 @@ sub afi    { $_[0]->{ 'afi'    }->{$_[1]} || die "no afi for $_[1]"; };
 
 =head1 PRIVATE
 
+=head2 _invalidate_tag
+
+  $rfid->_invalidate_tag( $tag );
+
+=cut
+
+sub _invalidate_tag {
+       my ( $self, $tag ) = @_;
+       delete $self->{'blocks'}->{$tag};
+       delete $self->{'afi'}->{$tag};
+       delete $self->{'inventory'}->{$tag};
+       warn "# _invalidate_tag $tag";
+}
+
 =head2 _available
 
 Probe each RFID reader supported and returns succefull ones
@@ -143,6 +163,8 @@ sub AUTOLOAD {
                push @out, $r->$command(@_);
        }
 
+       $self->_invalidate_tag( $_[0] ) if $command =~ m/write/;
+
        return @out;
 }