/[Grep]/lib/Grep/Action/Fetch.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

Contents of /lib/Grep/Action/Fetch.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (show annotations)
Sun Mar 4 22:16:23 2007 UTC (17 years, 2 months ago) by dpavlin
File size: 2055 byte(s)
removed all debug warn(s) or move them to $self->log->debug
1 use strict;
2 use warnings;
3
4 =head1 NAME
5
6 Grep::Action::Fetch
7
8 =cut
9
10 package Grep::Action::Fetch;
11 use base qw/Grep::Action Jifty::Action/;
12
13 use XML::Feed;
14 use LWP::UserAgent;
15
16 use Grep::Search;
17 use Grep::Source;
18
19 use Data::Dump qw/dump/;
20
21 use Jifty::Param::Schema;
22 use Jifty::Action schema {
23
24 param q =>
25 type is 'text',
26 label is 'Search for',
27 hint is 'enter few words to search for';
28
29 param feed =>
30 label is 'From feed',
31 render as 'select',
32 available are defer {
33 my $feeds = Grep::Model::FeedCollection->new;
34 $feeds->order_by({ column => 'title', order => 'ASC' });
35 $feeds->unlimit;
36 #warn "feeds ", $feeds->build_select_query;
37 [{
38 display_from => 'title',
39 value_from => 'id',
40 collection => $feeds,
41 }];
42 };
43
44 param item_fragment =>
45 label is 'Show',
46 render as 'select',
47 # valid are qw/result result_short/,
48 # available are qw/result result_short/;
49 available are qw/long short title/;
50
51 };
52
53 =head2 take_action
54
55 Returns C<Grep::Model::ItemCollection> of fatched items from Feed which will
56 also be stored in local cache.
57
58 =cut
59
60 sub take_action {
61 my $self = shift;
62
63 # Custom action code
64
65 my $feed_id = $self->argument_value('feed') or die "no feed?";
66 my $q = $self->argument_value('q') or die "no q?";
67
68 my $feed = Grep::Model::Feed->new();
69 $feed->load_by_cols( id => $feed_id );
70 die "can't load feed ", $feed_id unless ($feed->id);
71
72 my $source = Grep::Source->new({ feed => $feed });
73 my $items = $source->search( $q );
74 my $new = $source->new_items;
75
76 if ( my $count = $items->count ) {
77
78 # construct a proper sentence :-)
79 my $message = $count
80 . ( $new == $count ? ' new' : '' )
81 . ( $new == 0 ? ' old' : '' )
82 . ' results '
83 . ( $new && $new < $count ? "of which $new new " : '' )
84 . "for '$q' in " . $source->feed->title;
85
86 $self->result->message( $message );
87
88 $self->result->content( items => $items );
89 $self->result->content( count => $items->count );
90
91 return $items;
92
93 } else {
94 return $self->result->error( "No results for '$q' in " . $feed->title );
95 }
96 }
97
98
99 1;
100

  ViewVC Help
Powered by ViewVC 1.1.26