← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/File/HomeDir/Darwin.pm
StatementsExecuted 15 statements in 609µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111502µs849µsFile::HomeDir::Darwin::::BEGIN@7File::HomeDir::Darwin::BEGIN@7
11114µs14µsFile::HomeDir::Darwin::::BEGIN@3File::HomeDir::Darwin::BEGIN@3
1119µs9µsFile::HomeDir::Darwin::::BEGIN@10File::HomeDir::Darwin::BEGIN@10
1117µs36µsFile::HomeDir::Darwin::::BEGIN@9File::HomeDir::Darwin::BEGIN@9
1116µs17µsFile::HomeDir::Darwin::::BEGIN@4File::HomeDir::Darwin::BEGIN@4
1113µs3µsFile::HomeDir::Darwin::::BEGIN@5File::HomeDir::Darwin::BEGIN@5
1113µs3µsFile::HomeDir::Darwin::::BEGIN@6File::HomeDir::Darwin::BEGIN@6
0000s0sFile::HomeDir::Darwin::::_my_homeFile::HomeDir::Darwin::_my_home
0000s0sFile::HomeDir::Darwin::::_to_userFile::HomeDir::Darwin::_to_user
0000s0sFile::HomeDir::Darwin::::my_dataFile::HomeDir::Darwin::my_data
0000s0sFile::HomeDir::Darwin::::my_desktopFile::HomeDir::Darwin::my_desktop
0000s0sFile::HomeDir::Darwin::::my_documentsFile::HomeDir::Darwin::my_documents
0000s0sFile::HomeDir::Darwin::::my_homeFile::HomeDir::Darwin::my_home
0000s0sFile::HomeDir::Darwin::::my_musicFile::HomeDir::Darwin::my_music
0000s0sFile::HomeDir::Darwin::::my_picturesFile::HomeDir::Darwin::my_pictures
0000s0sFile::HomeDir::Darwin::::my_videosFile::HomeDir::Darwin::my_videos
0000s0sFile::HomeDir::Darwin::::users_dataFile::HomeDir::Darwin::users_data
0000s0sFile::HomeDir::Darwin::::users_desktopFile::HomeDir::Darwin::users_desktop
0000s0sFile::HomeDir::Darwin::::users_documentsFile::HomeDir::Darwin::users_documents
0000s0sFile::HomeDir::Darwin::::users_homeFile::HomeDir::Darwin::users_home
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package File::HomeDir::Darwin;
2
3241µs114µs
# spent 14µs within File::HomeDir::Darwin::BEGIN@3 which was called: # once (14µs+0s) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 3
use 5.00503;
# spent 14µs making 1 call to File::HomeDir::Darwin::BEGIN@3
4218µs228µs
# spent 17µs (6+11) within File::HomeDir::Darwin::BEGIN@4 which was called: # once (6µs+11µs) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 4
use strict;
# spent 17µs making 1 call to File::HomeDir::Darwin::BEGIN@4 # spent 11µs making 1 call to strict::import
5215µs13µs
# spent 3µs within File::HomeDir::Darwin::BEGIN@5 which was called: # once (3µs+0s) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 5
use Cwd ();
# spent 3µs making 1 call to File::HomeDir::Darwin::BEGIN@5
6219µs13µs
# spent 3µs within File::HomeDir::Darwin::BEGIN@6 which was called: # once (3µs+0s) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 6
use Carp ();
# spent 3µs making 1 call to File::HomeDir::Darwin::BEGIN@6
7284µs1849µs
# spent 849µs (502+347) within File::HomeDir::Darwin::BEGIN@7 which was called: # once (502µs+347µs) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 7
use File::HomeDir::Unix ();
# spent 849µs making 1 call to File::HomeDir::Darwin::BEGIN@7
8
9229µs264µs
# spent 36µs (7+29) within File::HomeDir::Darwin::BEGIN@9 which was called: # once (7µs+29µs) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 9
use vars qw{$VERSION @ISA};
# spent 36µs making 1 call to File::HomeDir::Darwin::BEGIN@9 # spent 29µs making 1 call to vars::import
10
# spent 9µs within File::HomeDir::Darwin::BEGIN@10 which was called: # once (9µs+0s) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 13
BEGIN {
111300ns $VERSION = '1.00';
1219µs @ISA = 'File::HomeDir::Unix';
131393µs19µs}
# spent 9µs making 1 call to File::HomeDir::Darwin::BEGIN@10
14
- -
19#####################################################################
20# Current User Methods
21
22sub my_home {
23 my $class = shift;
24
25 if ( exists $ENV{HOME} and defined $ENV{HOME} ) {
26 return $ENV{HOME};
27 }
28
29 my $home = (getpwuid($<))[7];
30 return $home if $home && -d $home;
31
32 return undef;
33}
34
35sub _my_home {
36 my($class, $path) = @_;
37 my $home = $class->my_home;
38 return undef unless defined $home;
39
40 my $folder = "$home/$path";
41 unless ( -d $folder ) {
42 # Make sure that symlinks resolve to directories.
43 return undef unless -l $folder;
44 my $dir = readlink $folder or return;
45 return undef unless -d $dir;
46 }
47
48 return Cwd::abs_path($folder);
49}
50
51sub my_desktop {
52 my $class = shift;
53 $class->_my_home('Desktop');
54}
55
56sub my_documents {
57 my $class = shift;
58 $class->_my_home('Documents');
59}
60
61sub my_data {
62 my $class = shift;
63 $class->_my_home('Library/Application Support');
64}
65
66sub my_music {
67 my $class = shift;
68 $class->_my_home('Music');
69}
70
71sub my_pictures {
72 my $class = shift;
73 $class->_my_home('Pictures');
74}
75
76sub my_videos {
77 my $class = shift;
78 $class->_my_home('Movies');
79}
80
- -
85#####################################################################
86# Arbitrary User Methods
87
88sub users_home {
89 my $class = shift;
90 my $home = $class->SUPER::users_home(@_);
91 return defined $home ? Cwd::abs_path($home) : undef;
92}
93
94sub users_desktop {
95 my ($class, $name) = @_;
96 return undef if $name eq 'root';
97 $class->_to_user( $class->my_desktop, $name );
98}
99
100sub users_documents {
101 my ($class, $name) = @_;
102 return undef if $name eq 'root';
103 $class->_to_user( $class->my_documents, $name );
104}
105
106sub users_data {
107 my ($class, $name) = @_;
108 $class->_to_user( $class->my_data, $name )
109 ||
110 $class->users_home($name);
111}
112
113# cheap hack ... not entirely reliable, perhaps, but ... c'est la vie, since
114# there's really no other good way to do it at this time, that i know of -- pudge
115sub _to_user {
116 my ($class, $path, $name) = @_;
117 my $my_home = $class->my_home;
118 my $users_home = $class->users_home($name);
119 defined $users_home or return undef;
120 $path =~ s/^\Q$my_home/$users_home/;
121 return $path;
122}
123
12412µs1;
125
126=pod
127
128=head1 NAME
129
130File::HomeDir::Darwin - Find your home and other directories on Darwin (OS X)
131
132=head1 DESCRIPTION
133
134This module provides Mac OS X specific file path for determining
135common user directories in pure perl, by just using C<$ENV{HOME}>
136without Carbon nor Cocoa API calls. In normal usage this module will
137always be used via L<File::HomeDir>.
138
139=head1 SYNOPSIS
140
141 use File::HomeDir;
142
143 # Find directories for the current user
144 $home = File::HomeDir->my_home; # /Users/mylogin
145 $desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop
146 $docs = File::HomeDir->my_documents; # /Users/mylogin/Documents
147 $music = File::HomeDir->my_music; # /Users/mylogin/Music
148 $pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures
149 $videos = File::HomeDir->my_videos; # /Users/mylogin/Movies
150 $data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support
151
152=cut