Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Moose - How do I deploy my class pm file?

Tags:

perl

moose

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?

like image 387
dell1074 Avatar asked Dec 28 '22 17:12

dell1074


1 Answers

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.

like image 168
Joe McMahon Avatar answered Jan 12 '23 10:01

Joe McMahon