| 1 | ########################################### | ||
| 2 | package Perldoc::Search; | ||
| 3 | ########################################### | ||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | our $VERSION = "0.01"; | ||
| 8 | |||
| 9 | 1 | ▶ | use Pod::Simple::TextContent; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 0 | ▶ | use SWISH::API::Common; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 11 | use Config; | ||
| 12 | use Cwd; | ||
| 13 | |||
| 14 | ########################################### | ||
| 15 | sub new { | ||
| 16 | ########################################### | ||
| 17 | my($class, %options) = @_; | ||
| 18 | |||
| 19 | my $self = { | ||
| 20 | dirs => [$Config{installsitearch}, | ||
| 21 | $Config{installsitelib}, | ||
| 22 | $Config{installarchlib}, | ||
| 23 | $Config{installprivlib}, | ||
| 24 | ], | ||
| 25 | swish_options => { | ||
| 26 | swish_adm_dir => "$ENV{HOME}/.perldig", | ||
| 27 | }, | ||
| 28 | %options, | ||
| 29 | }; | ||
| 30 | |||
| 31 | # If the perl lib dir is symlinked, this | ||
| 32 | # will figure out the real paths | ||
| 33 | for(@{$self->{dirs}}) { | ||
| 34 | my $cwd = cwd(); | ||
| 35 | chdir $_ or die "Cannot cwd to $_"; | ||
| 36 | $_ = File::Spec->rel2abs("."); | ||
| 37 | chdir $cwd; | ||
| 38 | } | ||
| 39 | |||
| 40 | $self->{swish} = SWISH::API::Common->new( | ||
| 41 | %{$self->{swish_options}} | ||
| 42 | ); | ||
| 43 | |||
| 44 | bless $self, $class; | ||
| 45 | } | ||
| 46 | |||
| 47 | ########################################### | ||
| 48 | sub relative { | ||
| 49 | ########################################### | ||
| 50 | my($self, $path) = @_; | ||
| 51 | |||
| 52 | $path =~ s|^$_/|| for @{$self->{dirs}}; | ||
| 53 | return $path; | ||
| 54 | } | ||
| 55 | |||
| 56 | ########################################### | ||
| 57 | sub update { | ||
| 58 | ########################################### | ||
| 59 | my($self) = @_; | ||
| 60 | |||
| 61 | # Index all files in a directory and its subdirectories | ||
| 62 | $self->{swish}->index(@{$self->{dirs}}); | ||
| 63 | } | ||
| 64 | |||
| 65 | ########################################### | ||
| 66 | sub search { | ||
| 67 | ########################################### | ||
| 68 | my($self, @terms) = @_; | ||
| 69 | |||
| 70 | return $self->{swish}->search(@terms); | ||
| 71 | } | ||
| 72 | |||
| 73 | 1; | ||
| 74 | |||
| 75 | __END__ | ||