in reply to Re^2: IO::Handle UNIVERSAL::can STDOUT print
in thread IO::Handle UNIVERSAL::can STDOUT print

What about it?
  • Comment on Re^3: IO::Handle UNIVERSAL::can STDOUT print

Replies are listed 'Best First'.
Re^4: IO::Handle UNIVERSAL::can STDOUT print
by Anonymous Monk on Sep 04, 2009 at 06:28 UTC
    print works, but can('print') returns undef

      IO::Handle::can is called with *STDOUT as the first argument just like IO::Handle::print is called with *STDOUT as the first argument. Seeing as *STDOUT isn't an object, can returns false as documented.

      It wouldn't hurt for IO::Handle to override can to handle this better, though.

        Suggested change:
        { package IO::Handle; use strict; use warnings; use Scalar::Util qw( ); sub can { my $self = shift; $self = 'IO::Handle' if !Scalar::Util::blessed($self); return $self->SUPER::can(@_); } } use strict; use warnings; $\="\n"; print "\\*STDOUT: ", \*STDOUT; print "*STDOUT: ", *STDOUT; print "*STDOUT{IO}: ", *STDOUT{IO}; print ''; for (1..2) { print "\\*STDOUT: ", (\*STDOUT) ->can('print') ||0; print "*STDOUT: ", *STDOUT ->can('print') ||0; print "*STDOUT{IO}: ", *STDOUT{IO} ->can('print') ||0; print ''; require IO::Handle; }
        \*STDOUT: GLOB(0x182a044) *STDOUT: *main::STDOUT *STDOUT{IO}: IO::Handle=IO(0x182a054) \*STDOUT: 0 *STDOUT: 0 *STDOUT{IO}: 0 \*STDOUT: CODE(0x189cb0c) *STDOUT: CODE(0x189cb0c) *STDOUT{IO}: CODE(0x189cb0c)