Changeset 1621

Show
Ignore:
Timestamp:
08/29/06 02:11:44
Author:
miyagawa
Message:

Plugins refactorthon:

  • Switched from copy-and-pasted gen_filename() function to Plagger::Util::filename_for() in Publish:: plugins
  • Moved 'publish.entry.fixup' hooks to 'publish.entry' in some Notify/Publish plugins
  • Moved 'publish.init' to 'plugin.init' if it makes sense
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Notify/Audio.pm

    r1406 r1621  
    2222    $context->register_hook( 
    2323        $self, 
    24         'publish.entry.fixup' => \&update, 
     24        'publish.entry' => \&update, 
    2525        'publish.finalize' => \&finalize, 
    2626    ); 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Publish/CSV.pm

    r304 r1621  
    2828    } 
    2929 
    30     my $file = $self->gen_filename($args->{feed}) || $args->{feed}->id . ".csv"
     30    my $file = Plagger::Util::filename_for($args->{feed}, $self->conf->{filename} || "%i.csv")
    3131    my $path = File::Spec->catfile($dir, $file); 
    3232    my $io = IO::File->new($append  ? ">> $path" : "> $path"); 
     
    5353    utf8::decode($str) unless utf8::is_utf8($str); 
    5454    return encode($self->conf->{encoding} || 'utf8', $str); 
    55 } 
    56  
    57 my %formats = ( 
    58     'u' => sub { my $s = $_[0]->url;  $s =~ s!^https?://!!; $s }, 
    59     'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s }, 
    60     't' => sub { $_[0]->title }, 
    61     'i' => sub { $_[0]->id }, 
    62 ); 
    63  
    64 my $format_re = qr/%(u|l|t|i)/; 
    65  
    66 sub gen_filename { 
    67     my($self, $feed) = @_; 
    68  
    69     my $file = $self->conf->{filename} || ''; 
    70     $file =~ s{$format_re}{ 
    71         $self->safe_filename($formats{$1}->($feed)) 
    72     }egx; 
    73  
    74     $file; 
    75 } 
    76  
    77 sub safe_filename { 
    78     my($self, $path) = @_; 
    79     $path =~ s![^\w\s]+!_!g; 
    80     $path =~ s!\s+!_!g; 
    81     $path; 
    8255} 
    8356 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Publish/Delicious.pm

    r647 r1621  
    1010    $context->register_hook( 
    1111        $self, 
    12         'publish.init'        => \&initialize, 
    13         'publish.entry.fixup' => \&add_entry, 
     12        'plugin.init'   => \&initialize, 
     13        'publish.entry' => \&add_entry, 
    1414    ); 
    1515} 
     16 
     17sub rule_hook { 'publish.entry' } 
    1618 
    1719sub initialize { 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Publish/Feed.pm

    r1236 r1621  
    107107 
    108108    # generate file path 
    109     my $filepath = File::Spec->catfile($self->conf->{dir}, $self->gen_filename($f)); 
     109    my $tmpl = '%i.' . ($feed_format eq 'RSS' ? 'rss' : 'atom'); 
     110    my $file = Plagger::Util::filename_for($f, $self->conf->{filename} || $tmpl); 
     111    my $filepath = File::Spec->catfile($self->conf->{dir}, $file); 
    110112 
    111113    $context->log(info => "save feed for " . $f->link . " to $filepath"); 
     
    116118    print $output $xml; 
    117119    close $output; 
    118 } 
    119  
    120 my %formats = ( 
    121     'u' => sub { my $s = $_[0]->url;  $s =~ s!^https?://!!; $s }, 
    122     'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s }, 
    123     't' => sub { $_[0]->title }, 
    124     'i' => sub { $_[0]->id }, 
    125 ); 
    126  
    127 my $format_re = qr/%(u|l|t|i)/; 
    128  
    129 sub gen_filename { 
    130     my($self, $feed) = @_; 
    131  
    132     my $file = $self->conf->{filename} || 
    133         '%i.' . ($self->conf->{format} eq 'RSS' ? 'rss' : 'atom'); 
    134     $file =~ s{$format_re}{ 
    135         $self->safe_filename($formats{$1}->($feed)) 
    136     }egx; 
    137     $file; 
    138 } 
    139  
    140 sub safe_filename { 
    141     my($self, $path) = @_; 
    142     $path =~ s![^\w\s]+!_!g; 
    143     $path =~ s!\s+!_!g; 
    144     $path; 
    145120} 
    146121 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Publish/HatenaBookmark.pm

    r746 r1621  
    1212    $context->register_hook( 
    1313        $self, 
    14         'publish.init'        => \&initialize, 
    15         'publish.entry.fixup' => \&add_entry, 
     14        'plugin.init'   => \&initialize, 
     15        'publish.entry' => \&add_entry, 
    1616    ); 
    1717} 
    1818 
    19 sub rule_hook { 'publish.entry.fixup' } 
     19sub rule_hook { 'publish.entry' } 
    2020 
    2121sub initialize { 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Publish/IMAP.pm

    r1173 r1621  
    1717    $context->register_hook( 
    1818      $self, 
    19       'publish.init' => \&initialize, 
    20       'publish.entry.fixup' => \&store_entry, 
     19      'plugin.init' => \&initialize, 
     20      'publish.entry' => \&store_entry, 
    2121      'publish.finalize' => \&finalize, 
    2222    ); 
    2323} 
     24 
     25sub rule_hook { 'publish.entry' } 
    2426 
    2527sub initialize { 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Publish/JavaScript.pm

    r1173 r1621  
    2727    my($self, $context, $args) = @_; 
    2828 
    29     my $file = $self->gen_filename($args->{feed}, $self->conf->{filename} || '%i.js'); 
     29    my $file = Plagger::Util::filename_for($args->{feed}, $self->conf->{filename} || '%i.js'); 
    3030    my $path = File::Spec->catfile($self->conf->{dir}, $file); 
    3131    $context->log(info => "writing output to $path"); 
     
    3636    print $out $body; 
    3737    close $out; 
    38 } 
    39  
    40 my %formats = ( 
    41     'u' => sub { my $s = $_[0]->url;  $s =~ s!^https?://!!; $s }, 
    42     'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s }, 
    43     't' => sub { $_[0]->title }, 
    44     'i' => sub { $_[0]->id }, 
    45 ); 
    46  
    47 my $format_re = qr/%(u|l|t|i)/; 
    48  
    49 sub gen_filename { 
    50     my($self, $feed, $file) = @_; 
    51  
    52     $file =~ s{$format_re}{ 
    53         $self->safe_filename($formats{$1}->($feed)) 
    54     }egx; 
    55  
    56     $file; 
    57 } 
    58  
    59 sub safe_filename { 
    60     my($self, $path) = @_; 
    61     $path =~ s![^\w\s]+!_!g; 
    62     $path =~ s!\s+!_!g; 
    63     $path; 
    6438} 
    6539 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Publish/LivedoorClip.pm

    r1081 r1621  
    1212    $context->register_hook( 
    1313        $self, 
    14         'publish.entry.fixup' => \&add_entry, 
    15         'publish.init'        => \&initialize, 
     14        'publish.entry' => \&add_entry, 
     15        'publish.init'  => \&initialize, 
    1616    ); 
    1717} 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Publish/Maildir.pm

    r1173 r1621  
    1212use File::Find; 
    1313 
    14 our $VERSION = '0.3'; 
    15  
    1614sub register { 
    1715    my($self, $context) = @_; 
    1816    $context->register_hook( 
    1917      $self, 
    20       'publish.init' => \&initialize, 
    21       'publish.entry.fixup' => \&store_entry, 
    22       'publish.finalize' => \&finalize, 
     18      'plugin.init'  => \&initialize, 
     19      'publish.entry' => \&store_entry, 
     20      'publish.finalize' => \&finalize, 
    2321    ); 
    2422} 
     23 
     24sub rule_hook { 'publish.entry' } 
    2525 
    2626sub initialize { 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Publish/PowerPoint.pm

    r1432 r1621  
    1212    $context->register_hook( 
    1313        $self, 
    14         'publish.init' => \&connect_powerpoint, 
    1514        'publish.feed' => \&publish_presentation, 
     15        'publish.init'  => \&connect_powerpoint, 
    1616    ); 
    1717} 
     
    4545    # generate file path; 
    4646    my $file = File::Spec->catfile( 
    47         $self->conf->{dir}, $self->gen_filename($feed) 
     47        $self->conf->{dir}, Plagger::Util::filename_for($feed, $self->conf->{filename} || '%i.pps'), 
    4848    ); 
    4949 
     
    6565    $context->log(debug => "hello, PowerPoint"); 
    6666    $self->{powerpoint} = Win32::PowerPoint->new; 
    67 } 
    68  
    69 # stolen from ::Publish::Feed 
    70  
    71 my %formats = ( 
    72     'u' => sub { my $s = $_[0]->url;  $s =~ s!^https?://!!; $s }, 
    73     'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s }, 
    74     't' => sub { $_[0]->title }, 
    75     'i' => sub { $_[0]->id }, 
    76 ); 
    77  
    78 my $format_re = qr/%(u|l|t|i)/; 
    79  
    80 sub gen_filename { 
    81     my($self, $feed) = @_; 
    82  
    83     my $file = $self->conf->{filename} || '%i.pps'; 
    84     $file =~ s{$format_re}{ 
    85         $self->safe_filename($formats{$1}->($feed)) 
    86     }egx; 
    87     $file; 
    88 } 
    89  
    90 sub safe_filename { 
    91     my($self, $path) = @_; 
    92     $path =~ s![^\w\s]+!_!g; 
    93     $path =~ s!\s+!_!g; 
    94     $path; 
    9567} 
    9668