Changeset 1828

Show
Ignore:
Timestamp:
11/10/06 19:12:02
Author:
miyagawa
Message:

CustomFeed?::Debug: allow 'entries' key. auto_set_type on enclosures. Update tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/Debug.pm

    r1473 r1828  
    2727    $feed->type('debug'); 
    2828    for (keys %{$self->conf}) { 
    29         next if $_ eq 'entry'
     29        next if $_ eq 'entry' || $_ eq 'entries'
    3030        $feed->$_($self->conf->{$_}); 
    3131    } 
    3232 
    33     for my $entry_conf (@{$self->conf->{entry}}) { 
     33    for my $entry_conf (@{ $self->conf->{entry} || $self->conf->{entries} || [] }) { 
    3434        my $entry = Plagger::Entry->new; 
    35         $entry->$_($entry_conf->{$_}) for keys %$entry_conf; 
     35        for my $method (keys %$entry_conf) { 
     36            next if $method eq 'enclosure'; 
     37            $entry->$method($entry_conf->{$method}); 
     38        } 
    3639        $feed->add_entry($entry); 
    3740 
    3841        # enclosure 
    39         for my $enclosure_conf ( @{ $entry_conf->{enclosure} } ){ 
     42        my $encls = $entry_conf->{enclosure} || []; 
     43           $encls = [ $encls ] if ref $encls && ref $encls ne 'ARRAY'; 
     44 
     45        for my $enclosure_conf ( @$encls ) { 
    4046            my $enclosure = Plagger::Enclosure->new; 
    4147            $enclosure->$_($enclosure_conf->{$_}) for keys %$enclosure_conf; 
     48            $enclosure->auto_set_type unless defined $enclosure->type; 
    4249            $entry->add_enclosure($enclosure); 
    4350        } 
  • trunk/plagger/t/plugins/CustomFeed-Debug/test.t

    r1434 r1828  
    3333ok $context->update->feeds->[0]->entries->[1]->link; 
    3434ok $context->update->feeds->[0]->entries->[1]->body; 
     35 
     36=== Enclosures 
     37--- input config 
     38plugins: 
     39  - module: CustomFeed::Debug 
     40    config: 
     41      title: 'My Feed' 
     42      link: 'http://localhost/' 
     43      entry: 
     44        - title: 'First Entry' 
     45          link: 'http://localhost/1' 
     46          body: 'Hello World! :)' 
     47          enclosure: 
     48            url: http://example.com/foo.mp3 
     49            length: 123 
     50            type: audio/mp3 
     51 
     52        - title: 'First Entry' 
     53          link: 'http://localhost/1' 
     54          body: 'Hello World! :)' 
     55          enclosure: 
     56            - url: http://example.com/foo.mp3 
     57              length: 123 
     58            - url: http://example.com/foo.m4a 
     59              length: 456 
     60--- expected 
     61is $context->update->feeds->[0]->link, 'http://localhost/'; 
     62is $context->update->feeds->[0]->title, 'My Feed'; 
     63{ 
     64    my @e = $context->update->feeds->[0]->entries->[0]->enclosures; 
     65    is @e, 1; 
     66    isa_ok $e[0]->url, 'URI'; 
     67    is $e[0]->url, 'http://example.com/foo.mp3'; 
     68    is $e[0]->type, 'audio/mp3'; 
     69    is $e[0]->length, 123; 
     70} 
     71{ 
     72    my @e = $context->update->feeds->[0]->entries->[1]->enclosures; 
     73    is @e, 2; 
     74    isa_ok $e[0]->url, 'URI'; 
     75    is $e[0]->url, 'http://example.com/foo.mp3'; 
     76    is $e[0]->type, 'audio/mpeg'; 
     77    is $e[0]->length, 123; 
     78    is $e[1]->url, 'http://example.com/foo.m4a'; 
     79    is $e[1]->type, 'audio/aac'; 
     80    is $e[1]->length, 456; 
     81} 
     82 
     83