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"; }Thread Previous | Thread Next