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

Revision 1734 (checked in by miyagawa, 14 years ago)

added Test::Spelling and fixed typoes

Line 
1 package Plagger::Plugin::Subscription::Bookmarks;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use UNIVERSAL::require;
6
7 sub init {
8     my $self = shift;
9     $self->SUPER::init(@_);
10    
11     my $browser = $self->conf->{browser} || $self->auto_configure;
12     my $class = __PACKAGE__ . "::$browser";
13     $class->require or Plagger->context->error("Error loading $class: $@");
14    
15     bless $self, $class;
16 }
17
18 sub auto_configure {
19     my $self = shift;
20
21     my $path = $self->conf->{path};
22     if ($path) {
23         if (-d _ && $^O eq 'MSWin32') {
24             Plagger->context->log(debug => "$path is a directory. read as IE");
25             return "InternetExplorer";
26         } elsif ($path =~ /bookmarks\.html$/i) {
27             Plagger->context->log(debug => "$path is a Mozilla bookmarks");
28             return "Mozilla";
29         } elsif ($path =~ /Bookmarks\.plist$/) {
30             Plagger->context->log(debug => "$path is a Safari bookmarks");
31             return "Safari";
32         } else {
33             Plagger->context->error("Don't know Bookmark type of $path");
34         }
35     }
36    
37     # Hmm, no clue for path. Find it automatically ... only works for IE
38     if ($^O eq 'MSWin32') {
39         return "InternetExplorer";
40     } elsif ($^O eq 'darwin') {
41         return "Safari"; # xxx
42     } else {
43         return "Mozilla"; # xxx don't work because path is missing
44     }
45 }
46
47 sub register {
48     my($self, $context) = @_;
49     $context->register_hook(
50         $self,
51         'subscription.load' => $self->can('load'),
52     );
53 }
54
55 sub load { die "Override load" }
56
57 1;
58
59 __END__
60
61 =head1 NAME
62
63 Plagger::Plugin::Subscription::Bookmarks - Subscribe to URLs in Favorites / Bookmarks
64
65 =head1 SYNOPSIS
66
67   # DWIM: auto-detect browsers (and path) from your OS
68   - module: Subscription::Bookmarks
69  
70   # be a little explicit
71   - module: Subscription::Bookmarks
72     config:
73       browser: InternetExplorer
74
75   # auto-configure as Mozilla
76   - module: Subscription::Bookmarks
77     config:
78       path: /path/to/bookmarks.html
79
80   # auto-configure as Safari
81   - module: Subscription::Bookmarks
82     config:
83       path: /path/to/Bookmarks.plist
84
85   # more verbose
86   - module: Subscription::Bookmarks
87     config:
88       browser: Mozilla
89       path: /path/to/bookmarks.html
90
91 =head1 DESCRIPTION
92
93 This plugin allows you to subscribe to your Bookmarks (or Favorites) of your browser
94 like IE, Firefox or Safari.
95
96 =head1 CONFIGURATION
97
98 =over 4
99
100 =item browser
101
102 Specify your browser name. Possible values are 'InternetExplorer', 'Mozilla' and 'Safari'.
103
104 =item path
105
106 Specify path to your bookmarks file (or directory).
107
108 =back
109
110 Configuration is optional. When you omit I<browser>, this plugin auto-configure
111 the default config. On Win32, I<browser> is "InternetExplorer" and I<path> is looked up
112 using Windows Registry. On darwin, I<browser> is "Safari". Otherwise, I<browser> is set
113 to "Mozilla", but I<path> isn't set.
114
115 =head1 AUTHOR
116
117 Tatsuhiko Miyagawa
118
119 =head1 SEE ALSO
120
121 L<Plagger>, L<Netscape::Bookmarks>, L<Win32::IEFavorites>
Note: See TracBrowser for help on using the browser.