← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/hailo
  Run on Thu Oct 21 22:50:37 2010
Reported on Thu Oct 21 22:52:05 2010

Filename/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/MouseX/Getopt/Basic.pm
StatementsExecuted 458 statements in 4.74ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111913µs10.3msMouseX::Getopt::Basic::::_attrs_to_optionsMouseX::Getopt::Basic::_attrs_to_options
111618µs4.88msMouseX::Getopt::Basic::::_compute_getopt_attrsMouseX::Getopt::Basic::_compute_getopt_attrs
2211601µs1.83msMouseX::Getopt::Basic::::_get_cmd_flags_for_attrMouseX::Getopt::Basic::_get_cmd_flags_for_attr
111509µs1.16msMouseX::Getopt::Basic::::BEGIN@12MouseX::Getopt::Basic::BEGIN@12
111351µs517µsMouseX::Getopt::Basic::::CORE:sortMouseX::Getopt::Basic::CORE:sort (opcode)
111330µs4.73msMouseX::Getopt::Basic::::BEGIN@13MouseX::Getopt::Basic::BEGIN@13
111291µs2.05msMouseX::Getopt::Basic::::BEGIN@14MouseX::Getopt::Basic::BEGIN@14
11186µs67.6msMouseX::Getopt::Basic::::new_with_optionsMouseX::Getopt::Basic::new_with_options
11179µs48.6msMouseX::Getopt::Basic::::_parse_argvMouseX::Getopt::Basic::_parse_argv
11119µs19µsMouseX::Getopt::Basic::::BEGIN@2MouseX::Getopt::Basic::BEGIN@2
111118µs18µsMouseX::Getopt::Basic::::CORE:matchMouseX::Getopt::Basic::CORE:match (opcode)
11114µs43µsMouseX::Getopt::Basic::::BEGIN@17MouseX::Getopt::Basic::BEGIN@17
11112µs383µsMouseX::Getopt::Basic::::BEGIN@10MouseX::Getopt::Basic::BEGIN@10
11112µs102µsMouseX::Getopt::Basic::::BEGIN@235MouseX::Getopt::Basic::BEGIN@235
1116µs6µsMouseX::Getopt::Basic::::BEGIN@15MouseX::Getopt::Basic::BEGIN@15
1115µs5µsMouseX::Getopt::Basic::::BEGIN@5MouseX::Getopt::Basic::BEGIN@5
1113µs3µsMouseX::Getopt::Basic::::_usage_formatMouseX::Getopt::Basic::_usage_format
0000s0sMouseX::Getopt::Basic::::__ANON__[:100]MouseX::Getopt::Basic::__ANON__[:100]
0000s0sMouseX::Getopt::Basic::::_getopt_full_usageMouseX::Getopt::Basic::_getopt_full_usage
0000s0sMouseX::Getopt::Basic::::_getopt_get_optionsMouseX::Getopt::Basic::_getopt_get_options
0000s0sMouseX::Getopt::Basic::::_getopt_specMouseX::Getopt::Basic::_getopt_spec
0000s0sMouseX::Getopt::Basic::::_getopt_spec_exceptionMouseX::Getopt::Basic::_getopt_spec_exception
0000s0sMouseX::Getopt::Basic::::_getopt_spec_warningsMouseX::Getopt::Basic::_getopt_spec_warnings
0000s0sMouseX::Getopt::Basic::::_traditional_specMouseX::Getopt::Basic::_traditional_spec
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package MouseX::Getopt::Basic;
2
# spent 19µs within MouseX::Getopt::Basic::BEGIN@2 which was called: # once (19µs+0s) by Mouse::Util::_try_load_one_class at line 4
BEGIN {
316µs $MouseX::Getopt::Basic::AUTHORITY = 'cpan:STEVAN';
4123µs119µs}
# spent 19µs making 1 call to MouseX::Getopt::Basic::BEGIN@2
5
# spent 5µs within MouseX::Getopt::Basic::BEGIN@5 which was called: # once (5µs+0s) by Mouse::Util::_try_load_one_class at line 7
BEGIN {
615µs $MouseX::Getopt::Basic::VERSION = '0.33';
7118µs15µs}
# spent 5µs making 1 call to MouseX::Getopt::Basic::BEGIN@5
8# ABSTRACT: MouseX::Getopt::Basic - role to implement the Getopt::Long functionality
9
10230µs2754µs
# spent 383µs (12+371) within MouseX::Getopt::Basic::BEGIN@10 which was called: # once (12µs+371µs) by Mouse::Util::_try_load_one_class at line 10
use Mouse::Role;
# spent 383µs making 1 call to MouseX::Getopt::Basic::BEGIN@10 # spent 371µs making 1 call to Mouse::Exporter::do_import
11
122145µs11.16ms
# spent 1.16ms (509µs+653µs) within MouseX::Getopt::Basic::BEGIN@12 which was called: # once (509µs+653µs) by Mouse::Util::_try_load_one_class at line 12
use MouseX::Getopt::OptionTypeMap;
# spent 1.16ms making 1 call to MouseX::Getopt::Basic::BEGIN@12
132162µs14.73ms
# spent 4.73ms (330µs+4.40) within MouseX::Getopt::Basic::BEGIN@13 which was called: # once (330µs+4.40ms) by Mouse::Util::_try_load_one_class at line 13
use MouseX::Getopt::Meta::Attribute;
# spent 4.73ms making 1 call to MouseX::Getopt::Basic::BEGIN@13
142149µs12.05ms
# spent 2.05ms (291µs+1.76) within MouseX::Getopt::Basic::BEGIN@14 which was called: # once (291µs+1.76ms) by Mouse::Util::_try_load_one_class at line 14
use MouseX::Getopt::Meta::Attribute::NoGetopt;
# spent 2.05ms making 1 call to MouseX::Getopt::Basic::BEGIN@14
15226µs16µs
# spent 6µs within MouseX::Getopt::Basic::BEGIN@15 which was called: # once (6µs+0s) by Mouse::Util::_try_load_one_class at line 15
use Carp ();
# spent 6µs making 1 call to MouseX::Getopt::Basic::BEGIN@15
16
173920µs273µs
# spent 43µs (14+30) within MouseX::Getopt::Basic::BEGIN@17 which was called: # once (14µs+30µs) by Mouse::Util::_try_load_one_class at line 17
use Getopt::Long 2.37 ();
# spent 43µs making 1 call to MouseX::Getopt::Basic::BEGIN@17 # spent 30µs making 1 call to Getopt::Long::VERSION
18
1915µs138µshas ARGV => (is => 'rw', isa => 'ArrayRef', metaclass => "NoGetopt");
# spent 38µs making 1 call to Mouse::Role::has
2014µs131µshas extra_argv => (is => 'rw', isa => 'ArrayRef', metaclass => "NoGetopt");
# spent 31µs making 1 call to Mouse::Role::has
21
22
# spent 67.6ms (86µs+67.5) within MouseX::Getopt::Basic::new_with_options which was called: # once (86µs+67.5ms) by main::RUNTIME at line 35 of bin/hailo
sub new_with_options {
23961µs my ($class, @params) = @_;
24
25 my $config_from_file;
262177µs if($class->meta->does_role('MouseX::ConfigFromFile')) {
# spent 160µs making 1 call to Mouse::Meta::Class::does_role # spent 17µs making 1 call to Hailo::Command::meta
27 local @ARGV = @ARGV;
28
29 # just get the configfile arg now; the rest of the args will be
30 # fetched later
31 my $configfile;
32 my $opt_parser = Getopt::Long::Parser->new( config => [ qw( no_auto_help pass_through ) ] );
33 $opt_parser->getoptions( "configfile=s" => \$configfile );
34
35 if(!defined $configfile) {
36 my $cfmeta = $class->meta->find_attribute_by_name('configfile');
37 $configfile = $cfmeta->default if $cfmeta->has_default;
38 if (ref $configfile eq 'CODE') {
39 # not sure theres a lot you can do with the class and may break some assumptions
40 # warn?
41 $configfile = &$configfile($class);
42 }
43 if (defined $configfile) {
44 $config_from_file = eval {
45 $class->get_config_from_file($configfile);
46 };
47 if ($@) {
48 die $@ unless $@ =~ /Specified configfile '\Q$configfile\E' does not exist/;
49 }
50 }
51 }
52 else {
53 $config_from_file = $class->get_config_from_file($configfile);
54 }
55 }
56
57 my $constructor_params = ( @params == 1 ? $params[0] : {@params} );
58
59 Carp::croak("Single parameters to new_with_options() must be a HASH ref")
60 unless ref($constructor_params) eq 'HASH';
61
62258.9ms my %processed = $class->_parse_argv(
# spent 48.6ms making 1 call to MouseX::Getopt::Basic::_parse_argv # spent 10.3ms making 1 call to MouseX::Getopt::Basic::_attrs_to_options
63 options => [
64 $class->_attrs_to_options( $config_from_file )
65 ],
66 params => $constructor_params,
67 );
68
69 my $params = $config_from_file ? { %$config_from_file, %{$processed{params}} } : $processed{params};
70
71 # did the user request usage information?
7212µs1766µs if ( $processed{usage} and $params->{help_flag} )
# spent 766µs making 1 call to Getopt::Long::Descriptive::Usage::text
73 {
74 $class->_getopt_full_usage($processed{usage});
75 }
76
77 $class->new(
781305µs4214.3ms ARGV => $processed{argv_copy},
# spent 6.92ms making 1 call to Mouse::Object::new # spent 6.59ms making 1 call to Hailo::Command::__ANON__[lib/Hailo/Command.pm:59] # spent 708µs making 1 call to Getopt::Long::Descriptive::Usage::text # spent 29µs making 19 calls to Mouse::Meta::TypeConstraint::_compiled_type_constraint, avg 2µs/call # spent 22µs making 14 calls to Mouse::Meta::Attribute::default, avg 2µs/call # spent 21µs making 1 call to Hailo::Command::__ANON__[lib/Hailo/Command.pm:154] # spent 13µs making 4 calls to Hailo::__ANON__[lib/Hailo.pm:111], avg 3µs/call # spent 2µs making 1 call to Mouse::Meta::Attribute::trigger
79 extra_argv => $processed{argv},
80 ( $processed{usage} ? ( usage => $processed{usage} ) : () ),
81 %$constructor_params, # explicit params to ->new
82 %$params, # params from CLI
83 );
84}
85
86sub _getopt_spec { shift->_traditional_spec(@_); }
87
88
# spent 48.6ms (79µs+48.5) within MouseX::Getopt::Basic::_parse_argv which was called: # once (79µs+48.5ms) by MouseX::Getopt::Basic::new_with_options at line 62
sub _parse_argv {
891472µs my ( $class, %params ) = @_;
90
91 local @ARGV = @{ $params{params}{argv} || \@ARGV };
92
931282µs my ( $opt_spec, $name_to_init_arg ) = $class->_getopt_spec(%params);
# spent 282µs making 1 call to Hailo::Command::_getopt_spec
94
95 # Get a clean copy of the original @ARGV
96 my $argv_copy = [ @ARGV ];
97
98 my @warnings;
99 my ( $parsed_options, $usage ) = eval {
100 local $SIG{__WARN__} = sub { push @warnings, @_ };
101
102148.2ms return $class->_getopt_get_options(\%params, $opt_spec);
# spent 48.2ms making 1 call to Hailo::Command::_getopt_get_options
103 };
104 my $e = $@;
105
106 $class->_getopt_spec_warnings(@warnings) if @warnings;
107 $class->_getopt_spec_exception(\@warnings, $e) if $e;
108
109 # Get a copy of the Getopt::Long-mangled @ARGV
110 my $argv_mangled = [ @ARGV ];
111
112 my %constructor_args = (
113 map {
114 $name_to_init_arg->{$_} => $parsed_options->{$_}
115 } keys %$parsed_options,
116 );
117
118 return (
119 params => \%constructor_args,
120 argv_copy => $argv_copy,
121 argv => $argv_mangled,
122 ( defined($usage) ? ( usage => $usage ) : () ),
123 );
124}
125
126sub _getopt_get_options {
127 my ($class, $params, $opt_spec) = @_;
128 my %options;
129 Getopt::Long::GetOptions(\%options, @$opt_spec);
130 return ( \%options, undef );
131}
132
133sub _getopt_spec_warnings { }
134
135sub _getopt_spec_exception {
136 my ($self, $warnings, $exception) = @_;
137 die @$warnings, $exception;
138}
139
140sub _getopt_full_usage {
141 my ($self, $usage) = @_;
142 $usage->die;
143}
144
145
# spent 3µs within MouseX::Getopt::Basic::_usage_format which was called: # once (3µs+0s) by MouseX::Getopt::GLD::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/MouseX/Getopt/GLD.pm:39] at line 38 of MouseX/Getopt/GLD.pm
sub _usage_format {
14616µs return "usage: %c %o";
147}
148
149sub _traditional_spec {
150 my ( $class, %params ) = @_;
151
152 my ( @options, %name_to_init_arg, %options );
153
154 foreach my $opt ( @{ $params{options} } ) {
155 push @options, $opt->{opt_string};
156
157 my $identifier = $opt->{name};
158 $identifier =~ s/\W/_/g; # Getopt::Long does this to all option names
159
160 $name_to_init_arg{$identifier} = $opt->{init_arg};
161 }
162
163 return ( \@options, \%name_to_init_arg );
164}
165
166
# spent 4.88ms (618µs+4.26) within MouseX::Getopt::Basic::_compute_getopt_attrs which was called: # once (618µs+4.26ms) by MouseX::Getopt::Basic::_attrs_to_options at line 199
sub _compute_getopt_attrs {
167133962µs my $class = shift;
168180278µs sort { $a->insertion_order <=> $b->insertion_order }
# spent 166µs making 130 calls to Mouse::Meta::Attribute::insertion_order, avg 1µs/call # spent 77µs making 28 calls to Mouse::Util::does, avg 3µs/call # spent 18µs making 11 calls to MouseX::Getopt::Basic::CORE:match, avg 2µs/call # spent 17µs making 11 calls to Mouse::Meta::Attribute::name, avg 2µs/call
169 grep {
17038104µs $_->does("MouseX::Getopt::Meta::Attribute::Trait")
# spent 104µs making 38 calls to Mouse::Util::does, avg 3µs/call
171 or
172 $_->name !~ /^_/
173 } grep {
174130µs71.43ms !$_->does('MouseX::Getopt::Meta::Attribute::Trait::NoGetopt')
# spent 517µs making 1 call to MouseX::Getopt::Basic::CORE:sort # spent 467µs making 1 call to Mouse::Meta::Class::get_all_attributes # spent 431µs making 1 call to Mouse::Meta::Class::_calculate_all_attributes # spent 12µs making 1 call to Hailo::Command::meta # spent 2µs making 1 call to Mouse::Meta::Class::strict_constructor # spent 2µs making 1 call to Mouse::Meta::Class::is_immutable # spent 1µs making 1 call to Mouse::Meta::Class::is_anon_class
175 } $class->meta->get_all_attributes
176}
177
178
# spent 1.83ms (601µs+1.23) within MouseX::Getopt::Basic::_get_cmd_flags_for_attr which was called 22 times, avg 83µs/call: # 22 times (601µs+1.23ms) by MouseX::Getopt::Dashes::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/MouseX/Getopt/Dashes.pm:24] at line 18 of MouseX/Getopt/Dashes.pm, avg 83µs/call
sub _get_cmd_flags_for_attr {
179144693µs my ( $class, $attr ) = @_;
180
1812232µs my $flag = $attr->name;
# spent 32µs making 22 calls to Mouse::Meta::Attribute::name, avg 1µs/call
182
183 my @aliases;
184
1852263µs if ($attr->does('MouseX::Getopt::Meta::Attribute::Trait')) {
# spent 63µs making 22 calls to Mouse::Util::does, avg 3µs/call
1863451µs $flag = $attr->cmd_flag if $attr->has_cmd_flag;
# spent 27µs making 17 calls to Mouse::Meta::Class::__ANON__::2::has_cmd_flag, avg 2µs/call # spent 24µs making 17 calls to Mouse::Meta::Class::__ANON__::2::cmd_flag, avg 1µs/call
1873347µs @aliases = @{ $attr->cmd_aliases } if $attr->has_cmd_aliases;
# spent 26µs making 17 calls to Mouse::Meta::Class::__ANON__::2::has_cmd_aliases, avg 2µs/call # spent 22µs making 16 calls to Mouse::Meta::Class::__ANON__::2::cmd_aliases, avg 1µs/call
188 }
189
190 return ( $flag, @aliases );
191}
192
193
# spent 10.3ms (913µs+9.40) within MouseX::Getopt::Basic::_attrs_to_options which was called: # once (913µs+9.40ms) by MouseX::Getopt::Basic::new_with_options at line 62
sub _attrs_to_options {
1941371.09ms my $class = shift;
195 my $config_from_file = shift || {};
196
197 my @options;
198
19914.88ms foreach my $attr ($class->_compute_getopt_attrs) {
# spent 4.88ms making 1 call to MouseX::Getopt::Basic::_compute_getopt_attrs
200223.76ms my ( $flag, @aliases ) = $class->_get_cmd_flags_for_attr($attr);
# spent 3.76ms making 22 calls to Hailo::Command::_get_cmd_flags_for_attr, avg 171µs/call
201
202 my $opt_string = join(q{|}, $flag, @aliases);
203
2044464µs if ($attr->name eq 'configfile') {
# spent 33µs making 22 calls to Mouse::Meta::Attribute::name, avg 1µs/call # spent 31µs making 22 calls to Mouse::Meta::Attribute::has_type_constraint, avg 1µs/call
205 $opt_string .= '=s';
206 }
207 elsif ($attr->has_type_constraint) {
2082233µs my $type = $attr->type_constraint;
# spent 33µs making 22 calls to Mouse::Meta::Attribute::type_constraint, avg 1µs/call
20944551µs if (MouseX::Getopt::OptionTypeMap->has_option_type($type)) {
# spent 279µs making 22 calls to MouseX::Getopt::OptionTypeMap::get_option_type, avg 13µs/call # spent 272µs making 22 calls to MouseX::Getopt::OptionTypeMap::has_option_type, avg 12µs/call
210 $opt_string .= MouseX::Getopt::OptionTypeMap->get_option_type($type)
211 }
212 }
213
21488121µs push @options, {
# spent 34µs making 22 calls to Mouse::Meta::Attribute::init_arg, avg 2µs/call # spent 30µs making 22 calls to Mouse::Meta::Attribute::has_documentation, avg 1µs/call # spent 30µs making 22 calls to Mouse::Meta::Attribute::is_required, avg 1µs/call # spent 27µs making 22 calls to Mouse::Meta::Attribute::documentation, avg 1µs/call
215 name => $flag,
216 init_arg => $attr->init_arg,
217 opt_string => $opt_string,
218 required => $attr->is_required && !$attr->has_default && !$attr->has_builder && !exists $config_from_file->{$attr->name},
219 # NOTE:
220 # this "feature" was breaking because
221 # Getopt::Long::Descriptive would return
222 # the default value as if it was a command
223 # line flag, which would then override the
224 # one passed into a constructor.
225 # See 100_gld_default_bug.t for an example
226 # - SL
227 #( ( $attr->has_default && ( $attr->is_default_a_coderef xor $attr->is_lazy ) ) ? ( default => $attr->default({}) ) : () ),
228 ( $attr->has_documentation ? ( doc => $attr->documentation ) : () ),
229 }
230 }
231
232 return @options;
233}
234
235223µs2192µs
# spent 102µs (12+90) within MouseX::Getopt::Basic::BEGIN@235 which was called: # once (12µs+90µs) by Mouse::Util::_try_load_one_class at line 235
no Mouse::Role;
# spent 102µs making 1 call to MouseX::Getopt::Basic::BEGIN@235 # spent 90µs making 1 call to Mouse::Exporter::do_unimport
23616µs1;
237
238
239__END__
 
# spent 18µs within MouseX::Getopt::Basic::CORE:match which was called 11 times, avg 2µs/call: # 11 times (18µs+0s) by MouseX::Getopt::Basic::_compute_getopt_attrs at line 168, avg 2µs/call
sub MouseX::Getopt::Basic::CORE:match; # opcode
# spent 517µs (351+166) within MouseX::Getopt::Basic::CORE:sort which was called: # once (351µs+166µs) by MouseX::Getopt::Basic::_compute_getopt_attrs at line 174
sub MouseX::Getopt::Basic::CORE:sort; # opcode