1 |
use strict; |
2 |
use warnings; |
3 |
|
4 |
=head1 NAME |
5 |
|
6 |
Grep::Action::Search |
7 |
|
8 |
=cut |
9 |
|
10 |
package Grep::Action::Search; |
11 |
|
12 |
use Grep::Search; |
13 |
|
14 |
use Data::Dump qw/dump/; |
15 |
use Time::HiRes qw/time/; |
16 |
|
17 |
use Jifty::Param::Schema; |
18 |
use Jifty::Action schema { |
19 |
|
20 |
param q => |
21 |
type is 'text', |
22 |
label is 'Search for', |
23 |
hint is 'enter few words to search for'; |
24 |
|
25 |
param item_fragment => |
26 |
label is 'Show', |
27 |
render as 'select', |
28 |
available are qw/long short title/; |
29 |
|
30 |
}; |
31 |
|
32 |
=head2 take_action |
33 |
|
34 |
=cut |
35 |
|
36 |
sub take_action { |
37 |
my $self = shift; |
38 |
|
39 |
my $q = $self->argument_value('q') || warn "no q?"; |
40 |
|
41 |
my $coll = Grep::Search->collection( $q ); |
42 |
|
43 |
Jifty->log->error('result not collection but ', dump( $coll )) |
44 |
unless ( $coll->isa('Jifty::Collection') ); |
45 |
|
46 |
my $results = $coll->count; |
47 |
|
48 |
if ($results > 0) { |
49 |
$self->result->message( "Found $results results for '$q'" ); |
50 |
} else { |
51 |
$self->result->error('No local results, try remote feeds...'); |
52 |
} |
53 |
|
54 |
$self->result->content( search => $coll ); |
55 |
|
56 |
return $coll; |
57 |
} |
58 |
|
59 |
1; |
60 |
|