perlrc
view release on metacpan or search on metacpan
lib/perlrc.pm view on Meta::CPAN
package perlrc;
our $VERSION = '0.01';
use strict;
use warnings;
use Carp;
sub _home {
my $user = shift;
my $uid = (length $user ? getpwnam($user) : $>);
defined $uid or return "~$user";
my $home = (getpwuid $uid)[7];
defined $home or return "~$user";
$home
}
sub import {
shift;
my $path;
if (@_) {
$path = join(',', @_);
}
else {
$path = '~/.perlrc:/etc/perlrc';
}
my @path = split /:/, $path;
for my $file (@path) {
$file =~ s/^~([^\/]*)/_home($1)/e;
$file = '.' unless length $file;
$file =~ s/\/*$/\/.perlrc/ if -d $file;
my @files = $file;
push @files, "$file.pl" unless $file =~ /\.pl$/;
for (@files) {
if (-f $_) {
package main;
do $_;
return;
}
}
}
warn "no perlrc file found in $path\n";
}
1;
__END__
=head1 NAME
perlrc - run perlrc file before script
=head1 SYNOPSIS
$ perl -Mperlrc script.pl
$ perl -Mperlrc=/path1:/path2:...
=head1 DESCRIPTION
This module executes a perlrc file containing perl code before calling
the main script.
By default it looks for the perlrc file in the following locations:
~/.perlrc
~/.perlrc.pl
/etc/perlrc
/etc/perlrc.pl
Alternatively, a list of directories and/or files can be passed to the
module. For instance:
$ perl -Mperlrc=~root/:/tmp/myperlrc
( run in 0.611 second using v1.01-cache-2.11-cpan-98e64b0badf )