/[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 19 by dpavlin, Sun Feb 18 12:51:26 2007 UTC revision 25 by dpavlin, Sun Feb 18 20:45:59 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    
47  };  };
48    
49  =head2 take_action  =head2 take_action
# Line 71  sub take_action { Line 78  sub take_action {
78                  Jifty->log->info("Fetching ", $feed->title, " at $uri");                  Jifty->log->info("Fetching ", $feed->title, " at $uri");
79          }          }
80    
81          my $xml_feed = XML::Feed->parse( URI->new($uri) )          my $ua = LWP::UserAgent->new;
82            $ua->default_header( 'Cookie' => $feed->cookie );
83            my $r = $ua->get( $uri );
84            die $feed->title . " returned " . $r->status_line . " for $uri\n" unless ( $r->is_success );
85    
86            my $content = $r->content;
87    
88            die "No content returned from $uri" unless length( $content ) > 1;
89    
90            my $xml_feed = XML::Feed->parse( \$content )
91                  or die $feed->title, " returned ", XML::Feed->errstr, " for $uri\n";                  or die $feed->title, " returned ", XML::Feed->errstr, " for $uri\n";
92    
93          warn "fetching ", $xml_feed->title, "\n";          warn "getting entries from ", $xml_feed->title, "\n";
94    
95          my @items;          my @items;
96    
# Line 93  sub take_action { Line 109  sub take_action {
109                          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,
110                  );                  );
111    
112                  die "can't create item from entry ", dump( $entry ) unless ( $i->id );                  if ( $i->id ) {
113                            push @items, $i;
114    
115                  push @items, $i;          #               Grep::Event::Result->new( $i )->publish;
116    
117  #               Grep::Event::Result->new( $i )->publish;                          Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) );
118                    } else {
119                            warn "can't create item from entry ", dump( $entry ) unless ( $i->id );
120                    }
121    
                 Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) );  
122          }          }
123    
124          if ( @items ) {          if ( @items ) {
# Line 113  sub take_action { Line 132  sub take_action {
132    
133          } else {          } else {
134    
135                  $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 );  
   
136                  return 0;                  return 0;
137    
138          }          }
139  }  }
140    

Legend:
Removed from v.19  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26