Search code examples
perlherokubuildpack

How do I use a custom module in my Heroku / Perl web application?


I have seen that post about a similar question, but the replies did not allow me to understand the process. AFAIK, Perl is not a compiled language. It does not make sense I would have to put all my code into a single app file... OK, I also must confess I am not a Heroku buildpack expert.

My issue is really simple: I have coded a Mojolicious application, my Perloku setup is working well, I am happy except I do not understand how to package my own Perl module into my app. And I can't trust there is no way of achieving this.

Could anyone give me advice about what I should do?


Solution

  • I use Heroku, Perloku and Mojolicious for my personal website. I have a couple very basic modules I wrote to connect to the database and run single query.

    I use the full size Mojolicious App. I put all my .pm files in the lib directory. Then in my Mojolicious app file lib/NJEApp.pm:

    use lib 'lib';
    use Projects; # This is a basic module that runs a single database query. 
    

    In the script/StartApp.pl. This file is called by the Perloku file in the top level directory.

    use strict;
    use warnings;
    
    use FindBin;
    use lib "$FindBin::Bin/../lib";
    use Mojolicious::Commands;
    
    #~ Start the Commands for the Application
    Mojolicious::Commands->start_app('NJEApp');
    

    For external modules, you can put them in the Makefile.PL in the PREREQ_PM = {} section