| Filename | /Users/marcus/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Mojo/Command.pm |
| Statements | Executed 189 statements in 3.68ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2.02ms | 7.39ms | Mojo::Command::BEGIN@11 |
| 1 | 1 | 1 | 546µs | 546µs | Mojo::Command::CORE:readline (opcode) |
| 24 | 3 | 1 | 474µs | 474µs | Mojo::Command::CORE:subst (opcode) |
| 5 | 2 | 2 | 468µs | 1.51ms | Mojo::Command::get_all_data |
| 1 | 1 | 1 | 73µs | 21.3s | Mojo::Command::run |
| 1 | 1 | 1 | 30µs | 21.3s | Mojo::Command::start |
| 4 | 4 | 1 | 28µs | 1.53ms | Mojo::Command::get_data |
| 1 | 1 | 1 | 18µs | 18µs | Mojo::Command::CORE:close (opcode) |
| 1 | 1 | 1 | 14µs | 53µs | Mojo::Command::BEGIN@2 |
| 2 | 2 | 2 | 14µs | 14µs | Mojo::Command::detect |
| 1 | 1 | 1 | 11µs | 12µs | Mojo::Command::BEGIN@12 |
| 1 | 1 | 1 | 9µs | 11µs | Mojo::Command::BEGIN@10 |
| 1 | 1 | 1 | 7µs | 19µs | Mojo::Command::BEGIN@126 |
| 1 | 1 | 1 | 7µs | 31µs | Mojo::Command::BEGIN@9 |
| 1 | 1 | 1 | 6µs | 40µs | Mojo::Command::BEGIN@13 |
| 1 | 1 | 1 | 6µs | 6µs | Mojo::Command::CORE:seek (opcode) |
| 1 | 1 | 1 | 3µs | 3µs | Mojo::Command::CORE:match (opcode) |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::__ANON__[:28] |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::__ANON__[:30] |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::chmod_file |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::chmod_rel_file |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::class_to_file |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::class_to_path |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::create_dir |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::create_rel_dir |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::help |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::rel_dir |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::rel_file |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::render_data |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::render_to_file |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::render_to_rel_file |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::write_file |
| 0 | 0 | 0 | 0s | 0s | Mojo::Command::write_rel_file |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Mojo::Command; | ||||
| 2 | 3 | 59µs | 2 | 53µ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 # 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 | |||||
| 4 | 1 | 150µs | require Cwd; | ||
| 5 | 1 | 119µs | require File::Path; | ||
| 6 | 1 | 500ns | require File::Spec; | ||
| 7 | 1 | 300ns | require IO::File; | ||
| 8 | |||||
| 9 | 3 | 22µs | 2 | 55µ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 # spent 31µs making 1 call to Mojo::Command::BEGIN@9
# spent 24µs making 1 call to Exporter::import |
| 10 | 3 | 21µs | 2 | 11µ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 # 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 |
| 11 | 3 | 162µs | 2 | 7.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 # 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 |
| 12 | 3 | 25µs | 2 | 12µ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 # 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 |
| 13 | 3 | 448µs | 2 | 74µ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 # spent 40µs making 1 call to Mojo::Command::BEGIN@13
# spent 34µs making 1 call to Exporter::import |
| 14 | |||||
| 15 | 1 | 4µs | 1 | 98µs | has hint => <<"EOF"; # spent 98µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38] |
| 16 | |||||
| 17 | See '$0 help COMMAND' for more information on a specific command. | ||||
| 18 | EOF | ||||
| 19 | 1 | 2µs | 1 | 95µs | has description => 'No description.'; # spent 95µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38] |
| 20 | 1 | 3µs | 1 | 90µs | has message => <<"EOF"; # spent 90µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38] |
| 21 | usage: $0 COMMAND [OPTIONS] | ||||
| 22 | |||||
| 23 | Tip: CGI, FastCGI and PSGI environments can be automatically detected very | ||||
| 24 | often and work without commands. | ||||
| 25 | |||||
| 26 | These commands are currently available: | ||||
| 27 | EOF | ||||
| 28 | 1 | 3µs | 1 | 99µs | has namespaces => sub { ['Mojo::Command'] }; # spent 99µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38] |
| 29 | 1 | 2µs | 1 | 91µs | has quiet => 0; # spent 91µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38] |
| 30 | 1 | 8µs | 1 | 103µs | has renderer => sub { Mojo::Template->new }; # spent 103µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38] |
| 31 | 1 | 3µs | 1 | 104µs | has usage => "usage: $0\n"; # spent 104µs making 1 call to Mojo::Base::__ANON__[Mojo/Base.pm:38] |
| 32 | |||||
| 33 | # Cache | ||||
| 34 | 1 | 400ns | my $CACHE = {}; | ||
| 35 | |||||
| 36 | sub 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 | |||||
| 47 | sub 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 | |||||
| 57 | sub 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 | |||||
| 67 | sub 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 | |||||
| 76 | sub 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 | |||||
| 91 | sub 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 | ||||
| 102 | 10 | 17µ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 | ||||
| 122 | 109 | 1.50ms | my ($self, $class) = @_; | ||
| 123 | $class ||= ref $self; | ||||
| 124 | |||||
| 125 | # Handle | ||||
| 126 | 3 | 1.01ms | 2 | 31µ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 # 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 | ||||
| 132 | 1 | 6µs | seek $d, 0, 0; # spent 6µs making 1 call to Mojo::Command::CORE:seek | ||
| 133 | |||||
| 134 | # Slurp | ||||
| 135 | 1 | 546µs | $CACHE->{$class} = join '', <$d>; # spent 546µs making 1 call to Mojo::Command::CORE:readline | ||
| 136 | |||||
| 137 | # Close | ||||
| 138 | 1 | 18µ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) | ||||
| 145 | 4 | 449µ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__ | ||||
| 148 | 4 | 21µ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 | ||||
| 162 | 16 | 4µ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 | ||||
| 171 | 12 | 29µs | my ($self, $data, $class) = @_; | ||
| 172 | |||||
| 173 | # All data | ||||
| 174 | 4 | 1.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." | ||||
| 181 | sub help { | ||||
| 182 | my $self = shift; | ||||
| 183 | print $self->usage; | ||||
| 184 | exit; | ||||
| 185 | } | ||||
| 186 | |||||
| 187 | sub 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 | |||||
| 197 | sub 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 | |||||
| 207 | sub 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 | |||||
| 218 | sub 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 | |||||
| 232 | sub 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 | ||||
| 246 | 18 | 53µ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 | ||||
| 252 | 1 | 6µs | $name = $self->detect($name) unless $ENV{MOJO_NO_DETECT}; # spent 6µs making 1 call to Mojo::Command::detect | ||
| 253 | |||||
| 254 | # Run command | ||||
| 255 | 1 | 3µ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; | ||||
| 263 | 1 | 14µs | for my $namespace (@{$self->namespaces}) { # spent 14µs making 1 call to Mojo::Base::__ANON__[(eval 183)[Mojo/Base.pm:123]:8] | ||
| 264 | |||||
| 265 | # Generate module | ||||
| 266 | my $camelized = $name; | ||||
| 267 | 1 | 16µs | camelize $camelized; # spent 16µs making 1 call to Mojo::Util::camelize | ||
| 268 | my $try = "$namespace\::$camelized"; | ||||
| 269 | |||||
| 270 | # Load | ||||
| 271 | 1 | 1.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 | ||||
| 281 | 2 | 4µ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 | ||||
| 293 | 1 | 8µs | my $command = $module->new; # spent 8µs making 1 call to Mojo::Base::new | ||
| 294 | 1 | 21.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 | ||||
| 355 | 6 | 19µ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 | ||||
| 368 | 2 | 21.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 | |||||
| 371 | sub 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 | |||||
| 391 | sub 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 | |||||
| 401 | 1 | 17µs | 1; | ||
| 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 | |||||
# spent 3µs within Mojo::Command::CORE:match which was called:
# once (3µs+0s) by Mojo::Command::run at line 255 | |||||
# spent 546µs within Mojo::Command::CORE:readline which was called:
# once (546µs+0s) by Mojo::Command::get_all_data at line 135 | |||||
# spent 6µs within Mojo::Command::CORE:seek which was called:
# once (6µs+0s) by Mojo::Command::get_all_data at line 132 | |||||
# 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 |