← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mojo-test.pl
  Run on Sat Feb 5 19:54:22 2011
Reported on Sat Feb 5 19:54:57 2011

Filename/Users/marcus/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Mojo/Command.pm
StatementsExecuted 189 statements in 3.68ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1112.02ms7.39msMojo::Command::::BEGIN@11Mojo::Command::BEGIN@11
111546µs546µsMojo::Command::::CORE:readlineMojo::Command::CORE:readline (opcode)
2431474µs474µsMojo::Command::::CORE:substMojo::Command::CORE:subst (opcode)
522468µs1.51msMojo::Command::::get_all_dataMojo::Command::get_all_data
11173µs21.3sMojo::Command::::runMojo::Command::run
11130µs21.3sMojo::Command::::startMojo::Command::start
44128µs1.53msMojo::Command::::get_dataMojo::Command::get_data
11118µs18µsMojo::Command::::CORE:closeMojo::Command::CORE:close (opcode)
11114µs53µsMojo::Command::::BEGIN@2Mojo::Command::BEGIN@2
22214µs14µsMojo::Command::::detectMojo::Command::detect
11111µs12µsMojo::Command::::BEGIN@12Mojo::Command::BEGIN@12
1119µs11µsMojo::Command::::BEGIN@10Mojo::Command::BEGIN@10
1117µs19µsMojo::Command::::BEGIN@126Mojo::Command::BEGIN@126
1117µs31µsMojo::Command::::BEGIN@9Mojo::Command::BEGIN@9
1116µs40µsMojo::Command::::BEGIN@13Mojo::Command::BEGIN@13
1116µs6µsMojo::Command::::CORE:seekMojo::Command::CORE:seek (opcode)
1113µs3µsMojo::Command::::CORE:matchMojo::Command::CORE:match (opcode)
0000s0sMojo::Command::::__ANON__[:28]Mojo::Command::__ANON__[:28]
0000s0sMojo::Command::::__ANON__[:30]Mojo::Command::__ANON__[:30]
0000s0sMojo::Command::::chmod_fileMojo::Command::chmod_file
0000s0sMojo::Command::::chmod_rel_fileMojo::Command::chmod_rel_file
0000s0sMojo::Command::::class_to_fileMojo::Command::class_to_file
0000s0sMojo::Command::::class_to_pathMojo::Command::class_to_path
0000s0sMojo::Command::::create_dirMojo::Command::create_dir
0000s0sMojo::Command::::create_rel_dirMojo::Command::create_rel_dir
0000s0sMojo::Command::::helpMojo::Command::help
0000s0sMojo::Command::::rel_dirMojo::Command::rel_dir
0000s0sMojo::Command::::rel_fileMojo::Command::rel_file
0000s0sMojo::Command::::render_dataMojo::Command::render_data
0000s0sMojo::Command::::render_to_fileMojo::Command::render_to_file
0000s0sMojo::Command::::render_to_rel_fileMojo::Command::render_to_rel_file
0000s0sMojo::Command::::write_fileMojo::Command::write_file
0000s0sMojo::Command::::write_rel_fileMojo::Command::write_rel_file
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Mojo::Command;
2359µs253µs
# spent 53µs (14+38) within Mojo::Command::BEGIN@2 which was called: # once (14µs+38µs) by Mojo::Loader::BEGIN@7 at line 2
use Mojo::Base -base;
# spent 53µs making 1 call to Mojo::Command::BEGIN@2 # spent 38µs making 1 call to Mojo::Base::import, recursion: max depth 3, sum of overlapping time 38µs
3
41150µsrequire Cwd;
51119µsrequire File::Path;
61500nsrequire File::Spec;
71300nsrequire IO::File;
8
9322µs255µs
# spent 31µs (7+24) within Mojo::Command::BEGIN@9 which was called: # once (7µs+24µs) by Mojo::Loader::BEGIN@7 at line 9
use Carp 'croak';
# spent 31µs making 1 call to Mojo::Command::BEGIN@9 # spent 24µs making 1 call to Exporter::import
10321µs211µs
# spent 11µs (9+2) within Mojo::Command::BEGIN@10 which was called: # once (9µs+2µs) by Mojo::Loader::BEGIN@7 at line 10
use Mojo::Server;
# spent 11µs making 1 call to Mojo::Command::BEGIN@10 # spent 2µs making 1 call to Mojo::Base::import, recursion: max depth 3, sum of overlapping time 2µs
113162µs27.39ms
# spent 7.39ms (2.02+5.37) within Mojo::Command::BEGIN@11 which was called: # once (2.02ms+5.37ms) by Mojo::Loader::BEGIN@7 at line 11
use Mojo::Template;
# spent 7.39ms making 1 call to Mojo::Command::BEGIN@11 # spent 2µs making 1 call to Mojo::Base::import, recursion: max depth 3, sum of overlapping time 2µs
12325µs212µs
# spent 12µs (11+2) within Mojo::Command::BEGIN@12 which was called: # once (11µs+2µs) by Mojo::Loader::BEGIN@7 at line 12
use Mojo::Loader;
# spent 12µs making 1 call to Mojo::Command::BEGIN@12 # spent 2µs making 1 call to Mojo::Base::import, recursion: max depth 3, sum of overlapping time 2µs
133448µs274µs
# spent 40µs (6+34) within Mojo::Command::BEGIN@13 which was called: # once (6µs+34µs) by Mojo::Loader::BEGIN@7 at line 13
use Mojo::Util qw/b64_decode camelize decamelize/;
# spent 40µs making 1 call to Mojo::Command::BEGIN@13 # spent 34µs making 1 call to Exporter::import
14
1514µs198µshas hint => <<"EOF";
# spent 98µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38]
16
17See '$0 help COMMAND' for more information on a specific command.
18EOF
1912µs195µshas description => 'No description.';
# spent 95µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38]
2013µs190µshas message => <<"EOF";
# spent 90µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38]
21usage: $0 COMMAND [OPTIONS]
22
23Tip: CGI, FastCGI and PSGI environments can be automatically detected very
24 often and work without commands.
25
26These commands are currently available:
27EOF
2813µs199µshas namespaces => sub { ['Mojo::Command'] };
# spent 99µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38]
2912µs191µshas quiet => 0;
# spent 91µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38]
3018µs1103µshas renderer => sub { Mojo::Template->new };
# spent 103µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38]
3113µs1104µshas usage => "usage: $0\n";
# spent 104µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38]
32
33# Cache
341400nsmy $CACHE = {};
35
36sub chmod_file {
37 my ($self, $path, $mod) = @_;
38
39 # chmod
40 chmod $mod, $path or croak qq/Can't chmod path "$path": $!/;
41
42 $mod = sprintf '%lo', $mod;
43 print " [chmod] $path $mod\n" unless $self->quiet;
44 return $self;
45}
46
47sub chmod_rel_file {
48 my ($self, $path, $mod) = @_;
49
50 # Path
51 $path = $self->rel_file($path);
52
53 # chmod
54 $self->chmod_file($path, $mod);
55}
56
57sub class_to_file {
58 my ($self, $class) = @_;
59
60 # Class to file
61 $class =~ s/:://g;
62 decamelize $class;
63
64 return $class;
65}
66
67sub class_to_path {
68 my ($self, $class) = @_;
69
70 # Class to path
71 my $path = join '/', split /::/, $class;
72
73 return "$path.pm";
74}
75
76sub create_dir {
77 my ($self, $path) = @_;
78
79 # Exists
80 if (-d $path) {
81 print " [exist] $path\n" unless $self->quiet;
82 return $self;
83 }
84
85 # Make
86 File::Path::mkpath($path) or croak qq/Can't make directory "$path": $!/;
87 print " [mkdir] $path\n" unless $self->quiet;
88 return $self;
89}
90
91sub create_rel_dir {
92 my ($self, $path) = @_;
93
94 # Path
95 $path = $self->rel_dir($path);
96
97 # Create
98 $self->create_dir($path);
99}
100
101
# spent 14µs within Mojo::Command::detect which was called 2 times, avg 7µs/call: # once (8µs+0s) by Mojolicious::Commands::BEGIN@21 at line 25 of Mojolicious/Commands.pm # once (6µs+0s) by Mojo::Command::run at line 252
sub detect {
1021017µs my ($self, $guess) = @_;
103
104 # PSGI (Plack only for now)
105 return 'psgi' if defined $ENV{PLACK_ENV};
106
107 # CGI
108 return 'cgi'
109 if defined $ENV{PATH_INFO} || defined $ENV{GATEWAY_INTERFACE};
110
111 # No further detection if we have a guess
112 return $guess if $guess;
113
114 # FastCGI (detect absence of WINDIR for Windows and USER for UNIX)
115 return 'fastcgi' if !defined $ENV{WINDIR} && !defined $ENV{USER};
116
117 # Nothing
118 return;
119}
120
121
# spent 1.51ms (468µs+1.04) within Mojo::Command::get_all_data which was called 5 times, avg 303µs/call: # 4 times (456µs+1.04ms) by Mojo::Command::get_data at line 174, avg 375µs/call # once (12µs+0s) by Mojolicious::Renderer::_list_inline_templates at line 312 of Mojolicious/Renderer.pm
sub get_all_data {
1221091.50ms my ($self, $class) = @_;
123 $class ||= ref $self;
124
125 # Handle
12631.01ms231µs
# spent 19µs (7+12) within Mojo::Command::BEGIN@126 which was called: # once (7µs+12µs) by Mojo::Loader::BEGIN@7 at line 126
my $d = do { no strict 'refs'; \*{"$class\::DATA"} };
# spent 19µs making 1 call to Mojo::Command::BEGIN@126 # spent 12µs making 1 call to strict::unimport
127
128 # Refresh
129 if (fileno $d) {
130
131 # Reset
13216µs seek $d, 0, 0;
# spent 6µs making 1 call to Mojo::Command::CORE:seek
133
134 # Slurp
1351546µs $CACHE->{$class} = join '', <$d>;
# spent 546µs making 1 call to Mojo::Command::CORE:readline
136
137 # Close
138118µs close $d or die "DAMN: $!\n";
# spent 18µs making 1 call to Mojo::Command::CORE:close
139 }
140
141 # Content
142 return unless defined(my $content = $CACHE->{$class});
143
144 # Ignore everything before __DATA__ (windows will seek to start of file)
1454449µs $content =~ s/^.*\n__DATA__\n/\n/s;
# spent 449µs making 4 calls to Mojo::Command::CORE:subst, avg 112µs/call
146
147 # Ignore everything after __END__
148421µs $content =~ s/\n__END__\n.*$/\n/s;
# spent 21µs making 4 calls to Mojo::Command::CORE:subst, avg 5µs/call
149
150 # Split
151 my @data = split /^@@\s+(.+)\s*\r?\n/m, $content;
152
153 # Remove split garbage
154 shift @data;
155
156 # Find data
157 my $all = {};
158 while (@data) {
159 my ($name, $content) = splice @data, 0, 2;
160
161 # Base 64
162164µs b64_decode $content if $name =~ s/\s*\(\s*base64\s*\)$//;
# spent 4µs making 16 calls to Mojo::Command::CORE:subst, avg 281ns/call
163
164 $all->{$name} = $content;
165 }
166
167 return $all;
168}
169
170
# spent 1.53ms (28µs+1.50) within Mojo::Command::get_data which was called 4 times, avg 382µs/call: # once (11µs+1.02ms) by Mojo::Loader::load at line 19 of Mojolicious/Controller.pm # once (6µs+168µs) by Mojo::Loader::load at line 27 of Mojolicious/Controller.pm # once (6µs+162µs) by Mojo::Loader::load at line 31 of Mojolicious/Controller.pm # once (6µs+153µs) by Mojo::Loader::load at line 23 of Mojolicious/Controller.pm
sub get_data {
1711229µs my ($self, $data, $class) = @_;
172
173 # All data
17441.50ms my $all = $self->get_all_data($class);
# spent 1.50ms making 4 calls to Mojo::Command::get_all_data, avg 375µs/call
175
176 return $all->{$data};
177}
178
179# "You don’t like your job, you don’t strike.
180# You go in every day and do it really half-assed. That’s the American way."
181sub help {
182 my $self = shift;
183 print $self->usage;
184 exit;
185}
186
187sub rel_dir {
188 my ($self, $path) = @_;
189
190 # Parts
191 my @parts = split /\//, $path;
192
193 # Render
194 return File::Spec->catdir(Cwd::getcwd(), @parts);
195}
196
197sub rel_file {
198 my ($self, $path) = @_;
199
200 # Parts
201 my @parts = split /\//, $path;
202
203 # Render
204 return File::Spec->catfile(Cwd::getcwd(), @parts);
205}
206
207sub render_data {
208 my $self = shift;
209 my $data = shift;
210
211 # Get data
212 my $template = $self->get_data($data);
213
214 # Render
215 return $self->renderer->render($template, @_);
216}
217
218sub render_to_file {
219 my $self = shift;
220 my $data = shift;
221 my $path = shift;
222
223 # Render
224 my $content = $self->render_data($data, @_);
225
226 # Write
227 $self->write_file($path, $content);
228
229 return $self;
230}
231
232sub render_to_rel_file {
233 my $self = shift;
234 my $data = shift;
235 my $path = shift;
236
237 # Path
238 $path = $self->rel_dir($path);
239
240 # Render
241 $self->render_to_file($data, $path, @_);
242}
243
244# "My cat's breath smells like cat food."
245
# spent 21.3s (73µs+21.3) within Mojo::Command::run which was called: # once (73µs+21.3s) by Mojo::Command::start at line 368
sub run {
2461853µs my ($self, $name, @args) = @_;
247
248 # Hypnotoad
249 return Mojo::Server->new->app if defined $ENV{HYPNOTOAD_APP};
250
251 # Try to detect environment
25216µs $name = $self->detect($name) unless $ENV{MOJO_NO_DETECT};
# spent 6µs making 1 call to Mojo::Command::detect
253
254 # Run command
25513µs if ($name && $name =~ /^\w+$/ && ($name ne 'help' || $args[0])) {
# spent 3µs making 1 call to Mojo::Command::CORE:match
256
257 # Help
258 my $help = $name eq 'help' ? 1 : 0;
259 $name = shift @args if $help;
260
261 # Try all namespaces
262 my $module;
263114µs for my $namespace (@{$self->namespaces}) {
264
265 # Generate module
266 my $camelized = $name;
267116µs camelize $camelized;
# spent 16µs making 1 call to Mojo::Util::camelize
268 my $try = "$namespace\::$camelized";
269
270 # Load
27111.08ms if (my $e = Mojo::Loader->load($try)) {
# spent 1.08ms making 1 call to Mojo::Loader::load
272
273 # Module missing
274 next unless ref $e;
275
276 # Real error
277 die $e;
278 }
279
280 # Module is a command
28124µs next unless $try->can('new') && $try->can('run');
# spent 4µs making 2 calls to UNIVERSAL::can, avg 2µs/call
282
283 # Found
284 $module = $try;
285 last;
286 }
287
288 # Command missing
289 die qq/Command "$name" missing, maybe you need to install it?\n/
290 unless $module;
291
292 # Run
29318µs my $command = $module->new;
# spent 8µs making 1 call to Mojo::Base::new
294121.3s return $help ? $command->help : $command->run(@args);
# spent 21.3s making 1 call to Mojolicious::Command::Daemon::run
295 }
296
297 # Test
298 return $self if $ENV{HARNESS_ACTIVE};
299
300 # Try all namespaces
301 my $commands = [];
302 my $seen = {};
303 for my $namespace (@{$self->namespaces}) {
304
305 # Search
306 if (my $modules = Mojo::Loader->search($namespace)) {
307 for my $module (@$modules) {
308
309 # Load
310 if (my $e = Mojo::Loader->load($module)) { die $e }
311
312 # Seen
313 my $command = $module;
314 $command =~ s/^$namespace\:://;
315 push @$commands, [$command => $module]
316 unless $seen->{$command};
317 $seen->{$command} = 1;
318 }
319 }
320 }
321
322 # Print overview
323 print $self->message;
324
325 # Make list
326 my $list = [];
327 my $len = 0;
328 foreach my $command (@$commands) {
329
330 # Generate name
331 my $name = $command->[0];
332 decamelize $name;
333
334 # Add to list
335 my $l = length $name;
336 $len = $l if $l > $len;
337 push @$list, [$name, $command->[1]->new->description];
338 }
339
340 # Print list
341 foreach my $command (@$list) {
342 my $name = $command->[0];
343 my $description = $command->[1];
344 my $padding = ' ' x ($len - length $name);
345 print " $name$padding $description";
346 }
347
348 # Hint
349 print $self->hint;
350
351 return $self;
352}
353
354
# spent 21.3s (30µs+21.3) within Mojo::Command::start which was called: # once (30µs+21.3s) by Mojolicious::start at line 301 of Mojolicious.pm
sub start {
355619µs my $self = shift;
356
357 # Don't run commands if we are reloading
358 return $self if $ENV{MOJO_COMMANDS_DONE};
359 $ENV{MOJO_COMMANDS_DONE} ||= 1;
360
361 # Executable
362 $ENV{MOJO_EXE} ||= (caller)[1] if $ENV{MOJO_APP};
363
364 # Arguments
365 my @args = @_ ? @_ : @ARGV;
366
367 # Run
368221.3s return ref $self ? $self->run(@args) : $self->new->run(@args);
# spent 21.3s making 1 call to Mojo::Command::run # spent 12µs making 1 call to Mojo::Base::new
369}
370
371sub write_file {
372 my ($self, $path, $data) = @_;
373
374 # Directory
375 my @parts = File::Spec->splitdir($path);
376 pop @parts;
377 my $dir = File::Spec->catdir(@parts);
378 $self->create_dir($dir);
379
380 # Open file
381 my $file = IO::File->new;
382 $file->open(">$path") or croak qq/Can't open file "$path": $!/;
383
384 # Write unbuffered
385 $file->syswrite($data);
386
387 print " [write] $path\n" unless $self->quiet;
388 return $self;
389}
390
391sub write_rel_file {
392 my ($self, $path, $data) = @_;
393
394 # Path
395 $path = $self->rel_file($path);
396
397 # Write
398 $self->write_file($path, $data);
399}
400
401117µs1;
402__END__
 
# spent 18µs within Mojo::Command::CORE:close which was called: # once (18µs+0s) by Mojo::Command::get_all_data at line 138
sub Mojo::Command::CORE:close; # opcode
# spent 3µs within Mojo::Command::CORE:match which was called: # once (3µs+0s) by Mojo::Command::run at line 255
sub Mojo::Command::CORE:match; # opcode
# spent 546µs within Mojo::Command::CORE:readline which was called: # once (546µs+0s) by Mojo::Command::get_all_data at line 135
sub Mojo::Command::CORE:readline; # opcode
# spent 6µs within Mojo::Command::CORE:seek which was called: # once (6µs+0s) by Mojo::Command::get_all_data at line 132
sub Mojo::Command::CORE:seek; # opcode
# spent 474µs within Mojo::Command::CORE:subst which was called 24 times, avg 20µs/call: # 16 times (4µs+0s) by Mojo::Command::get_all_data at line 162, avg 281ns/call # 4 times (449µs+0s) by Mojo::Command::get_all_data at line 145, avg 112µs/call # 4 times (21µs+0s) by Mojo::Command::get_all_data at line 148, avg 5µs/call
sub Mojo::Command::CORE:subst; # opcode