package PNSearch; use strict; use warnings FATAL => qw(all); use CGIutil; our $Log = "PNSearch.log"; $SIG{__WARN__} = \&logwarn; sub logwarn { CGIutil->logger($Log,shift) } sub new { # represents a note my $self = {}; (my $fname, $self->{terms}, my $ln, my $dbh) = (pop,pop,pop,pop); my $cur = 0; while (<$dbh>) { next unless (++$cur == $ln); $_ =~ s/^([^>]+?)<\|>(.*?)\((.*?)\)\s*<\|>//; if (!defined $1) { CGIutil->logger($Log, "No href defined: $fname\n$_\n\n"); return undef; } my $href = $1; if (!defined $2) { $self->{date} = "—"; $self->{title} = "[no title]"; } else { $self->{date} = $2; if (!defined $3) { $self->{title} = "[no title]" } else { $self->{title} = $3 }; } $self->{href} = ""; $self->{body} = $_; last; } bless($self); } sub hilight { (my $self, my $term) = (shift,shift); my @left = split /{body}; foreach (@left) { # @right halves each elem of @left my @right = split />/,$_; next if ($#right < 1); # no half = $right[1] =~ s/($term)/$1<\/em>/g; $_ = join(">",@right); } $self->{body} = join("<",@left); $self->{title} =~ s/($term)/$1<\/em>/g; } 1;