4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Carp; |
use Carp; |
7 |
use Tie::Array::Sorted; |
use Tie::Array::Sorted::Lazy; |
8 |
use Log::Log4perl qw(get_logger :levels); |
use Log::Log4perl qw(get_logger :levels); |
|
use locale; |
|
9 |
|
|
10 |
=head1 NAME |
=head1 NAME |
11 |
|
|
23 |
|
|
24 |
my $thes = new WebPAC::Index( |
my $thes = new WebPAC::Index( |
25 |
log => 'log4perl.conf', |
log => 'log4perl.conf', |
26 |
|
name => 'index name', |
27 |
); |
); |
28 |
|
|
29 |
C<log> is optional parametar which specify filename of L<Log::Log4Perl> |
C<log> is optional parametar which specify filename of L<Log::Log4Perl> |
30 |
config file. Default is C<log.conf>. |
config file. Default is C<log.conf>. |
31 |
|
|
32 |
|
C<name> is optional parametar used to mark lines in log file with index |
33 |
|
name. |
34 |
|
|
35 |
Default sort function is my C<headline>, non case sensitive. It can't be |
Default sort function is my C<headline>, non case sensitive. It can't be |
36 |
changed right now without editing of source. |
changed right now without editing of source. |
37 |
|
|
45 |
my $log_file = $self->{'log'} || "log.conf"; |
my $log_file = $self->{'log'} || "log.conf"; |
46 |
Log::Log4perl->init($log_file); |
Log::Log4perl->init($log_file); |
47 |
|
|
48 |
tie @{$self->{'index'}}, "Tie::Array::Sorted", sub { |
tie @{$self->{'index'}}, "Tie::Array::Sorted::Lazy", sub { |
49 |
lc( $_[0]->{'headline'} ) cmp lc( $_[1]->{'headline'} ) |
lc( $_[0]->{'headline'} ) cmp lc( $_[1]->{'headline'} ) |
50 |
}; |
}; |
51 |
|
|
57 |
Insert data into index |
Insert data into index |
58 |
|
|
59 |
$index->insert( |
$index->insert( |
|
path => 'path', |
|
60 |
headline => 'headline text', |
headline => 'headline text', |
61 |
|
mfn => '99', |
62 |
); |
); |
63 |
|
|
64 |
=cut |
=cut |
68 |
|
|
69 |
my $data = {@_}; |
my $data = {@_}; |
70 |
|
|
|
confess("need path and headline!") unless (defined($data->{'path'}) && defined($data->{'headline'})); |
|
|
|
|
71 |
my $log = $self->_get_logger(); |
my $log = $self->_get_logger(); |
72 |
|
|
73 |
|
$log->logconfess("need headline and mfn!") unless (defined($data->{'headline'}) && defined($data->{'mfn'})); |
74 |
|
|
75 |
push @{$self->{'index'}}, $data; |
push @{$self->{'index'}}, $data; |
76 |
|
|
77 |
$log->debug("stored path: ",$data->{'path'}," headline: ",$data->{'headline'}); |
my $name = ''; |
78 |
|
$name = $self->{'name'}." " if ($self->{'name'}); |
79 |
|
|
80 |
|
$log->debug("stored ",$name,$data->{'mfn'},": ",$data->{'headline'}); |
81 |
|
|
82 |
} |
} |
83 |
|
|