]> Sergey Matveev's repositories - public-inbox.git/commitdiff
feed: generate takes a hashref for args
authorEric Wong <e@80x24.org>
Mon, 7 Apr 2014 20:26:42 +0000 (20:26 +0000)
committerEric Wong <e@80x24.org>
Mon, 7 Apr 2014 20:26:42 +0000 (20:26 +0000)
Passing a giant argument list is to error prone and
hard-to-document.

lib/PublicInbox/Feed.pm
public-inbox-cgi
t/feed.t

index e282dc740d42bc63d11b5b034a9537b9c556aa05..3ac771747b7ef077ac291e1cbae4f0600b8c5126 100644 (file)
@@ -16,13 +16,13 @@ use constant DATEFMT => '%Y-%m-%dT%H:%M:%SZ';
 use PublicInbox::View;
 
 # main function
-# FIXME: takes too many args, cleanup
 sub generate {
-       my ($class, $git_dir, $max, $pi_config, $listname, $cgi, $top) = @_;
-       $max ||= 25;
+       my ($class, $args) = @_;
+       my $max = $args->{max} || 25;
+       my $top = $args->{top}; # bool
 
-       local $ENV{GIT_DIR} = $git_dir;
-       my $feed_opts = get_feedopts($pi_config, $listname, $cgi);
+       local $ENV{GIT_DIR} = $args->{git_dir};
+       my $feed_opts = get_feedopts($args);
 
        my $feed = XML::Atom::SimpleFeed->new(
                title => $feed_opts->{description} || "unnamed feed",
@@ -63,8 +63,12 @@ sub generate {
 
 # private functions below
 sub get_feedopts {
-       my ($pi_config, $listname, $cgi) = @_;
+       my ($args) = @_;
+       my $pi_config = $args->{pi_config};
+       my $listname = $args->{listname};
+       my $cgi = $args->{cgi};
        my %rv;
+
        if ($pi_config && defined $listname && length $listname) {
                foreach my $key (qw(description address)) {
                        $rv{$key} = $pi_config->get($listname, $key);
index cfcf3feb5da4e0d43b9c638bc9404597d96e4d68..ccfaae3789d1f0322c86f24b3aaf25d44f07c7be 100755 (executable)
@@ -73,8 +73,12 @@ sub get_atom_all {
        print $cgi->header(-type => "application/xml", -charset => 'us-ascii',
                                -status => '200 OK');
 
-       print PublicInbox::Feed->generate($git_dir, undef,
-                                       $pi_config, $listname, $cgi);
+       print PublicInbox::Feed->generate({
+               git_dir => $git_dir,
+               pi_config => $pi_config,
+               listname => $listname,
+               cgi => $cgi
+       });
 }
 
 # /$LISTNAME/index.atom.xml    -> Atom feed
@@ -86,7 +90,11 @@ sub get_atom_index {
        require PublicInbox::Feed;
        print $cgi->header(-type => "application/xml", -charset => 'us-ascii',
                                -status => '200 OK');
-
-       print PublicInbox::Feed->generate($git_dir, undef,
-                                       $pi_config, $listname, $cgi, 1);
+       print PublicInbox::Feed->generate({
+               git_dir => $git_dir,
+               pi_config => $pi_config,
+               listname => $listname,
+               cgi => $cgi,
+               top => 1
+       });
 }
index baa99fee38a99cb873d9c2210637b25d2650d492..63fcc443143f1f40e7e5463f5181da495c8fbc85 100644 (file)
--- a/t/feed.t
+++ b/t/feed.t
@@ -44,7 +44,10 @@ EOF
 
        # check initial feed
        {
-               my $feed = PublicInbox::Feed->generate($git_dir, 3);
+               my $feed = PublicInbox::Feed->generate({
+                       git_dir => $git_dir,
+                       max => 3
+               });
                if ($have_xml_feed) {
                        my $p = XML::Feed->parse(\$feed);
                        is($p->format, "Atom", "parsed atom feed");
@@ -78,7 +81,10 @@ EOF
 
        # check spam shows up
        {
-               my $spammy_feed = PublicInbox::Feed->generate($git_dir, 3);
+               my $spammy_feed = PublicInbox::Feed->generate({
+                       git_dir => $git_dir,
+                       max => 3
+               });
                if ($have_xml_feed) {
                        my $p = XML::Feed->parse(\$spammy_feed);
                        is($p->format, "Atom", "parsed atom feed");
@@ -100,7 +106,10 @@ EOF
 
        # spam no longer shows up
        {
-               my $feed = PublicInbox::Feed->generate($git_dir, 3);
+               my $feed = PublicInbox::Feed->generate({
+                       git_dir => $git_dir,
+                       max => 3
+               });
                if ($have_xml_feed) {
                        my $p = XML::Feed->parse(\$feed);
                        is($p->format, "Atom", "parsed atom feed");