Subject: Re: [PATCHv5 06/17] gitweb/lib - Simple select(FH) based output capture

From: Jakub Narebski <[email-masked]>
Date: Thu, 7 Oct 2010 01:22:24 +0200

Thomas Adam wrote:
> On 6 October 2010 23:01, Jakub Narebski <[email-masked]> wrote:

> > +sub capture {
> > +       my ($self, $code) = @_;
> > +
> > +       $self->start();
> > +       $code->();
> 
> unless( defined $code and ref($code) eq 'CODE' )
> {
>        # Error?
>         ....
> }

But what to do if $code is *not* a code reference?  Well, except perhaps
providing better error message...

> > +       return $self->stop();
> > +}
> > +
> > +# Wrap caching data; capture only STDOUT
> > +sub capture_block (&) {
> 
> This is prototyped deliberately?

Yes, it is prototyped deliberately to be able to use it like this

  my $data = capture_block {
     ...
  }

similarly to the API used by Capture::Tiny (which is not in core, which
captures also STDERR, and which do not provide capture_stop() equivalent
for die_error to be not captured and cached).

Only to explicitely discard prototype with '&capture_block($code)', when
using it in ->cache_output_* methods in GitwebCache::CacheOutput ;-)

-- 
Jakub Narebski
Poland