develooper Front page | perl.perl5.porters | Postings from January 2003

Re: [PATCH] %open::modes to hold ${^OPEN} values for run-time access

Thread Previous
From:
Autrijus Tang
Date:
January 29, 2003 12:21
Subject:
Re: [PATCH] %open::modes to hold ${^OPEN} values for run-time access
Message ID:
20030129202121.GA3199@not.autrijus.org
On Wed, Jan 29, 2003 at 11:24:36PM +0800, Autrijus Tang wrote:
> On Wed, Jan 29, 2003 at 01:18:26PM +0100, Rafael Garcia-Suarez wrote:
> > If you (and others) find this snippet useful, I can release it
> > to CPAN. (I've *no idea* about a proper module name for it.)
> How about extenting it to other members than ->cop_io, and call it
> Devel::Hints?

And I did so promptly and put Devel::Hints 0.02 on CPAN, because this
 is needed in production today:

        use Devel::Hints ':all';

        LABEL:
        print cop_label();      # 'LABEL'

        print cop_seq();        # some integer

        $[ = 10;
        print cop_arybase();    # 10

        use open IO => ':utf8';
        print cop_io();         # same as compile-time ${^OPEN}

        {
            use IO => ':raw';
            print cop_io(1);    # access one uplevel; still ":utf8\0:utf8"
        }

This, combined with a padwalker-inspired trick:

    #define MYCOP ((count <= 0) ? PL_curcop \
				: cxstack[cxstack_ix - count + 1 ].blk_oldcop)

has enabled me to override CORE::GLOBAL::open() while respecting the caller's
${^OPEN} bits, and add it back with binmode().

A new version of PerlIO::via::trap should be released soon with this
capability.

Thanks,
/Autrijus/

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About