From: Marius Gavrilescu Date: Sat, 9 Dec 2017 17:35:49 +0000 (+0200) Subject: Another method X-Git-Tag: 0.001~3 X-Git-Url: http://git.ieval.ro/?p=slob.git;a=commitdiff_plain;h=0e15b49616308e77f3f6ede65711ea70a876af47 Another method --- diff --git a/lib/Slob.pm b/lib/Slob.pm index b1eb4f8..8298bec 100644 --- a/lib/Slob.pm +++ b/lib/Slob.pm @@ -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. diff --git a/t/Slob.t b/t/Slob.t index b0ab28f..395c59e 100644 --- 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;