I am trying to look into learning Moose and need to know how to properly deploy my class pm file.
What I mean is I created a Person.pm.
Can I call this in my main package if it is in the same folder as my main.pl script doing a use Person; or do I have to do a make and deploy it to my @INC perl modules location before being able to use the file?
I am hoping to create pm class files in my local folder and then simply call them with my program main.pl in that folder.
How would I go about doing this?
Perl does default to having .
as the first item in @INC
, so side-by-side will work. If you want to be a little more sophisticated, you can use FindBin
and use lib
:
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/lib";
# Main program continues...
Now put your modules in lib/
in the same directory as your script, and your script will see them. This keeps your library modules and your script(s) separated. If you're writing tests, you can have a t/
library with the test scripts starting like this:
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Test::More;
# other test modules, your plan, etc.
And your tests will look in the right place for the library modules as well.
You can also use PERL5OPT=-I/path/to/some/library
to add that path to your @INC
, and you then don't need use lib
at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With