From: Jakub Narebski Date: Wed, 06 Oct 2010 23:22:24 GMT Subject: Re: [PATCHv5 06/17] gitweb/lib - Simple select(FH) based output capture Message-ID: <201010070122.25355.jnareb@gmail.com> In-Reply-To: Thomas Adam wrote: > On 6 October 2010 23:01, Jakub Narebski 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