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

I am writing a little website with Mojolicious::Lite (highly recommended, even though the docs are not great, yet; the package itself is).

I am wondering whether it makes sense to stick each webpage (which is roughly a get '/webpage' => sub { ... }) into its own .pl file. because they are more like .pl files than .pm files, I could glob through the directory for .pl files and then concat and eval them.

Numerical Recipees in C/Fortran/etc. organized itself roughly like this, too.

I am probably not the first to run into this issue. What is the best practice here?

/iaw

Replies are listed 'Best First'.
Re: Multiple Perl Files, Each With 1 Sub?
by chromatic (Archbishop) on Jan 17, 2012 at 20:29 UTC
    I could glob through the directory for .pl files and then concat and eval them.

    That sounds like more work than using one .pm file per logical unit. I prefer less work.


    Improve your skills with Modern Perl: the free book.

Re: Multiple Perl Files, Each With 1 Sub?
by perlson (Initiate) on Jan 18, 2012 at 16:53 UTC

    The best practice here is to switch from Mojolicious::Lite to Mojolicious.

    If you don't like the shorthand available for specifying your route destinations, you can use the namespace option like:

    my $r = $self->routes(); $r->route('/foo')->to(namespace => 'Some::Module', action => 'someSub' +); $r->route('/bar')->to(namespace => 'Another::Module', action => 'anoth +erSub');
Re: Multiple Perl Files, Each With 1 Sub?
by Anonymous Monk on Jan 19, 2012 at 04:33 UTC