From b8e5db8fb8cbf8fcd7f6f826bff489d38830ae91 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 27 Jun 2010 17:50:45 +0200 Subject: [PATCH 1/1] load storable files This involves special file format which is basically dumps of storable objects joined together --- lib/MojoFacets/Data.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/MojoFacets/Data.pm b/lib/MojoFacets/Data.pm index 3d1ac65..86d71bc 100644 --- a/lib/MojoFacets/Data.pm +++ b/lib/MojoFacets/Data.pm @@ -43,6 +43,9 @@ sub index { } elsif ( -f $file && $file =~ m/\.csv$/i ) { $file =~ s/$data_dir\/*//; push @files, $file; + } elsif ( -f $file && $file =~ m/\.storable/i ) { + $file =~ s/$data_dir\/*//; + push @files, $file; } else { #warn "IGNORE: $file\n"; } @@ -186,6 +189,18 @@ sub _load_path { if ( -f $full_path ) { if ( $full_path =~ m/.csv/i ) { $data = MojoFacets::Import::CSV->new( full_path => $full_path )->data; + } elsif ( $full_path =~ m/.storable/ ) { + warn "open $full_path ", -s $full_path, " bytes"; + open(my $pipe, "<", $full_path) || die $!; + while ( my $o = eval { Storable::fd_retrieve $pipe } ) { + if ( defined $o->{item} ) { + push @{ $data->{items} }, $o->{item}; + } else { + warn "SKIP ",dump($o); + } + } + close($pipe); + warn "loaded ", $#{ $data->{items} } + 1, " items from $full_path\n"; } else { $data = MojoFacets::Import::File->new( full_path => $full_path, path => $path )->data; } -- 2.20.1