Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/MouseX/Getopt/Basic.pm |
Statements | Executed 458 statements in 4.74ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 913µs | 10.3ms | _attrs_to_options | MouseX::Getopt::Basic::
1 | 1 | 1 | 618µs | 4.88ms | _compute_getopt_attrs | MouseX::Getopt::Basic::
22 | 1 | 1 | 601µs | 1.83ms | _get_cmd_flags_for_attr | MouseX::Getopt::Basic::
1 | 1 | 1 | 509µs | 1.16ms | BEGIN@12 | MouseX::Getopt::Basic::
1 | 1 | 1 | 351µs | 517µs | CORE:sort (opcode) | MouseX::Getopt::Basic::
1 | 1 | 1 | 330µs | 4.73ms | BEGIN@13 | MouseX::Getopt::Basic::
1 | 1 | 1 | 291µs | 2.05ms | BEGIN@14 | MouseX::Getopt::Basic::
1 | 1 | 1 | 86µs | 67.6ms | new_with_options | MouseX::Getopt::Basic::
1 | 1 | 1 | 79µs | 48.6ms | _parse_argv | MouseX::Getopt::Basic::
1 | 1 | 1 | 19µs | 19µs | BEGIN@2 | MouseX::Getopt::Basic::
11 | 1 | 1 | 18µs | 18µs | CORE:match (opcode) | MouseX::Getopt::Basic::
1 | 1 | 1 | 14µs | 43µs | BEGIN@17 | MouseX::Getopt::Basic::
1 | 1 | 1 | 12µs | 383µs | BEGIN@10 | MouseX::Getopt::Basic::
1 | 1 | 1 | 12µs | 102µs | BEGIN@235 | MouseX::Getopt::Basic::
1 | 1 | 1 | 6µs | 6µs | BEGIN@15 | MouseX::Getopt::Basic::
1 | 1 | 1 | 5µs | 5µs | BEGIN@5 | MouseX::Getopt::Basic::
1 | 1 | 1 | 3µs | 3µs | _usage_format | MouseX::Getopt::Basic::
0 | 0 | 0 | 0s | 0s | __ANON__[:100] | MouseX::Getopt::Basic::
0 | 0 | 0 | 0s | 0s | _getopt_full_usage | MouseX::Getopt::Basic::
0 | 0 | 0 | 0s | 0s | _getopt_get_options | MouseX::Getopt::Basic::
0 | 0 | 0 | 0s | 0s | _getopt_spec | MouseX::Getopt::Basic::
0 | 0 | 0 | 0s | 0s | _getopt_spec_exception | MouseX::Getopt::Basic::
0 | 0 | 0 | 0s | 0s | _getopt_spec_warnings | MouseX::Getopt::Basic::
0 | 0 | 0 | 0s | 0s | _traditional_spec | MouseX::Getopt::Basic::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package 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 | ||||
3 | 1 | 6µs | $MouseX::Getopt::Basic::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 23µs | 1 | 19µ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 | ||||
6 | 1 | 5µs | $MouseX::Getopt::Basic::VERSION = '0.33'; | ||
7 | 1 | 18µs | 1 | 5µ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 | |||||
10 | 2 | 30µs | 2 | 754µ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 # spent 383µs making 1 call to MouseX::Getopt::Basic::BEGIN@10
# spent 371µs making 1 call to Mouse::Exporter::do_import |
11 | |||||
12 | 2 | 145µs | 1 | 1.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 # spent 1.16ms making 1 call to MouseX::Getopt::Basic::BEGIN@12 |
13 | 2 | 162µs | 1 | 4.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 # spent 4.73ms making 1 call to MouseX::Getopt::Basic::BEGIN@13 |
14 | 2 | 149µs | 1 | 2.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 # spent 2.05ms making 1 call to MouseX::Getopt::Basic::BEGIN@14 |
15 | 2 | 26µs | 1 | 6µ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 # spent 6µs making 1 call to MouseX::Getopt::Basic::BEGIN@15 |
16 | |||||
17 | 3 | 920µs | 2 | 73µ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 # spent 43µs making 1 call to MouseX::Getopt::Basic::BEGIN@17
# spent 30µs making 1 call to Getopt::Long::VERSION |
18 | |||||
19 | 1 | 5µs | 1 | 38µs | has ARGV => (is => 'rw', isa => 'ArrayRef', metaclass => "NoGetopt"); # spent 38µs making 1 call to Mouse::Role::has |
20 | 1 | 4µs | 1 | 31µs | has 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 | ||||
23 | 9 | 61µs | my ($class, @params) = @_; | ||
24 | |||||
25 | my $config_from_file; | ||||
26 | 2 | 177µ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 | |||||
62 | 2 | 58.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? | ||||
72 | 1 | 2µs | 1 | 766µ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( | ||||
78 | 1 | 305µs | 42 | 14.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 | |||||
86 | sub _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 | ||||
89 | 12 | 56µs | my ( $class, %params ) = @_; | ||
90 | |||||
91 | local @ARGV = @{ $params{params}{argv} || \@ARGV }; | ||||
92 | |||||
93 | 1 | 282µ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 | 2 | 17µs | my ( $parsed_options, $usage ) = eval { | ||
100 | local $SIG{__WARN__} = sub { push @warnings, @_ }; | ||||
101 | |||||
102 | 1 | 48.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 | |||||
126 | sub _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 | |||||
133 | sub _getopt_spec_warnings { } | ||||
134 | |||||
135 | sub _getopt_spec_exception { | ||||
136 | my ($self, $warnings, $exception) = @_; | ||||
137 | die @$warnings, $exception; | ||||
138 | } | ||||
139 | |||||
140 | sub _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 | ||||
146 | 1 | 6µs | return "usage: %c %o"; | ||
147 | } | ||||
148 | |||||
149 | sub _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 | ||||
167 | 67 | 610µs | my $class = shift; | ||
168 | 180 | 278µ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 { | ||||
170 | 38 | 104µ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 { | ||||
174 | 66 | 382µs | 7 | 1.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 | ||||
179 | 110 | 365µs | my ( $class, $attr ) = @_; | ||
180 | |||||
181 | 22 | 32µ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 | |||||
185 | 34 | 329µs | 22 | 63µs | if ($attr->does('MouseX::Getopt::Meta::Attribute::Trait')) { # spent 63µs making 22 calls to Mouse::Util::does, avg 3µs/call |
186 | 34 | 51µ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 | ||
187 | 33 | 47µ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 | ||||
194 | 5 | 23µs | my $class = shift; | ||
195 | my $config_from_file = shift || {}; | ||||
196 | |||||
197 | my @options; | ||||
198 | |||||
199 | 1 | 4.88ms | foreach my $attr ($class->_compute_getopt_attrs) { # spent 4.88ms making 1 call to MouseX::Getopt::Basic::_compute_getopt_attrs | ||
200 | 88 | 796µs | 22 | 3.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 | |||||
204 | 44 | 268µs | 44 | 64µ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) { | ||||
208 | 22 | 33µs | my $type = $attr->type_constraint; # spent 33µs making 22 calls to Mouse::Meta::Attribute::type_constraint, avg 1µs/call | ||
209 | 44 | 551µ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 | |||||
214 | 88 | 121µ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 | |||||
235 | 2 | 23µs | 2 | 192µ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 # spent 102µs making 1 call to MouseX::Getopt::Basic::BEGIN@235
# spent 90µs making 1 call to Mouse::Exporter::do_unimport |
236 | 1 | 6µs | 1; | ||
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 | |||||
# 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 |