Filename | C:/tmp64ng/perl/lib/Parse/CPAN/Meta.pm |
Statements | Executed 558 statements in 15.6ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
73 | 2 | 1 | 15.6ms | 31.2ms | _can_load | Parse::CPAN::Meta::
1 | 1 | 1 | 0s | 0s | BEGIN@1.7 | CPAN::Meta::Converter::
1 | 1 | 1 | 0s | 0s | BEGIN@2.8 | CPAN::Meta::Converter::
1 | 1 | 1 | 0s | 0s | BEGIN@45 | Parse::CPAN::Meta::
1 | 1 | 1 | 0s | 0s | BEGIN@7 | Parse::CPAN::Meta::
1 | 1 | 1 | 0s | 0s | BEGIN@8 | Parse::CPAN::Meta::
2 | 1 | 1 | 0s | 0s | CORE:match (opcode) | Parse::CPAN::Meta::
1 | 1 | 1 | 0s | 0s | CORE:open (opcode) | Parse::CPAN::Meta::
1 | 1 | 1 | 0s | 0s | CORE:readline (opcode) | Parse::CPAN::Meta::
73 | 1 | 1 | 0s | 0s | CORE:subst (opcode) | Parse::CPAN::Meta::
0 | 0 | 0 | 0s | 0s | Load | Parse::CPAN::Meta::
0 | 0 | 0 | 0s | 0s | LoadFile | Parse::CPAN::Meta::
1 | 1 | 1 | 0s | 0s | _slurp | Parse::CPAN::Meta::
64 | 3 | 3 | 0s | 15.6ms | json_backend | Parse::CPAN::Meta::
1 | 1 | 1 | 0s | 0s | load_file | Parse::CPAN::Meta::
1 | 1 | 1 | 0s | 0s | load_json_string | Parse::CPAN::Meta::
0 | 0 | 0 | 0s | 0s | load_string | Parse::CPAN::Meta::
0 | 0 | 0 | 0s | 0s | load_yaml_string | Parse::CPAN::Meta::
9 | 1 | 1 | 0s | 15.6ms | yaml_backend | Parse::CPAN::Meta::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 0s | 1 | 0s | # spent 0s within CPAN::Meta::Converter::BEGIN@1.7 which was called:
# once (0s+0s) by CPAN::Meta::Converter::BEGIN@27 at line 1 # spent 0s making 1 call to CPAN::Meta::Converter::BEGIN@1.7 |
2 | 2 | 0s | 2 | 0s | # spent 0s within CPAN::Meta::Converter::BEGIN@2.8 which was called:
# once (0s+0s) by CPAN::Meta::Converter::BEGIN@27 at line 2 # spent 0s making 1 call to CPAN::Meta::Converter::BEGIN@2.8
# spent 0s making 1 call to strict::import |
3 | package Parse::CPAN::Meta; | ||||
4 | # ABSTRACT: Parse META.yml and META.json CPAN metadata files | ||||
5 | 1 | 0s | our $VERSION = '1.4414'; # VERSION | ||
6 | |||||
7 | 2 | 0s | 2 | 0s | # spent 0s within Parse::CPAN::Meta::BEGIN@7 which was called:
# once (0s+0s) by CPAN::Meta::Converter::BEGIN@27 at line 7 # spent 0s making 1 call to Exporter::import
# spent 0s making 1 call to Parse::CPAN::Meta::BEGIN@7 |
8 | 2 | 0s | 2 | 0s | # spent 0s within Parse::CPAN::Meta::BEGIN@8 which was called:
# once (0s+0s) by CPAN::Meta::Converter::BEGIN@27 at line 8 # spent 0s making 1 call to Exporter::import
# spent 0s making 1 call to Parse::CPAN::Meta::BEGIN@8 |
9 | |||||
10 | 1 | 0s | our @ISA = qw/Exporter/; | ||
11 | 1 | 0s | our @EXPORT_OK = qw/Load LoadFile/; | ||
12 | |||||
13 | # spent 0s within Parse::CPAN::Meta::load_file which was called:
# once (0s+0s) by CPAN::Meta::load_file at line 300 of CPAN/Meta.pm | ||||
14 | 1 | 0s | my ($class, $filename) = @_; | ||
15 | |||||
16 | 1 | 0s | 1 | 0s | my $meta = _slurp($filename); # spent 0s making 1 call to Parse::CPAN::Meta::_slurp |
17 | |||||
18 | 1 | 0s | 3 | 0s | if ($filename =~ /\.ya?ml$/) { # spent 0s making 2 calls to Parse::CPAN::Meta::CORE:match, avg 0s/call
# spent 0s making 1 call to Parse::CPAN::Meta::load_json_string |
19 | return $class->load_yaml_string($meta); | ||||
20 | } | ||||
21 | elsif ($filename =~ /\.json$/) { | ||||
22 | return $class->load_json_string($meta); | ||||
23 | } | ||||
24 | else { | ||||
25 | $class->load_string($meta); # try to detect yaml/json | ||||
26 | } | ||||
27 | } | ||||
28 | |||||
29 | sub load_string { | ||||
30 | my ($class, $string) = @_; | ||||
31 | if ( $string =~ /^---/ ) { # looks like YAML | ||||
32 | return $class->load_yaml_string($string); | ||||
33 | } | ||||
34 | elsif ( $string =~ /^\s*\{/ ) { # looks like JSON | ||||
35 | return $class->load_json_string($string); | ||||
36 | } | ||||
37 | else { # maybe doc-marker-free YAML | ||||
38 | return $class->load_yaml_string($string); | ||||
39 | } | ||||
40 | } | ||||
41 | |||||
42 | sub load_yaml_string { | ||||
43 | my ($class, $string) = @_; | ||||
44 | my $backend = $class->yaml_backend(); | ||||
45 | 2 | 0s | 2 | 0s | # spent 0s within Parse::CPAN::Meta::BEGIN@45 which was called:
# once (0s+0s) by CPAN::Meta::Converter::BEGIN@27 at line 45 # spent 0s making 1 call to Parse::CPAN::Meta::BEGIN@45
# spent 0s making 1 call to strict::unimport |
46 | croak $@ if $@; | ||||
47 | return $data || {}; # in case document was valid but empty | ||||
48 | } | ||||
49 | |||||
50 | # spent 0s within Parse::CPAN::Meta::load_json_string which was called:
# once (0s+0s) by Parse::CPAN::Meta::load_file at line 18 | ||||
51 | 1 | 0s | my ($class, $string) = @_; | ||
52 | 2 | 0s | 3 | 0s | my $data = eval { $class->json_backend()->new->decode($string) }; # spent 0s making 1 call to JSON::PP::decode
# spent 0s making 1 call to JSON::PP::new
# spent 0s making 1 call to Parse::CPAN::Meta::json_backend |
53 | 1 | 0s | croak $@ if $@; | ||
54 | 1 | 0s | return $data || {}; | ||
55 | } | ||||
56 | |||||
57 | # spent 15.6ms (0s+15.6) within Parse::CPAN::Meta::yaml_backend which was called 9 times, avg 1.73ms/call:
# 9 times (0s+15.6ms) by CPAN::Meta::as_string at line 615 of CPAN/Meta.pm, avg 1.73ms/call | ||||
58 | 9 | 0s | if (! defined $ENV{PERL_YAML_BACKEND} ) { | ||
59 | 9 | 0s | 9 | 15.6ms | _can_load( 'CPAN::Meta::YAML', 0.011 ) # spent 15.6ms making 9 calls to Parse::CPAN::Meta::_can_load, avg 1.73ms/call |
60 | or croak "CPAN::Meta::YAML 0.011 is not available\n"; | ||||
61 | 9 | 0s | return "CPAN::Meta::YAML"; | ||
62 | } | ||||
63 | else { | ||||
64 | my $backend = $ENV{PERL_YAML_BACKEND}; | ||||
65 | _can_load( $backend ) | ||||
66 | or croak "Could not load PERL_YAML_BACKEND '$backend'\n"; | ||||
67 | $backend->can("Load") | ||||
68 | or croak "PERL_YAML_BACKEND '$backend' does not implement Load()\n"; | ||||
69 | return $backend; | ||||
70 | } | ||||
71 | } | ||||
72 | |||||
73 | # spent 15.6ms (0s+15.6) within Parse::CPAN::Meta::json_backend which was called 64 times, avg 244µs/call:
# 54 times (0s+15.6ms) by CPAN::Meta::Converter::_dclone at line 56 of CPAN/Meta/Converter.pm, avg 289µs/call
# 9 times (0s+0s) by CPAN::Meta::as_string at line 611 of CPAN/Meta.pm, avg 0s/call
# once (0s+0s) by Parse::CPAN::Meta::load_json_string at line 52 | ||||
74 | 64 | 0s | if (! $ENV{PERL_JSON_BACKEND} or $ENV{PERL_JSON_BACKEND} eq 'JSON::PP') { | ||
75 | 64 | 0s | 64 | 15.6ms | _can_load( 'JSON::PP' => 2.27103 ) # spent 15.6ms making 64 calls to Parse::CPAN::Meta::_can_load, avg 244µs/call |
76 | or croak "JSON::PP 2.27103 is not available\n"; | ||||
77 | 64 | 0s | return 'JSON::PP'; | ||
78 | } | ||||
79 | else { | ||||
80 | _can_load( 'JSON' => 2.5 ) | ||||
81 | or croak "JSON 2.5 is required for " . | ||||
82 | "\$ENV{PERL_JSON_BACKEND} = '$ENV{PERL_JSON_BACKEND}'\n"; | ||||
83 | return "JSON"; | ||||
84 | } | ||||
85 | } | ||||
86 | |||||
87 | # spent 0s within Parse::CPAN::Meta::_slurp which was called:
# once (0s+0s) by Parse::CPAN::Meta::load_file at line 16 | ||||
88 | 1 | 0s | require Encode; | ||
89 | 1 | 0s | 1 | 0s | open my $fh, "<:raw", "$_[0]" ## no critic # spent 0s making 1 call to Parse::CPAN::Meta::CORE:open |
90 | or die "can't open $_[0] for reading: $!"; | ||||
91 | 3 | 0s | 1 | 0s | my $content = do { local $/; <$fh> }; # spent 0s making 1 call to Parse::CPAN::Meta::CORE:readline |
92 | 1 | 0s | 2 | 0s | $content = Encode::decode('UTF-8', $content, Encode::PERLQQ()); # spent 0s making 1 call to Encode::PERLQQ
# spent 0s making 1 call to Encode::decode |
93 | 1 | 0s | return $content; | ||
94 | } | ||||
95 | |||||
96 | sub _can_load { | ||||
97 | 73 | 0s | my ($module, $version) = @_; | ||
98 | 73 | 0s | 73 | 0s | (my $file = $module) =~ s{::}{/}g; # spent 0s making 73 calls to Parse::CPAN::Meta::CORE:subst, avg 0s/call |
99 | 73 | 0s | $file .= ".pm"; | ||
100 | 73 | 0s | return 1 if $INC{$file}; | ||
101 | 2 | 0s | return 0 if exists $INC{$file}; # prior load failed | ||
102 | 6 | 15.6ms | eval { require $file; 1 } | ||
103 | or return 0; | ||||
104 | 2 | 0s | if ( defined $version ) { | ||
105 | 6 | 0s | 2 | 0s | eval { $module->VERSION($version); 1 } # spent 0s making 2 calls to version::vxs::_VERSION, avg 0s/call |
106 | or return 0; | ||||
107 | } | ||||
108 | 2 | 0s | return 1; | ||
109 | } | ||||
110 | |||||
111 | # Kept for backwards compatibility only | ||||
112 | # Create an object from a file | ||||
113 | sub LoadFile ($) { | ||||
114 | return Load(_slurp(shift)); | ||||
115 | } | ||||
116 | |||||
117 | # Parse a document from a string. | ||||
118 | sub Load ($) { | ||||
119 | require CPAN::Meta::YAML; | ||||
120 | my $object = eval { CPAN::Meta::YAML::Load(shift) }; | ||||
121 | croak $@ if $@; | ||||
122 | return $object; | ||||
123 | } | ||||
124 | |||||
125 | 1 | 0s | 1; | ||
126 | |||||
127 | __END__ | ||||
# spent 0s within Parse::CPAN::Meta::CORE:match which was called 2 times, avg 0s/call:
# 2 times (0s+0s) by Parse::CPAN::Meta::load_file at line 18, avg 0s/call | |||||
# spent 0s within Parse::CPAN::Meta::CORE:open which was called:
# once (0s+0s) by Parse::CPAN::Meta::_slurp at line 89 | |||||
# spent 0s within Parse::CPAN::Meta::CORE:readline which was called:
# once (0s+0s) by Parse::CPAN::Meta::_slurp at line 91 | |||||
# spent 0s within Parse::CPAN::Meta::CORE:subst which was called 73 times, avg 0s/call:
# 73 times (0s+0s) by Parse::CPAN::Meta::_can_load at line 98, avg 0s/call |