onsearch

 view release on metacpan or  search on metacpan

lib/OnSearch/Cache.pm  view on Meta::CPAN

    my ($vf, $offset_ref, $buf, $content, $stnc, $bufnc);
    $vf = OnSearch::VFile -> new;
    $vf -> vfopen ($path);
####
#### FIXME!!!
####
    return undef unless $vf;

    if ($matchcase =~ /no/) {
	$stnc = lc $searchterm;
    } else {
	$stnc = $searchterm;
    }

    $content = '';
    while (1) {
	$buf = $vf -> vfread (1024);
	if ($matchcase =~ /no/) {
	    $bufnc = lc $buf;
	} else {
	    $bufnc = $buf;
	}
	$content .= $bufnc;
	last if length ($buf) < 1024;
    }
    $vf -> vfclose;
    $content =~ s/\n/ /gs;

    return  OnSearch::StringSearch::_search_string ($searchterm, $content);
}

sub cache_file_name_from_term {
    my $term = $_[0];
    my $cachepath = cache_path ();
    my $initial = substr ($term, 0, 1);
    $initial = lc $initial;
    return "$cachepath/$initial";
}

=head2 caching_enabled ();

Returns 1 if caching is enabled, or undef otherwise.

=cut

sub caching_enabled {
    my $cfg = OnSearch::AppConfig -> new;
    my $cachingenabled = $cfg -> str (qw/CacheResults/);
    return ($cachingenabled eq '0') ? undef : 1;
}

sub cache_path { 
    my $cfg = OnSearch::AppConfig -> new;
    my $onsearchdir = $cfg -> str (qw/OnSearchDir/);
    undef $cfg;
    return $ENV{DOCUMENT_ROOT} . "/$onsearchdir/cache"; 
}

sub get_selected_volumes {

    my ($r, $k, $val, @cookies, $vol_prefs);
    my $c = OnSearch::AppConfig -> new;
    my %vols = $c -> Volumes;
    my @voldirs;

    if ($ENV{HTTP_COOKIE}) {
	@cookies = split /\;\s?/, $ENV{HTTP_COOKIE};
	($val) = grep (/onsearchvols/, @cookies);
	if ($val) {
	    ($val) = $val =~ /.*?\=(.*)/ if $val;
	    $vol_prefs = $c -> get_prefs ($val) if $val;
	}
	if (! $val) {
	    push @voldirs, ($vols{Default});
	} else {
	    my @preflist = split /,/, $vol_prefs;
	    foreach $k (keys %vols) {
		next unless scalar grep /$k/, @preflist;
		push @voldirs, ($vols{$k});
	    }
	}
    }
    return @voldirs;
}

1;

__END__

=head1 VERSION AND CREDITS

Written by Robert Kiesling <rkies@cpan.org> and licensed under the 
same terms as Perl.  Refer to the file, "Artistic," for information.

=head1 SEE ALSO

L<OnSearch(3)>

=cut



( run in 0.683 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )