karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I stumbled over this issue by chance.

As fare as i understand the docs of IO::All this snippet:

say for io($dir)->all;

is equivalent to this one:

my $io = IO::All->new(); $io->dir($dir); say for $io->all;

But please take a look at this:

#!/usr/bin/env perl use strict; use warnings; use IO::All; use Cwd; use feature qw(say); my $dir = cwd; say for io($dir)->all; my $io = IO::All->new(); $io->dir($dir); say for $io->all; __END__ karls-mac-mini:Desktop karl$ ./io.pl ...tons of stuff under /Users/karl/Desktop/ Can't use an undefined value as a subroutine reference at /Users/karl/ +perl5/perlbrew/perls/perl-5.20.0threads/lib/site_perl/5.20.0/IO/All/D +ir.pm line 167

The line referred to in Dir.pm is:

my $io = $self->constructor->(File::Spec->catfile($self->pathname, $na +me));

For the moment i don't understand the error message as well as the line referred to.

Is this a bug or do i miss something?

Thank you very much for any hint and best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re: Strange IO::All constructor behavior?
by karlgoethebier (Abbot) on Feb 19, 2015 at 08:04 UTC
    "... so I don't know if it should even work."

    According to the docs it should:

    "There are three ways to create a new IO::All object. The first is with the special function io which really just calls IO::All->new. The second is by calling new as a class method. The third is calling new as an object instance method. In this final case, the new objects attributes are copied from the instance object."
    io(file-descriptor); IO::All->new(file-descriptor); $io->new(file-descriptor);
    "If no file descriptor is provided, an object will still be created, but it must be defined by one of the following methods before it can be used for I/O:"
    io->file("path/to/my/file.txt");
    "Using the file method sets the type of the object to file and sets the pathname of the file if provided."
    io->dir($dir_name);
    "Make the object be of type directory."

    This works as described for file but not for dir - as described in the OP.

    I think, i should ask the author.

    Thank you and best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Re: Strange IO::All constructor behavior?
by Anonymous Monk on Feb 18, 2015 at 23:50 UTC
    The module is highly magical... I don't really understand it either but
    use strict; use warnings; use IO::All; use feature qw(say); my $io = io('/home/vic'); say *$io->{_constructor}; my $io2 = IO::All->new(); $io2->dir('/home/vic/'); say *$io2->{_constructor}; __END__ CODE(0x16de930) Use of uninitialized value in say at karl.pl line 14.
    Seems to me the $io2 lacks the field _constructor simply because nothing sets it... so I don't know if it should even work.