invalidate tags after going through all reader
[Biblio-RFID.git] / lib / Biblio / RFID / Reader.pm
index f5e6fd4..0ec702e 100644 (file)
@@ -63,6 +63,7 @@ sub tags {
                                        $self->{_tags}->{$tag}->{blocks} = $blocks->{$tag} || die "no $tag in ",dump($blocks);
                                        my $afi = $rfid->read_afi($tag);
                                        $self->{_tags}->{$tag}->{afi} = $afi;
+                                       $self->{_tags}->{$tag}->{type} = $rfid->tag_type( $tag );
 
                                };
                                if ( $@ ) {
@@ -78,11 +79,11 @@ sub tags {
 
                }
        
-               foreach my $tag ( grep { $self->{_tags}->{$_}->{time} == 0 } keys %{ $self->{_tags} } ) {
-                       $triggers->{leave}->( $tag ) if $triggers->{leave};
-                       $self->_invalidate_tag( $tag );
-               }
+       }
 
+       foreach my $tag ( grep { $self->{_tags}->{$_}->{time} == 0 } keys %{ $self->{_tags} } ) {
+               $triggers->{leave}->( $tag ) if $triggers->{leave};
+               $self->_invalidate_tag( $tag );
        }
 
        warn "## _tags ",dump( $self->{_tags} );
@@ -103,6 +104,23 @@ sub tags {
 sub blocks { $_[0]->{_tags}->{$_[1]}->{ 'blocks' } || confess "no blocks for $_[1]"; };
 sub afi    { $_[0]->{_tags}->{$_[1]}->{ 'afi'    } || confess "no afi for $_[1]"; };
 
+=head2 to_hash
+
+  $self->to_hash( $tag );
+
+=cut
+
+sub to_hash {
+       my ( $self, $tag ) = @_;
+       return unless exists $self->{_tags}->{$tag};
+       my $type = $self->{_tags}->{$tag}->{type} || confess "can't find type for tag $tag ",dump( $self->{_tags} );
+       my $decode = 'Biblio::RFID::' . $type;
+       my $hash = $decode->to_hash( $self->blocks( $tag ) );
+       $hash->{tag_type} = $type;
+       return $hash;
+}
+
+
 =head1 PRIVATE
 
 =head2 _invalidate_tag