]> iEval git - slob.git/commitdiff
Another method
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 9 Dec 2017 17:35:49 +0000 (19:35 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 9 Dec 2017 17:35:49 +0000 (19:35 +0200)
lib/Slob.pm
t/Slob.t

index b1eb4f8a7bae668dff5365a1580834b89a35b119..8298becd0e964bb8e1e3508ff9f811793cc67cdd 100644 (file)
@@ -197,6 +197,15 @@ sub get_entry_of_storage_bin {
        substr $start_of_data, 4, $length;
 }
 
+sub seek_and_read_ref_and_data {
+       my ($self, $index) = @_;
+       my $ref = $self->seek_and_read_ref($index);
+       my $bin = $self->seek_and_read_storage_bin($ref->{bin_index});
+       my $data = $self->get_entry_of_storage_bin($bin, $ref->{item_index});
+       $ref->{data} = $data;
+       $ref
+}
+
 1;
 __END__
 
@@ -225,6 +234,11 @@ Slob - Read .slob dictionaries (as used by Aard 2)
   say "Value at position $second_ref->{item_index} is ",
     $slob->get_entry_of_storage_bin($bin, $second_ref->{item_index});
 
+  # instead of the above, we can do
+  my $second_ref_and_data = $slob->seek_and_read_ref_and_data(4);
+  say "Entry is for $second_ref_and_data->{key}";
+  say "Value is $second_ref_and_data->{data}";
+
 =head1 DESCRIPTION
 
 No documentation yet, see SYNOPSIS.
index b0ab28f8921c9a35d591948e041f5b5e302fb957..395c59eba88286f79a890d2bf50c614efdccf8bd 100644 (file)
--- a/t/Slob.t
+++ b/t/Slob.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 6;
+use Test::More tests => 7;
 BEGIN { use_ok('Slob') };
 
 my $slob = Slob->new('t/freedict-01.slob');
@@ -27,3 +27,5 @@ my $expected = <<'EOF';
 EOF
 chomp $expected;
 is $slob->get_entry_of_storage_bin($bin, $second_ref->{item_index}), $expected;
+
+is $slob->seek_and_read_ref_and_data(4)->{data}, $expected;
This page took 0.020405 seconds and 4 git commands to generate.