← Index
NYTProf Performance Profile   « line view »
For svc/members/upsert
  Run on Tue Jan 13 11:50:22 2015
Reported on Tue Jan 13 12:09:47 2015

Filename/usr/share/perl5/Data/OptList.pm
StatementsExecuted 17 statements in 2.12ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1112.25ms2.96msData::OptList::::BEGIN@10Data::OptList::BEGIN@10
1112.02ms2.22msData::OptList::::BEGIN@11Data::OptList::BEGIN@11
11112µs19µsData::OptList::::BEGIN@100Data::OptList::BEGIN@100
11111µs23µsClass::Load::::BEGIN@1 Class::Load::BEGIN@1
1117µs11µsClass::Load::::BEGIN@2 Class::Load::BEGIN@2
1116µs6µsData::OptList::::BEGIN@15Data::OptList::BEGIN@15
1114µs4µsData::OptList::::BEGIN@9Data::OptList::BEGIN@9
0000s0sData::OptList::::__ANON__[:27]Data::OptList::__ANON__[:27]
0000s0sData::OptList::::__ANON__[:54]Data::OptList::__ANON__[:54]
0000s0sData::OptList::::__is_aData::OptList::__is_a
0000s0sData::OptList::::mkoptData::OptList::mkopt
0000s0sData::OptList::::mkopt_hashData::OptList::mkopt_hash
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1222µs234µs
# spent 23µs (11+12) within Class::Load::BEGIN@1 which was called: # once (11µs+12µs) by Class::Load::BEGIN@10 at line 1
use strict;
# spent 23µs making 1 call to Class::Load::BEGIN@1 # spent 12µs making 1 call to strict::import
2245µs215µs
# spent 11µs (7+4) within Class::Load::BEGIN@2 which was called: # once (7µs+4µs) by Class::Load::BEGIN@10 at line 2
use warnings;
# spent 11µs making 1 call to Class::Load::BEGIN@2 # spent 4µs making 1 call to warnings::import
3package Data::OptList;
4{
52900ns $Data::OptList::VERSION = '0.109';
6}
7# ABSTRACT: parse and validate simple name/value option pairs
8
9220µs14µs
# spent 4µs within Data::OptList::BEGIN@9 which was called: # once (4µs+0s) by Class::Load::BEGIN@10 at line 9
use List::Util ();
# spent 4µs making 1 call to Data::OptList::BEGIN@9
102826µs12.96ms
# spent 2.96ms (2.25+714µs) within Data::OptList::BEGIN@10 which was called: # once (2.25ms+714µs) by Class::Load::BEGIN@10 at line 10
use Params::Util ();
# spent 2.96ms making 1 call to Data::OptList::BEGIN@10
113782µs22.23ms
# spent 2.22ms (2.02+205µs) within Data::OptList::BEGIN@11 which was called: # once (2.02ms+205µs) by Class::Load::BEGIN@10 at line 11
use Sub::Install 0.921 ();
# spent 2.22ms making 1 call to Data::OptList::BEGIN@11 # spent 9µs making 1 call to UNIVERSAL::VERSION
12
13
141200nsmy %test_for;
15
# spent 6µs within Data::OptList::BEGIN@15 which was called: # once (6µs+0s) by Class::Load::BEGIN@10 at line 22
BEGIN {
1616µs %test_for = (
17 CODE => \&Params::Util::_CODELIKE, ## no critic
18 HASH => \&Params::Util::_HASHLIKE, ## no critic
19 ARRAY => \&Params::Util::_ARRAYLIKE, ## no critic
20 SCALAR => \&Params::Util::_SCALAR0, ## no critic
21 );
221390µs16µs}
# spent 6µs making 1 call to Data::OptList::BEGIN@15
23
24sub __is_a {
25 my ($got, $expected) = @_;
26
27 return List::Util::first { __is_a($got, $_) } @$expected if ref $expected;
28
29 return defined (
30 exists($test_for{$expected})
31 ? $test_for{$expected}->($got)
32 : Params::Util::_INSTANCE($got, $expected) ## no critic
33 );
34}
35
36sub mkopt {
37 my ($opt_list) = shift;
38
39 my ($moniker, $require_unique, $must_be); # the old positional args
40 my $name_test;
41
42 if (@_ == 1 and Params::Util::_HASHLIKE($_[0])) {
43 my $arg = $_[0];
44 ($moniker, $require_unique, $must_be, $name_test)
45 = @$arg{ qw(moniker require_unique must_be name_test) };
46 } else {
47 ($moniker, $require_unique, $must_be) = @_;
48 }
49
50 $moniker = 'unnamed' unless defined $moniker;
51
52 return [] unless $opt_list;
53
54 $name_test ||= sub { ! ref $_[0] };
55
56 $opt_list = [
57 map { $_ => (ref $opt_list->{$_} ? $opt_list->{$_} : ()) } keys %$opt_list
58 ] if ref $opt_list eq 'HASH';
59
60 my @return;
61 my %seen;
62
63 for (my $i = 0; $i < @$opt_list; $i++) { ## no critic
64 my $name = $opt_list->[$i];
65 my $value;
66
67 if ($require_unique) {
68 Carp::croak "multiple definitions provided for $name" if $seen{$name}++;
69 }
70
71 if ($i == $#$opt_list) { $value = undef; }
72 elsif (not defined $opt_list->[$i+1]) { $value = undef; $i++ }
73 elsif ($name_test->($opt_list->[$i+1])) { $value = undef; }
74 else { $value = $opt_list->[++$i] }
75
76 if ($must_be and defined $value) {
77 unless (__is_a($value, $must_be)) {
78 my $ref = ref $value;
79 Carp::croak "$ref-ref values are not valid in $moniker opt list";
80 }
81 }
82
83 push @return, [ $name => $value ];
84 }
85
86 return \@return;
87}
88
89
90sub mkopt_hash {
91 my ($opt_list, $moniker, $must_be) = @_;
92 return {} unless $opt_list;
93
94 $opt_list = mkopt($opt_list, $moniker, 1, $must_be);
95 my %hash = map { $_->[0] => $_->[1] } @$opt_list;
96 return \%hash;
97}
98
99
100
# spent 19µs (12+7) within Data::OptList::BEGIN@100 which was called: # once (12µs+7µs) by Class::Load::BEGIN@10 at line 104
BEGIN {
10115µs17µs *import = Sub::Install::exporter {
# spent 7µs making 1 call to Sub::Install::exporter
102 exports => [qw(mkopt mkopt_hash)],
103 };
104122µs119µs}
# spent 19µs making 1 call to Data::OptList::BEGIN@100
105
10612µs1;
107
108__END__