line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::cd; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$File::cd::VERSION = '0.003'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Easily and safely change directory |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
24227
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
76
|
|
12
|
|
|
|
|
|
|
$Carp::Internal{(__PACKAGE__)} = 1; |
13
|
1
|
|
|
1
|
|
4
|
use Cwd (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
4
|
use Exporter qw(import); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
203
|
|
17
|
|
|
|
|
|
|
our @EXPORT = our @EXPORT_OK = qw(cd); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub cd ($&) { |
21
|
12
|
|
|
12
|
1
|
45414
|
my ($dir, $func) = @_; |
22
|
12
|
100
|
|
|
|
2603
|
croak "Directory '$dir' does not exist" unless -d $dir; |
23
|
|
|
|
|
|
|
|
24
|
11
|
|
|
|
|
99
|
my $orig_dir = Cwd::getcwd(); |
25
|
|
|
|
|
|
|
|
26
|
11
|
50
|
|
|
|
151
|
chdir $dir or croak "Failed to change directory to '$dir': $!"; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# only one will eventually be used (depending on context) |
29
|
11
|
|
|
|
|
33
|
my ($retval, @retval); |
30
|
|
|
|
|
|
|
|
31
|
11
|
100
|
|
|
|
29
|
if (wantarray) { |
32
|
2
|
|
|
|
|
8
|
@retval = $func->(); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
|
|
|
|
|
|
# void context also goes here |
36
|
9
|
|
|
|
|
22
|
$retval = $func->(); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
11
|
50
|
|
|
|
18944
|
chdir $orig_dir |
40
|
|
|
|
|
|
|
or croak "Failed to go back to original directory '$orig_dir': $!"; |
41
|
|
|
|
|
|
|
|
42
|
11
|
100
|
|
|
|
108
|
return wantarray ? @retval : $retval; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |