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