thank you all. i have a much better grasp on what this means now. at least i
know why i had trouble with it - i didn't (don't) understand closures. and,
i am not used to event driven programming. the example comes from psgi which
(generally) gets an event and gives you data. i've also been looking into
anyevent (following the rabbit hole) to try to figure out event programming
better. however, i see now that i need to take a few steps back and
understand closures first.

if i understand what everyone here has said and what i've been reading, he
needs to keep $s in scope with the first closure (i suppose to keep the
place of the file handle), and then uses $writer to get that string.

so, i'd access that by doing
my $appfunc = $app;
my $fhsub = $appfunc;
my $writer = fhsub( $thing_to_pass_shift );
print $writer;

now, i'm not too far to reading (so maybe this is a stupid question, but) he
shifts $_[ 0 ]; into that last closure. what happens to that value? why not
just:
return sub{ [ 200, [ "Content-type" => "text/plain" ], $s ] };


ps - i still feel like a beginner :)

reference:
my $s = Streamer->new;
my $app = sub {
   return sub {
      $s->open_fh;
      my $writer = shift->(
         [ 200, [ "Content-type" => "text/plain" ], $s ]
      );
   };
};

Reply via email to