package textbender::a::b::Config; # Copyright 2005, 2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. use strict; use warnings; =pod =head1 DESCRIPTION Configuration files for build scripts. A build script that cannot locate its configuration will halt with an error: unable to parse *basepath*_config.pl: No such file or directory cannot find *basepath*_config.*: No such file or directory etc. You must create the missing configuration file. An example is provided in the same directory, under the name: *basename*_config_example.* Make a copy of the example file, renaming it, and placing it in a separate directory tree on Perl's library search path. For example: /usr/local/lib/site_perl/*basepath*_config.* (You could also place it in the same directory with the example file. But it is usually wiser to keep config files separate from the source working copies; if only to prevent them being accidently committed to the repo.) Finally, load the new config file into your editor, and modify it as instructed therein. =head2 When Upgrading If you have upgraded to new code, and a build script detects out-of-date configuration, it will halt with an error: Undefined subroutine *name* called at *file* Expecting version *n* at *file* etc. If there is an associated *file*_config, then it is probably out-of-date. Update it according to the example configuration supplied with the new code. =head1 EXPORTS =over 4 =cut BEGIN { use Exporter (); our @ISA; @ISA = qw( Exporter ); our @EXPORT_OK; @EXPORT_OK = qw( $auto_deploy config_basepath_from_package do_fail ensure_config_file ); } our @EXPORT_OK; =pod =item B( $I ) Returns the relative basepath to the local files for the specified package name. This is the complete relative pathname of the local files, except for their extensions. =cut sub config_basepath_from_package( $ ) { my $basepath = shift; # textbender::foo::Bar $basepath =~ s,::,/,g; # textbender/foo/Bar $basepath .= '_config'; # textbender/foo/Bar_config return $basepath; } =pod =item B( $I ) Handles a failure of 'do', on the specified local path. Dies with an appropriate message. =cut sub do_fail( $ ) { my $config_path = shift; $@ and die "compile error in $config_path: $@\n"; $! and die "unable to parse $config_path: $!\n"; die "$config_path did not return a true value\n"; } =pod =item B( $I ) Ensures that a config file exists on the specified relative path. Returns the config file, or dies. =cut sub ensure_config_file( $ ) { my $rel_path = shift; my $file; for my $prefix( @INC ) { my $f = "$prefix/$rel_path"; if( -f $f ) { $file = $f; last; } } defined $file or die "cannot find $rel_path\n"; return $file; } =pod =back =cut 1;