From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7093E1F92A for ; Sun, 5 Jul 2020 23:28:09 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 19/43] wwwatomstream: reuse $ctx as $self Date: Sun, 5 Jul 2020 23:27:35 +0000 Message-Id: <20200705232759.3161-20-e@yhbt.net> In-Reply-To: <20200705232759.3161-1-e@yhbt.net> References: <20200705232759.3161-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: No need to deepen our object graph, here. --- lib/PublicInbox/WwwAtomStream.pm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm index 35b536c1c..9f322d38f 100644 --- a/lib/PublicInbox/WwwAtomStream.pm +++ b/lib/PublicInbox/WwwAtomStream.pm @@ -22,15 +22,17 @@ sub close {} sub new { my ($class, $ctx, $cb) = @_; $ctx->{feed_base_url} = $ctx->{-inbox}->base_url($ctx->{env}); - bless { cb => $cb || \&close, ctx => $ctx, emit_header => 1 }, $class; + $ctx->{cb} = $cb || \&close; + $ctx->{emit_header} = 1; + bless $ctx, $class; } sub response { my ($class, $ctx, $code, $cb) = @_; my $h = [ 'Content-Type' => 'application/atom+xml' ]; - my $self = $class->new($ctx, $cb); - $self->{gzf} = gzf_maybe($h, $ctx->{env}); - [ $code, $h, $self ] + $class->new($ctx, $cb); + $ctx->{gzf} = gzf_maybe($h, $ctx->{env}); + [ $code, $h, $ctx ] } # called once for each message by PSGI server @@ -38,7 +40,7 @@ sub getline { my ($self) = @_; my $buf = do { if (my $middle = $self->{cb}) { - my $smsg = $middle->($self->{ctx}); + my $smsg = $middle->($self); feed_entry($self, $smsg) if $smsg; } } // (delete($self->{cb}) ? '' : undef); @@ -106,8 +108,7 @@ sub atom_header { # returns undef or string sub feed_entry { - my ($self, $smsg) = @_; - my $ctx = $self->{ctx}; + my ($ctx, $smsg) = @_; my $eml = $ctx->{-inbox}->smsg_eml($smsg) or return ''; my $hdr = $eml->header_obj; my $mid = $smsg->{mid}; @@ -136,7 +137,7 @@ sub feed_entry { $email = ascii_html($email); my $s = ''; - if (delete $self->{emit_header}) { + if (delete $ctx->{emit_header}) { $s .= atom_header($ctx, $title); } $s .= "$name$email" .