| 1 | package perlrc; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = '0.01'; | |||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | sub _home { | ||||||||
|
Subroutine
_home: called CC=4 SCAR=14.5
| |||||||||||
| 10 | 1 | my $user = shift; | |||||||||
| 11 | 1 | ▶ | my $uid = (length $user ? getpwnam($user) : $>); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | 1 | ▶ | defined $uid or return "~$user"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 1 | my $home = (getpwuid $uid)[7]; | |||||||||
| 14 | 1 | ▶ | defined $home or return "~$user"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 1 | $home | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=8 SCAR=22.5
| |||||||||||
| 19 | 1 | shift; | |||||||||
| 20 | 1 | my $path; | |||||||||
| 21 | 1 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | $path = join(',', @_); | |||||||||
| 23 | } | ||||||||||
| 24 | else { | ||||||||||
| 25 | 1 | $path = '~/.perlrc:/etc/perlrc'; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 1 | my @path = split /:/, $path; | |||||||||
| 29 | 1 | for my $file (@path) { | |||||||||
| 30 | 2 | $file =~ s/^~([^\/]*)/_home($1)/e; | |||||||||
| 31 | 2 | ▶ | $file = '.' unless length $file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 2 | ▶ | $file =~ s/\/*$/\/.perlrc/ if -d $file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 2 | my @files = $file; | |||||||||
| 34 | 2 | ▶ | push @files, "$file.pl" unless $file =~ /\.pl$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 2 | for (@files) { | |||||||||
| 36 | 4 | ▶ | if (-f $_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | package main; | ||||||||||
| 38 | 0 | do $_; | |||||||||
| 39 | 0 | return; | |||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | } | ||||||||||
| 43 | 1 | warn "no perlrc file found in $path\n"; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 1 | 1; | |||||||||
| 47 | __END__ | ||||||||||