| 1 | package FindApp; | ||
| 2 | |||
| 3 | 6 | ▶ | use v5.10; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 6 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 6 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 6 | ▶ | use mro "c3"; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 6 | our $VERSION = "v0.0.7"; | |
| 9 | |||
| 10 | 6 | ▶ | use FindApp::Vars qw(:all); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 6 | ▶ | use FindApp::Utils qw(:package); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 6 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 6 | ▶ | use FindApp::Utils <tracing debugging>; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 6 | ▶ | use parent subpackage Object => with "Exporter"; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | |||
| 16 | # Don't do this here!!! | ||
| 17 | #__PACKAGE__->renew(); | ||
| 18 | |||
| 19 | 6 | 1; | |
| 20 | |||
| 21 | =encoding utf8 | ||
| 22 | |||
| 23 | =head1 NAME | ||
| 24 | |||
| 25 | FindApp - find your application home and config your process for it | ||
| 26 | |||
| 27 | =head1 SYNOPSIS | ||
| 28 | |||
| 29 | use FindApp; # defaults to "lib" argument | ||
| 30 | use FindApp "lib"; # explicit | ||
| 31 | |||
| 32 | That guarantees that this will always src, presuming there is | ||
| 33 | a "lib" above you that has the "MyCorp::CorpApp" module under it: | ||
| 34 | |||
| 35 | use FindApp "MyCorp::CorpApp"; | ||
| 36 | use MyCorp::CorpApp; | ||
| 37 | |||
| 38 | Or load-and-go: | ||
| 39 | |||
| 40 | use FindApp -root => "lib/", -use "MyCorp::CorpApp"; | ||
| 41 | |||
| 42 | AKA: | ||
| 43 | |||
| 44 | use applib "MyCorp::CorpApp"; | ||
| 45 | |||
| 46 | =head1 DESCRIPTION | ||
| 47 | |||
| 48 | When you have a application directory with its own installation | ||
| 49 | instructure, setting up its @INC path for its scripts to use | ||
| 50 | can be troublesome. You can't just say: | ||
| 51 | |||
| 52 | use lib "lib"; | ||
| 53 | |||
| 54 | or | ||
| 55 | |||
| 56 | use lib "../lib"; | ||
| 57 | |||
| 58 | because that requires that the program be run from a particular | ||
| 59 | directory. The normal approach is something like this: | ||
| 60 | |||
| 61 | use FindBin; | ||
| 62 | use lib "$FindBin::Bin/../lib"; | ||
| 63 | |||
| 64 | Even when possible in a few cases, it doesn't src for scripts that | ||
| 65 | you want to move around your application tree, such as test files, | ||
| 66 | support tools that may be in a prod-vs-nonprod directory, cron scripts, | ||
| 67 | and all the rest. | ||
| 68 | |||
| 69 | When you say C<use FindApp>, the first enclosing directory that matches | ||
| 70 | the selection criteria is used. The default selection criterion is that | ||
| 71 | the root application directory contain a directory called "lib", which | ||
| 72 | will be added to your @INC. You can also look at the current selection | ||
| 73 | criteria this way: | ||
| 74 | |||
| 75 | bash$ perl -MFindApp -le 'print FindApp->constraint_text' | ||
| 76 | lib/ in root | ||
| 77 | |||
| 78 | What it actually does is something like this: | ||
| 79 | |||
| 80 | bash$ perl -MFindApp -e 'print FindApp->shell_settings' | ||
| 81 | export APP_ROOT="/home/tchrist/src/corp-app"; | ||
| 82 | export PERL5LIB="/home/tchrist/src/corp-app/lib:$PERL5LIB"; | ||
| 83 | export PATH-"/home/tchrist/src/corp-app/bin:$PATH"; | ||
| 84 | |||
| 85 | Except that it only does a C<use lib> on the library directory it found; it doesn't | ||
| 86 | actually muck with your PERL5LIB variable. | ||
| 87 | |||
| 88 | That's something you could eval directly from your shell. This even | ||
| 89 | srcs for I<csh> and I<tcsh> users, because they see something different: | ||
| 90 | |||
| 91 | tcsh% perl -MFindApp -e 'print FindApp->shell_settings' | ||
| 92 | setenv APP_ROOT "/home/tchrist/src/corp-app"; | ||
| 93 | setenv PERL5LIB "/home/tchrist/src/corp-app/lib:$PERL5LIB"; | ||
| 94 | setenv PATH "/home/tchrist/src/corp-app/bin:$PATH"; | ||
| 95 | |||
| 96 | You can add constraints to the root directory itself or the bin set, the lib set, | ||
| 97 | or the man set. For example, | ||
| 98 | |||
| 99 | use FindApp -LIB "t/lib", # add new lib possibility | ||
| 100 | -BIN "bin/utils", # add new bin possibility | ||
| 101 | -bin "app.fcgi", # add new bin requirement | ||
| 102 | qw(MyCorp::CorpApp MyCorp::CorpApp::Test); # add two lib requirements | ||
| 103 | |||
| 104 | The constraint text after that would be: | ||
| 105 | |||
| 106 | lib/ in root, app.fcgi in bin or bin/utils, and MyCorp::CorpApp and MyCorp::CorpApp::Test in lib or t/lib | ||
| 107 | |||
| 108 | =head2 Public Methods | ||
| 109 | |||
| 110 | =over | ||
| 111 | |||
| 112 | =back | ||
| 113 | |||
| 114 | =head2 Exports | ||
| 115 | |||
| 116 | =over | ||
| 117 | |||
| 118 | =back | ||
| 119 | |||
| 120 | =head1 EXAMPLES | ||
| 121 | |||
| 122 | =head1 ENVIRONMENT | ||
| 123 | |||
| 124 | =head1 SEE ALSO | ||
| 125 | |||
| 126 | =over | ||
| 127 | |||
| 128 | =item L<FindApp> | ||
| 129 | |||
| 130 | =back | ||
| 131 | |||
| 132 | =head1 CAVEATS AND PROVISOS | ||
| 133 | |||
| 134 | =head1 BUGS AND LIMITATIONS | ||
| 135 | |||
| 136 | =head1 HISTORY | ||
| 137 | |||
| 138 | =head1 AUTHOR | ||
| 139 | |||
| 140 | Tom Christiansen C<< <tchrist@perl.com> >> | ||
| 141 | |||
| 142 | =head1 LICENCE AND COPYRIGHT | ||
| 143 | |||
| 144 | Copyright (c) 2016, Tom Christiansen C<< <tchrist@perl.com> >>. | ||
| 145 | All Rights Reserved. | ||
| 146 | |||
| 147 | This module is free software; you can redistribute it and/or | ||
| 148 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||