Changeset 793


Ignore:
Timestamp:
Jun 1, 2006, 3:33:55 PM (15 years ago)
Author:
nick
Message:

Remove some duplication, by having a helper method to return the built feed maker

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/Feed.pm

    r791 r793  
    6363    my $feed_listing = $args{feed_listing};
    6464   
    65     my %known_types = (
    66                           'rss'  => 1,
    67                           'atom' => 1,
    68                       );
    6965    my %known_listings = (
    7066                          'recent_changes' => 1,
     
    7268                         );
    7369                     
     70    croak "No feed listing specified" unless $feed_listing;
     71    croak "Unknown feed listing: $feed_listing" unless $known_listings{$feed_listing};
     72
     73    # Fetch the right Wiki::Toolkit::Feeds::Listing instance to use
     74    my $maker = $self->fetch_maker($feed_type);
     75
     76    # Call the appropriate feed listing from it
     77    if ($feed_listing eq 'recent_changes') {
     78        return $maker->recent_changes(%args);
     79    }
     80    elsif ($feed_listing eq 'node_all_versions') {
     81        return $maker->node_all_versions(%args);
     82    }
     83}
     84
     85=item B<fetch_maker>
     86For the given feed type, identify and return the maker routine for feeds
     87of that type.
     88
     89my $maker = $feed->fetch_maker("rss");
     90my $feed_contents = maker->node_all_versions(%options);
     91
     92Will always return something of type Wiki::Toolkit::Feed::Listing
     93=cut
     94sub fetch_maker {
     95    my ($self,$feed_type) = @_;
     96
     97    my %known_types = (
     98                          'rss'  => \&atom_maker,
     99                          'atom' => \&rss_maker,
     100                      );
     101
    74102    croak "No feed type specified" unless $feed_type;
    75103    croak "Unknown feed type: $feed_type" unless $known_types{$feed_type};
    76104
    77     croak "No feed listing specified" unless $feed_listing;
    78     croak "Unknown feed listing: $feed_listing" unless $known_listings{$feed_listing};
    79 
    80     if ($feed_type eq 'rss') {
    81         if ($feed_listing eq 'recent_changes') {
    82             return $self->rss_maker->recent_changes(%args);
    83         }
    84         elsif ($feed_listing eq 'node_all_versions') {
    85             return $self->rss_maker->node_all_versions(%args);
    86         }
    87     }
    88     elsif ($feed_type eq 'atom') {
    89         if ($feed_listing eq 'recent_changes') {
    90             return $self->atom_maker->recent_changes(%args);
    91         }
    92         elsif ($feed_listing eq 'node_all_versions') {
    93             return $self->atom_maker->node_all_versions(%args);
    94         }
    95     }
     105    return &{$known_types{$feed_type}};
    96106}
    97107
Note: See TracChangeset for help on using the changeset viewer.