/[webpac]/trunk2/lib/WebPAC/Index.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk2/lib/WebPAC/Index.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 410 by dpavlin, Sun Sep 5 21:40:57 2004 UTC revision 515 by dpavlin, Mon Oct 18 13:59:12 2004 UTC
# Line 4  use warnings; Line 4  use warnings;
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    
# Line 24  Create new sorted index object Line 23  Create new sorted index object
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    
# Line 42  sub new { Line 45  sub new {
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    
# Line 54  sub new { Line 57  sub new {
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
# Line 65  sub insert { Line 68  sub insert {
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    

Legend:
Removed from v.410  
changed lines
  Added in v.515

  ViewVC Help
Powered by ViewVC 1.1.26