File Coverage

blib/lib/E2/Search.pm
Criterion Covered Total %
statement 15 38 39.4
branch 0 8 0.0
condition 0 11 0.0
subroutine 5 10 50.0
pod 2 2 100.0
total 22 69 31.8


line stmt bran cond sub pod time code
1             # E2::Search
2             # Jose M. Weeks
3             # 05 June 2003
4             #
5             # See bottom for pod documentation.
6              
7             package E2::Search;
8              
9 1     1   594 use 5.006;
  1         4  
  1         37  
10 1     1   6 use strict;
  1         1  
  1         30  
11 1     1   5 use warnings;
  1         2  
  1         31  
12 1     1   5 use Carp;
  1         2  
  1         66  
13              
14 1     1   5 use E2::Ticker;
  1         1  
  1         546  
15              
16             our $VERSION = "0.32";
17             our @ISA = qw(E2::Ticker);
18             our $DEBUG; *DEBUG = *E2::Interface::DEBUG;
19              
20             sub new {
21 0     0 1   my $arg = shift;
22 0   0       my $class = ref( $arg ) || $arg;
23 0           my $self = $class->SUPER::new();
24              
25 0           bless ($self, $class);
26              
27 0           return $self;
28             }
29              
30             sub search {
31 0 0   0 1   my $self = shift or croak "Usage: search E2SEARCH, KEYWORDS [, NODETYPE ] [, MAX_RESULTS ]";
32 0 0         my $keywords = shift or croak "Usage: search E2SEARCH, KEYWORDS [, NODETYPE ] [, MAX_RESULTS ]";
33 0   0       my $nodetype = shift || 'e2node';
34 0           my $max_results = shift;
35              
36 0           my @results;
37              
38 0 0         warn "E2::Search::search\n" if $DEBUG > 1;
39              
40 0           my %opt = (
41             keywords => $keywords,
42             nodetype => $nodetype
43             );
44            
45             my $handlers = {
46             'searchinfo/keywords' => sub {
47 0     0     (my $a, my $b) = @_;
48 0           $self->{keywords} = $b->text;
49             },
50             'searchinfo/search_nodetype' => sub {
51 0     0     (my $a, my $b) = @_;
52 0           $self->{searchtype} = $b->text;
53             },
54             'searchresults/e2link' => sub {
55 0     0     (my $a, my $b) = @_;
56 0 0 0       if( !$self->{max_results} ||
      0        
57             !$self->{results} ||
58             $self->{max_results} > @results ) {
59              
60 0           push @results, {
61             title => $b->text,
62             node_id =>$b->{att}->{node_id}
63             };
64             }
65             }
66 0           };
67              
68              
69 0           $self->{keywords} = undef;
70 0           $self->{searchtype} = undef;
71            
72 0           return $self->parse( 'search', $handlers, \@results, %opt );
73             }
74              
75             1;
76             __END__