github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

dagolden / capture-tiny

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 4
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (8)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (8)
    • release-0.07
    • release-0.06
    • release-0.05_51
    • release-0.05
    • release-0.04
    • release-0.03
    • release-0.02
    • release-0.01
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

(Perl) Capture STDOUT and STDERR from Perl, XS or external programs — Read more

  cancel

http://search.cpan.org/dist/Capture-Tiny/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

update MANIFEST.SKIP 
David Golden (author)
Sat Jan 23 21:20:30 -0800 2010
commit  685372b50918827b8c3d2a9e68c6e26025cd29b9
tree    27694bcf38c2e3c536a65e09168d74eea44e1388
parent  6da33faa0ed63ddaa9739d90d5577e768736f9fd
capture-tiny /
name age
history
message
file .gitignore Sat Jan 23 13:13:32 -0800 2010 ignore MYMETA [David Golden]
file Build.PL Wed May 06 14:10:36 -0700 2009 For Win32, close suprocesses on EOF isntead of ... [David Golden]
file Changes Sat Jan 23 21:18:54 -0800 2010 timestamp Changes [David Golden]
file INSTALL Wed Feb 11 12:51:39 -0800 2009 import boilerplate [David Golden]
file LICENSE Loading commit data...
file MANIFEST Thu May 07 03:55:54 -0700 2009 bump version to 0.06; fix Changes & meta for re... [David Golden]
file MANIFEST.SKIP Sat Jan 23 21:20:30 -0800 2010 update MANIFEST.SKIP [David Golden]
file META.yml
file Makefile.PL Sat Jan 23 13:17:54 -0800 2010 bump version to 0.07 and note Changes [David Golden]
file README Sat Jan 23 13:59:31 -0800 2010 drop support for 5.8.0 [David Golden]
file Todo Thu Mar 19 18:52:55 -0700 2009 updated POD and todo [David Golden]
directory examples/ Fri Feb 13 20:22:03 -0800 2009 made example interactive [David Golden]
directory inc/ Wed Feb 11 12:51:39 -0800 2009 import boilerplate [David Golden]
directory lib/ Sat Jan 23 13:59:31 -0800 2010 drop support for 5.8.0 [David Golden]
directory t/ Sat Jan 23 13:59:31 -0800 2010 drop support for 5.8.0 [David Golden]
directory xt/
README
NAME
    Capture::Tiny - Capture STDOUT and STDERR from Perl, XS or external
    programs

VERSION
    This documentation describes version 0.07.

SYNOPSIS
         use Capture::Tiny qw/capture tee capture_merged tee_merged/;
 
         ($stdout, $stderr) = capture {
           # your code here
         };
 
         ($stdout, $stderr) = tee {
           # your code here
         };
 
         $merged = capture_merged {
           # your code here
         };
 
         $merged = tee_merged {
           # your code here
         };

DESCRIPTION
    Capture::Tiny provides a simple, portable way to capture anything sent
    to STDOUT or STDERR, regardless of whether it comes from Perl, from XS
    code or from an external program. Optionally, output can be teed so that
    it is captured while being passed through to the original handles. Yes,
    it even works on Windows. Stop guessing which of a dozen capturing
    modules to use in any particular situation and just use this one.

    This module was heavily inspired by IO::CaptureOutput, which provides
    similar functionality without the ability to tee output and with more
    complicated code and API.

USAGE
    The following functions are available. None are exported by default.

  capture
       ($stdout, $stderr) = capture \&code;
       $stdout = capture \&code;

    The `capture' function takes a code reference and returns what is sent
    to STDOUT and STDERR. In scalar context, it returns only STDOUT. If no
    output was received, returns an empty string. Regardless of context, all
    output is captured -- nothing is passed to the existing handles.

    It is prototyped to take a subroutine reference as an argument. Thus, it
    can be called in block form:

       ($stdout, $stderr) = capture {
         # your code here ...
       };

  capture_merged
       $merged = capture_merged \&code;

    The `capture_merged' function works just like `capture' except STDOUT
    and STDERR are merged. (Technically, STDERR is redirected to STDOUT
    before executing the function.) If no output was received, returns an
    empty string. As with `capture' it may be called in block form.

    Caution: STDOUT and STDERR output in the merged result are not
    guaranteed to be properly ordered due to buffering.

  tee
       ($stdout, $stderr) = tee \&code;
       $stdout = tee \&code;

    The `tee' function works just like `capture', except that output is
    captured as well as passed on to the original STDOUT and STDERR. As with
    `capture' it may be called in block form.

  tee_merged
       $merged = tee_merged \&code;

    The `tee_merged' function works just like `capture_merged' except that
    output is captured as well as passed on to STDOUT. As with `capture' it
    may be called in block form.

    Caution: STDOUT and STDERR output in the merged result are not
    guaranteed to be properly ordered due to buffering.

LIMITATIONS
  Portability
    Portability is a goal, not a guarantee. `tee' requires fork, except on
    Windows where `system(1, @cmd)' is used instead. Not tested on any
    particularly esoteric platforms yet.

  PerlIO layers
    Capture::Tiny does it's best to preserve PerlIO layers such as ':utf8'
    or ':crlf' when capturing. Layers should be applied to STDOUT or STDERR
    *before* the call to `capture' or `tee'.

  Closed STDIN, STDOUT or STDERR
    Capture::Tiny will work even if STDIN, STDOUT or STDERR have been
    previously closed. However, since they may be reopened to capture or tee
    output, any code within the captured block that depends on finding them
    closed will, of course, not find them to be closed. If they started
    closed, Capture::Tiny will reclose them again when the capture block
    finishes.

  Scalar filehandles and STDIN, STDOUT or STDERR
    If STDOUT or STDERR are reopened to scalar filehandles prior to the call
    to `capture' or `tee', then Capture::Tiny will override the output
    handle for the duration of the `capture' or `tee' call and then send
    captured output to the output handle after the capture is complete.
    (Requires Perl 5.8)

    Capture::Tiny attempts to preserve the semantics of STDIN opened to a
    scalar reference.

  Tied STDIN, STDOUT or STDERR
    If STDOUT or STDERR are tied prior to the call to `capture' or `tee',
    then Capture::Tiny will attempt to override the tie for the duration of
    the `capture' or `tee' call and then send captured output to the tied
    handle after the capture is complete. (Requires Perl 5.8)

    Capture::Tiny does not (yet) support resending utf8 encoded data to a
    tied STDOUT or STDERR handle. Characters will appear as bytes.

    Capture::Tiny attempts to preserve the semantics of tied STDIN, but
    capturing or teeing when STDIN is tied is currently broken on Windows.

  Modifiying STDIN, STDOUT or STDERR during a capture
    Attempting to modify STDIN, STDOUT or STDERR *during* `capture' or `tee'
    is almost certainly going to cause problems. Don't do that.

  No support for Perl 5.8.0
    It's just too buggy when it comes to layers and UTF8.

BUGS
    Please report any bugs or feature requests using the CPAN Request
    Tracker. Bugs can be submitted through the web interface at
    http://rt.cpan.org/Dist/Display.html?Queue=Capture-Tiny

    When submitting a bug or request, please include a test-file or a patch
    to an existing test-file that illustrates the bug or desired feature.

SEE ALSO
    This is a selection of CPAN modules that provide some sort of output
    capture, albeit with various limitations that make them appropriate only
    in particular circumstances. I'm probably missing some. The long list is
    provided to show why I felt Capture::Tiny was necessary.

    *   IO::Capture

    *   IO::Capture::Extended

    *   IO::CaptureOutput

    *   IPC::Capture

    *   IPC::Cmd

    *   IPC::Open2

    *   IPC::Open3

    *   IPC::Open3::Simple

    *   IPC::Open3::Utils

    *   IPC::Run

    *   IPC::Run::SafeHandles

    *   IPC::Run::Simple

    *   IPC::Run3

    *   IPC::System::Simple

    *   Tee

    *   IO::Tee

    *   File::Tee

    *   Filter::Handle

    *   Tie::STDERR

    *   Tie::STDOUT

    *   Test::Output

AUTHOR
    David A. Golden (DAGOLDEN)

COPYRIGHT AND LICENSE
    Copyright (c) 2009 by David A. Golden. All rights reserved.

    Licensed under Apache License, Version 2.0 (the "License"). You may not
    use this file except in compliance with the License. A copy of the
    License was distributed with this file or you may obtain a copy of the
    License from
    http:E<sol>E<sol>www.apache.orgE<sol>licensesE<sol>LICENSE-2.0

    Files produced as output though the use of this software, shall not be
    considered Derivative Works, but shall be considered the original work
    of the Licensor.

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server