Filename | /usr/lib64/perl5/vendor_perl/5.16.0/File/BaseDir.pm |
Statements | Executed 54 statements in 6.46ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 579µs | 3.04ms | _find_files | File::BaseDir::
6 | 1 | 1 | 198µs | 355µs | _file | File::BaseDir::
6 | 1 | 1 | 156µs | 156µs | CORE:ftfile (opcode) | File::BaseDir::
2 | 2 | 2 | 139µs | 3.24ms | data_files | File::BaseDir::
1 | 1 | 1 | 81µs | 179µs | BEGIN@3 | File::BaseDir::
1 | 1 | 1 | 54µs | 318µs | BEGIN@4 | File::BaseDir::
2 | 1 | 1 | 42µs | 42µs | CORE:fteread (opcode) | File::BaseDir::
2 | 1 | 1 | 33µs | 33µs | xdg_data_dirs | File::BaseDir::
2 | 1 | 1 | 30µs | 30µs | xdg_data_home | File::BaseDir::
2 | 1 | 1 | 11µs | 11µs | CORE:match (opcode) | File::BaseDir::
0 | 0 | 0 | 0s | 0s | _adapt | File::BaseDir::
0 | 0 | 0 | 0s | 0s | _catfile | File::BaseDir::
0 | 0 | 0 | 0s | 0s | _dir | File::BaseDir::
0 | 0 | 0 | 0s | 0s | cache_home | File::BaseDir::
0 | 0 | 0 | 0s | 0s | config_dirs | File::BaseDir::
0 | 0 | 0 | 0s | 0s | config_files | File::BaseDir::
0 | 0 | 0 | 0s | 0s | config_home | File::BaseDir::
0 | 0 | 0 | 0s | 0s | data_dirs | File::BaseDir::
0 | 0 | 0 | 0s | 0s | data_home | File::BaseDir::
0 | 0 | 0 | 0s | 0s | new | File::BaseDir::
0 | 0 | 0 | 0s | 0s | xdg_cache_home | File::BaseDir::
0 | 0 | 0 | 0s | 0s | xdg_config_dirs | File::BaseDir::
0 | 0 | 0 | 0s | 0s | xdg_config_files | File::BaseDir::
0 | 0 | 0 | 0s | 0s | xdg_config_home | File::BaseDir::
0 | 0 | 0 | 0s | 0s | xdg_data_files | File::BaseDir::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package File::BaseDir; | ||||
2 | |||||
3 | 2 | 150µs | 2 | 277µs | # spent 179µs (81+98) within File::BaseDir::BEGIN@3 which was called:
# once (81µs+98µs) by File::MimeInfo::Magic::BEGIN@7 at line 3 # spent 179µs making 1 call to File::BaseDir::BEGIN@3
# spent 98µs making 1 call to strict::import |
4 | 2 | 4.82ms | 2 | 582µs | # spent 318µs (54+264) within File::BaseDir::BEGIN@4 which was called:
# once (54µs+264µs) by File::MimeInfo::Magic::BEGIN@7 at line 4 # spent 318µs making 1 call to File::BaseDir::BEGIN@4
# spent 264µs making 1 call to Exporter::import |
5 | 1 | 6µs | require File::Spec; | ||
6 | 1 | 2µs | require Exporter; | ||
7 | |||||
8 | 1 | 2µs | our $VERSION = 0.03; | ||
9 | |||||
10 | 1 | 36µs | our @ISA = qw(Exporter); | ||
11 | 1 | 22µs | our %EXPORT_TAGS = ( | ||
12 | vars => [ qw( | ||||
13 | xdg_data_home xdg_data_dirs | ||||
14 | xdg_config_home xdg_config_dirs | ||||
15 | xdg_cache_home | ||||
16 | ) ], | ||||
17 | lookup => [ qw( | ||||
18 | data_home data_dirs data_files | ||||
19 | config_home config_dirs config_files | ||||
20 | cache_home | ||||
21 | ) ], | ||||
22 | ); | ||||
23 | 1 | 32µs | our @EXPORT_OK = ( | ||
24 | qw(xdg_data_files xdg_config_files), | ||||
25 | map @$_, values %EXPORT_TAGS | ||||
26 | ); | ||||
27 | |||||
28 | # Set root and home directories | ||||
29 | 1 | 30µs | 1 | 18µs | my $rootdir = File::Spec->rootdir(); # spent 18µs making 1 call to File::Spec::Unix::rootdir |
30 | 1 | 7µs | if ($^O eq 'MSWin32') { | ||
31 | $rootdir = 'C:\\'; # File::Spec default depends on CWD | ||||
32 | $ENV{HOME} ||= $ENV{USERPROFILE} || $ENV{HOMEDRIVE}.$ENV{HOMEPATH}; | ||||
33 | # logic from File::HomeDir::Windows | ||||
34 | } | ||||
35 | 1 | 8µs | my $home = $ENV{HOME}; | ||
36 | 1 | 600ns | unless ($home) { | ||
37 | warn "WARNING: HOME is not set, using root: $rootdir\n"; | ||||
38 | $home = $rootdir; | ||||
39 | } | ||||
40 | |||||
41 | # Set defaults | ||||
42 | 1 | 19µs | 1 | 164µs | our $xdg_data_home = File::Spec->catdir($home, qw/.local share/); # spent 164µs making 1 call to File::Spec::Unix::catdir |
43 | 1 | 33µs | 2 | 257µs | our @xdg_data_dirs = ( # spent 257µs making 2 calls to File::Spec::Unix::catdir, avg 128µs/call |
44 | File::Spec->catdir($rootdir, qw/usr local share/), | ||||
45 | File::Spec->catdir($rootdir, qw/usr share/), | ||||
46 | ); | ||||
47 | 1 | 14µs | 1 | 123µs | our $xdg_config_home = File::Spec->catdir($home, '.config'); # spent 123µs making 1 call to File::Spec::Unix::catdir |
48 | 1 | 18µs | 1 | 127µs | our @xdg_config_dirs = ( File::Spec->catdir($rootdir, qw/etc xdg/) ); # spent 127µs making 1 call to File::Spec::Unix::catdir |
49 | 1 | 16µs | 1 | 188µs | our $xdg_cache_home = File::Spec->catdir($home, '.cache'); # spent 188µs making 1 call to File::Spec::Unix::catdir |
50 | |||||
51 | # OO method | ||||
52 | sub new { bless \$VERSION, shift } # what else is there to bless ? | ||||
53 | |||||
54 | # Variable methods | ||||
55 | 2 | 52µs | # spent 30µs within File::BaseDir::xdg_data_home which was called 2 times, avg 15µs/call:
# 2 times (30µs+0s) by File::BaseDir::data_files at line 85, avg 15µs/call | ||
56 | |||||
57 | # spent 33µs within File::BaseDir::xdg_data_dirs which was called 2 times, avg 16µs/call:
# 2 times (33µs+0s) by File::BaseDir::data_files at line 85, avg 16µs/call | ||||
58 | 2 | 50µs | ( $ENV{XDG_DATA_DIRS} | ||
59 | ? _adapt($ENV{XDG_DATA_DIRS}) | ||||
60 | : @xdg_data_dirs | ||||
61 | ) | ||||
62 | } | ||||
63 | |||||
64 | sub xdg_config_home {$ENV{XDG_CONFIG_HOME} || $xdg_config_home } | ||||
65 | |||||
66 | sub xdg_config_dirs { | ||||
67 | ( $ENV{XDG_CONFIG_DIRS} | ||||
68 | ? _adapt($ENV{XDG_CONFIG_DIRS}) | ||||
69 | : @xdg_config_dirs | ||||
70 | ) | ||||
71 | } | ||||
72 | |||||
73 | sub xdg_cache_home { $ENV{XDG_CACHE_HOME} || $xdg_cache_home } | ||||
74 | |||||
75 | sub _adapt { | ||||
76 | map { File::Spec->catdir( split('/', $_) ) } split /[:;]/, shift; | ||||
77 | # ':' defined in the spec, but ';' is standard on win32 | ||||
78 | } | ||||
79 | |||||
80 | # Lookup methods | ||||
81 | sub data_home { _catfile(xdg_data_home, @_) } | ||||
82 | |||||
83 | sub data_dirs { _find_files(\&_dir, \@_, xdg_data_home, xdg_data_dirs) } | ||||
84 | |||||
85 | 2 | 118µs | 6 | 3.10ms | # spent 3.24ms (139µs+3.10) within File::BaseDir::data_files which was called 2 times, avg 1.62ms/call:
# once (83µs+1.96ms) by File::MimeInfo::Magic::_rehash at line 128 of File/MimeInfo/Magic.pm
# once (56µs+1.15ms) by File::MimeInfo::rehash at line 140 of File/MimeInfo.pm # spent 3.04ms making 2 calls to File::BaseDir::_find_files, avg 1.52ms/call
# spent 33µs making 2 calls to File::BaseDir::xdg_data_dirs, avg 16µs/call
# spent 30µs making 2 calls to File::BaseDir::xdg_data_home, avg 15µs/call |
86 | |||||
87 | sub xdg_data_files { my @dirs = data_files(@_); return @dirs } | ||||
88 | |||||
89 | sub config_home { _catfile(xdg_config_home, @_) } | ||||
90 | |||||
91 | sub config_dirs { _find_files(\&_dir, \@_, xdg_config_home, xdg_config_dirs) } | ||||
92 | |||||
93 | sub config_files { _find_files(\&_file, \@_, xdg_config_home, xdg_config_dirs) } | ||||
94 | |||||
95 | sub xdg_config_files { my @dirs = config_files(@_); return @dirs } | ||||
96 | |||||
97 | sub cache_home { _catfile(xdg_cache_home, @_) } | ||||
98 | |||||
99 | sub _catfile { | ||||
100 | my $dir = shift; | ||||
101 | shift if ref $_[0] or $_[0] =~ /::/; # OO call | ||||
102 | return File::Spec->catfile($dir, @_); | ||||
103 | } | ||||
104 | |||||
105 | # spent 3.04ms (579µs+2.46) within File::BaseDir::_find_files which was called 2 times, avg 1.52ms/call:
# 2 times (579µs+2.46ms) by File::BaseDir::data_files at line 85, avg 1.52ms/call | ||||
106 | 2 | 5µs | my $type = shift; | ||
107 | 2 | 3µs | my $file = shift; | ||
108 | 2 | 55µs | 2 | 11µs | shift @$file if ref $$file[0] or $$file[0] =~ /::/; # OO call # spent 11µs making 2 calls to File::BaseDir::CORE:match, avg 5µs/call |
109 | #warn "Looking for: @$file\n in: @_\n"; | ||||
110 | 2 | 5µs | if (wantarray) { | ||
111 | 12 | 337µs | 14 | 2.45ms | return grep { &$type( $_ ) && -r $_ } # spent 2.06ms making 6 calls to File::Spec::Unix::catfile, avg 343µs/call
# spent 355µs making 6 calls to File::BaseDir::_file, avg 59µs/call
# spent 42µs making 2 calls to File::BaseDir::CORE:fteread, avg 21µs/call |
112 | 2 | 112µs | map { File::Spec->catfile($_, @$file) } @_; | ||
113 | } | ||||
114 | else { # prevent unnessecary stats by returning early | ||||
115 | for (@_) { | ||||
116 | my $path = File::Spec->catfile($_, @$file); | ||||
117 | return $path if &$type($path) && -r $path; | ||||
118 | } | ||||
119 | } | ||||
120 | return (); | ||||
121 | } | ||||
122 | |||||
123 | sub _dir { -d $_[0] } | ||||
124 | |||||
125 | 6 | 442µs | 6 | 156µs | # spent 355µs (198+156) within File::BaseDir::_file which was called 6 times, avg 59µs/call:
# 6 times (198µs+156µs) by File::BaseDir::_find_files at line 111, avg 59µs/call # spent 156µs making 6 calls to File::BaseDir::CORE:ftfile, avg 26µs/call |
126 | |||||
127 | 1 | 70µs | 1; | ||
128 | |||||
129 | __END__ | ||||
# spent 42µs within File::BaseDir::CORE:fteread which was called 2 times, avg 21µs/call:
# 2 times (42µs+0s) by File::BaseDir::_find_files at line 111, avg 21µs/call | |||||
# spent 156µs within File::BaseDir::CORE:ftfile which was called 6 times, avg 26µs/call:
# 6 times (156µs+0s) by File::BaseDir::_file at line 125, avg 26µs/call | |||||
# spent 11µs within File::BaseDir::CORE:match which was called 2 times, avg 5µs/call:
# 2 times (11µs+0s) by File::BaseDir::_find_files at line 108, avg 5µs/call |