Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Collapsing smaller scripts into a larger one, request for comment

by perlfan (Vicar)
on May 31, 2020 at 06:19 UTC ( [id://11117521]=note: print w/replies, xml ) Need Help??


in reply to Collapsing smaller scripts into a larger one, request for comment

use lib '../files/lib';
I'd use FindBin here. Regarding what all is in __DATA__, you could separate the driver code and turn each set of __DATA__ into a module. And rather than having a __DATA__ section, have an our DATA variable - since you're clearly editing this manually anyway, the work to maintain it will be the same after you convert it. This brings you closer to the suggestion, which I agree with, to separate your code from your data.

For example, index.pl becomes:

use strict; use warnings; package site::index; our $DATA = q{Welcome to Lady Aleena's B<collections>, which is lists +of A<novels|href="Fiction.pl">, A<books|href="Non-fiction.pl">, A<mus +ic|href="Music_and_comedy.pl">, A<movies|href="Movies.pl">, A<tie-ins +|href="Tie-ins.pl">, and A<programs|href="Programs.pl"> I am willing +to admit I own or use. The list of movies here is just those movies I + own and should not to be confused with my more general interest in A +<movies|href="../Movies">. Tie-ins are books and music connected to m +ovies or television series. I also share my A<fandom|href="../Fandom" +> elsewhere. Here is a key for the notations after each title with the exception of + programs.}; 1;
Fiction.pl becomes:
use strict; use warnings; package site::collection::Fiction; our $DATA = q{This is my B<fiction collection> of SPAN<hardcovers|^har +dcovers^>, SPAN<trade paperbacks|^trades^>, and SPAN<mass market pape +rbacks|^massmarkets^>.} 1;
...etc

Then you'd register these modules in your main driver, and based on whatever it is that you're dispatching on you could use the appropriate full package name to get the content via $site::index::DATA, $site::collection::Fiction::DATA, etc. I suggest this because it seems you like this style for its maintenance ease, but not for it's Perl sophistication. The solution above keeps the maintenance overhead similar to now, but is more sophisticated Perl by allowing you to eliminate the repeated calling code and implement some dispatching. And you can even keep the same .pl file names and directory structure provided you require them (which you'd have to anyway.

Replies are listed 'Best First'.
Re^2: Collapsing smaller scripts into a larger one, request for comment
by Lady_Aleena (Priest) on Jun 03, 2020 at 04:18 UTC

    I looked at FindBin and can not tell what purpose it serves. It seems I would still need to know the relative path to my lib, so why add this to it?

    And so you know, the __DATA__ I put in the original post was just first paragraphs. Some __DATA__ fields are hundreds of lines long. So the modules you are suggesting would be tidier with __DATA__ fields and exporting those fields as a glob (faux file handle). I am also not sure that use statements could be put into loops.

    However, I may be misunderstanding what you are suggesting. The text still needs extensive munging any way I do it.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

    Version control is a non-issue, I do not use it.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117521]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-23 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found