/[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

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

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

revision 9 by dpavlin, Sat Feb 17 23:32:33 2007 UTC revision 28 by dpavlin, Mon Feb 19 16:28:00 2007 UTC
# Line 11  package Grep::Action::Fetch; Line 11  package Grep::Action::Fetch;
11  use base qw/Grep::Action Jifty::Action/;  use base qw/Grep::Action Jifty::Action/;
12    
13  use XML::Feed;  use XML::Feed;
14    use LWP::UserAgent;
15    
16  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
17    
# Line 37  use Jifty::Action schema { Line 38  use Jifty::Action schema {
38                          }];                          }];
39                  };                  };
40    
41            param item_fragment =>
42                    label is 'Show',
43                    render as 'select',
44    #               valid are qw/result result_short/,
45    #               available are qw/result result_short/;
46                    available are qw/long short title/;
47    
48  };  };
49    
50  =head2 take_action  =head2 take_action
# Line 65  sub take_action { Line 73  sub take_action {
73    
74          my $uri = $feed->uri;          my $uri = $feed->uri;
75          if ($uri =~ m/%s/) {          if ($uri =~ m/%s/) {
76                  $uri = sprintf( $uri, $self->argument_value('q') );                  $uri = $feed->search_uri( $self->argument_value('q') );
77                  Jifty->log->info("Searching ", $feed->title, " at $uri");                  Jifty->log->info("Searching ", $feed->title, " at $uri");
78          } else {          } else {
79                  Jifty->log->info("Fetching ", $feed->title, " at $uri");                  Jifty->log->info("Fetching ", $feed->title, " at $uri");
80          }          }
81    
82          my $xml_feed = XML::Feed->parse( URI->new($uri) )          my $ua = LWP::UserAgent->new;
83                  or die XML::Feed->errstr;          $ua->default_header( 'Cookie' => $feed->cookie );
84            my $r = $ua->get( $uri );
85            die $feed->title . " returned " . $r->status_line . " for $uri\n" unless ( $r->is_success );
86    
87            my $content = $r->content;
88    
89            die "No content returned from $uri" unless length( $content ) > 1;
90    
91          warn "fetching ", $xml_feed->title, "\n";          my $xml_feed = XML::Feed->parse( \$content )
92                    or die $feed->title, " returned ", XML::Feed->errstr, " for $uri\n";
93    
94            warn "getting entries from ", $xml_feed->title, "\n";
95    
96          my @items;          my @items;
97    
# Line 93  sub take_action { Line 110  sub take_action {
110                          modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S %z") : undef,                          modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S %z") : undef,
111                  );                  );
112    
113                  die "can't create item from entry ", dump( $entry ) unless ( $i->id );                  if ( $i->id ) {
114                            push @items, $i;
115    
116                  push @items, $i;          #               Grep::Event::Result->new( $i )->publish;
117    
118  #               Grep::Event::Result->new( $i )->publish;                          Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) );
119                    } else {
120                            warn "can't create item from entry ", dump( $entry ) unless ( $i->id );
121                    }
122    
                 Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) );  
123          }          }
124    
125          if ( @items ) {          if ( @items ) {
# Line 113  sub take_action { Line 133  sub take_action {
133    
134          } else {          } else {
135    
136                  $self->result->message( 'No results found' );                  $self->result->error( 'No results found' );
   
                 # with default sticky_on_failure, this will keep form data  
                 $self->result->failure( 1 );  
   
137                  return 0;                  return 0;
138    
139          }          }
140  }  }
141    

Legend:
Removed from v.9  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26