root/trunk/plagger/lib/Plagger/Plugin/Subscription/File.pm

Revision 1973 (checked in by miyagawa, 13 years ago)

support script:path in Subscription::File

Line 
1 package Plagger::Plugin::Subscription::File;
2
3 use strict;
4 use warnings;
5
6 use base qw(Plagger::Plugin);
7 use Plagger::Util;
8
9 use URI;
10
11 sub register {
12     my ( $self, $context ) = @_;
13
14     $context->register_hook( $self, 'subscription.load' => \&load );
15 }
16
17 sub load {
18     my ( $self, $context ) = @_;
19
20     my $uri = URI->new( $self->conf->{file} )
21       or $context->error("config 'file' is missing");
22
23     $uri->scheme('file') unless $uri->scheme;
24
25     my $output;
26     if ($uri->scheme eq 'script') {
27         my $script = $uri->opaque;
28         $script =~ s!^//!!;
29         $script = URI::Escape::uri_unescape($script);
30         $output = qx($script);
31         if ($?) {
32             $context->log(error => "Error happend while executing '$script': $?");
33             return;
34         }
35     } else {
36         $output = Plagger::Util::load_uri($uri);
37     }
38
39     for ( split /\n/, $output ) {
40         s/\#.*//;
41         next if /^\s*$/;
42         my $feed = Plagger::Feed->new;
43         $feed->url($_);
44         $context->subscription->add($feed);
45     }
46
47     return 1;
48 }
49
50 1;
51
52 =head1 NAME
53
54 Plagger::Plugin::Subscription::File - Store feed URLs in a file
55
56 =head1 SYNOPSIS
57
58   - module: Subscription::File
59     config:
60       file: feeds.txt
61
62 =head1 DESCRIPTION
63
64 This module subscribes to feed URLs from a file, where each line is one URL.
65 Lines that start with # are ignored.The URLs can also point to HTML files, in
66 which case feed autodiscovery will happen. The C<file> configuration key can
67 point to any URI supported. If a scheme is not specified, 'file' is assumed.
68
69 =head1 AUTHOR
70
71 Ilmari Vacklin <ilmari.vacklin@helsinki.fi>
72
73 =head1 SEE ALSO
74
75 L<Plagger>
76
77 =head1 LICENSE
78
79 This module is free software; you can redistribute it and/or modify it under
80 the same terms as Perl itself.
Note: See TracBrowser for help on using the browser.