David Cantrell > Tie-STDOUT-1.0401 > Tie::STDOUT

Download:
Tie-STDOUT-1.0401.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.0401   Source  

NAME ^

Tie::STDOUT - intercept writes to STDOUT and apply user-defined functions to them.

SYNOPSIS ^

    use Tie::STDOUT
        print => sub {
            print map { uc } @_;
        },
        printf => ... 
        syswrite => ... ;

DESCRIPTION ^

This module intercepts all writes to the STDOUT filehandle and applies whatever function you desire to what would have gone to STDOUT. In the example above, any use of the print() function on this filehandle will have its output transmogrified into upper case.

You will have noticed that we blithely print to the default filehandle (which is almost always STDOUT) in the function we supplied. Relax, this doesn't cause an infinite loop, because your functions are always called with a *normal* STDOUT.

You may provide up to three user-defined functions which are respectively called whenever you use print(), printf() or syswrite() on the filehandle:

print

defaults to printing to the real STDOUT;

printf

defaults to passing all parameters through sprintf() and then passing them to whatever the 'print' function is;

syswrite

Defaults to going straight through to the real STDOUT.

You will note that the default behaviour is exactly the same as it would be without this module.

Because we have a sensible default for 'printf' and because syswrite is so rarely used, you will normally only have to provide your own code for 'print'.

BUGS ^

Doesn't work on perl 5.6, because it seems that localising tied filehandles doesn't work.

SEE ALSO ^

Tie::STDERR
IO::Capture::Stdout

FEEDBACK ^

I like to know who's using my code. All comments, including constructive criticism, are welcome. Please email me.

AUTHOR ^

David Cantrell <david@cantrell.org.uk>

COPYRIGHT ^

Copyright 2006 David Cantrell

This module is free-as-in-speech software, and may be used, distributed, and modified under the same terms as Perl itself.

syntax highlighting: