I have been scratching my head for about an hour for trying to get a .pm to work as a module for me.
My issue is quite simple.
The story:
- I have made a package and used Moose for OOP.
- I have saved the package, My::FileIO in the home directory under a common dir for all such custom modules in the form /home/USER/DIRECTORY/My/FileIO.pm. In fact, this was done after I used Module::Starter and used
perl Makefile.PL
which installed it in that format. - I used an external script to test the module. In that, I used
use lib '/home/USER/DIRECTORY/'
and then confirmed the presence of the module by checking%INC
which yielded the correct filename value. This led me to conclude that perl had loaded the module without any complaints. - I tried to use this module by
My::FileIO
and the testing script had not complained at that time as well. - The testing script failed after I used the constructor in the Moose way,
my $test = My::FileIO->new()
and this is what it threw -Can't locate object method "new" via package "My::FileIO" (perhaps you forgot to load "My::FileIO"?) at line 1.
- I tried to make a mock subroutine named
init
and it failed too. - The author of Perl Maven however succeeds using these codes (https://perlmaven.com/object-oriented-perl-using-moose)
His testing script
use strict;
use warnings;
use v5.10;
use Person;
my $teacher = Person->new( name => 'Joe' );
say $teacher->name;
His test module
package Person;
use Moose;
has 'name' => (is => 'rw');
1;
Summary:
- The testing script is able to load the module successfuly.
- I am not able to use the package at all.
This is the assumed FileIO.pm
package My::FileIO;
use feature 'state';
use List::Util qw(max);
use Data::Dumper;
use Moose;
use Type::Params qw(compile);
use Type::Utils;
use Types::Standard qw(Str FileHandle Int HashRef ArrayRef Maybe);
[ ALL THE CODE ]
1;
Full code is at https://pastebin.com/1kxiPazd
This is my testing file - test.pl
use lib '/home/USER/DIRECTORY';
use My::FileIO;
$test = My::FileIO->new() # Fails
What am I doing wrong? I made a mock module like Perl Maven's and tried testing it and it failed too.
Update - I apologize for the silly errors in my writeup.