[prev in list] [next in list] [prev in thread] [next in thread]
List: perl5-porters
Subject: Re: [PATCH] Re: [PATCH] File::Copy & permission bits.
From: Charles Bailey <bailey.charles () gmail ! com>
Date: 2009-01-29 3:24:43
Message-ID: b78749dd0901281924j6d02883ctcd6194abb9b893be () mail ! gmail ! com
[Download RAW message or body]
On Mon, Jan 26, 2009 at 4:51 AM, Aristotle Pagaltzis <pagaltzis@gmx.de> wrote:
> * Charles Bailey <bailey.charles@gmail.com> [2009-01-25 05:15]:
>> - Remove Scalar::Util. It looks possible to replace the
>> blessed() and overload() checks with something like
>> my $ra = ref $a; "$a" !~ /^$ra\(0x[0-9a-f]+\)$/
>> but I need to think it through a bit more and test it.
>
> `blessed` can be written `UNIVERSAL::can( $var, 'can' )`.
Sure, but we may not need to look at blessedness directly to figure
out what we need here: whether we need to let an object stringify
itself into something useful. I think the "internal" option below
will do the trick, letting us avoid loading overload.pm as well.
--
Regards,
Charles Bailey
Lists: bailey _dot_ charles _at_ gmail _dot_ com
Other: bailey _at_ newman _dot_ upenn _dot_ edu
#!/usr/local/bin/perl
use IO::File;
use IO::Scalar;
use Path::Class;
use Scalar::Util 'blessed';
use overload;
my $str = '/some/where/out/there';
my $sref = \$str;
my $iosc = IO::Scalar->new(\$str);
my $pc = dir(split /\//, $str);
my $fh = IO::File->new($0);
my $gr = \do { local *GLOB; };
open FH, $0;
sub with_modules {
Scalar::Util::blessed($_[0]) &&
overload::Method($_[0],q{""})
? 'stringified' : 'native';
}
sub internal {
ref($_[0]) &&
"$_[0]" !~ /^(?:[\w:]+=)?\w+\(0x[0-9a-f]+\)/
? 'stringified' : 'native';
}
for my $c ( [ 'Flat string', $str ],
[ 'Old-style file handle', FH ],
[ 'Scalar ref', $sref ],
[ 'Glob', $gr ],
[ 'IO::Scalar', $iosc ],
[ 'Path::Class', $pc ],
[ 'IO::File', $fh ],) {
my $mod = with_modules($c->[1]);
my $int = internal($c->[1]);
print "$c->[0] ($c->[1]): modules=$mod internal=$int ",
($mod eq $int ? 'consistent' : 'INCONSISTENT'),
"\n";
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic