urpm/xml_info.pm

filter: Statementstmt 7.4% 7 / 94 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 11.7% 2 / 17 Podpod 0.0% 0 / 3 totaltotal 6.2% 9 / 145 CC 15 SCAR 23.4
CC
15
Cov
6%
_iterate_on_nodes
30.0
_open_xml_reader
12.0
_get_changelog_node
12.0
CRAP 10.4
« gurpm/RPMProgressDialog.pm ↑ Summary urpm/xml_info_pkg.pm »
1 package urpm::xml_info;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XML::LibXML::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 urpm::xml_info - XML data manipulation related routines for urpmi
9  
10 =head1 SYNOPSIS
11  
12 =head1 DESCRIPTION
13  
14 =over
15  
16 =cut
17  
18 # throw an exception on error
19 0 ▶sub get_nodes {
Subroutine get_nodes: not called CC=1 SCAR=6.9
Pod undocumented
20 0 my ($xml_info, $xml_info_file, $fullnames) = @_;
21  
22 0 my $get_one_node = _get_one_node($xml_info);
23 0 _get_xml_info_nodes($xml_info_file, $get_one_node, $fullnames);
24 }
25  
26 # throw an exception on error
27 0 ▶sub do_something_with_nodes {
Subroutine do_something_with_nodes: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my ($xml_info, $xml_info_file, $do, $o_wanted_attributes) = @_;
29  
30 0 my $get_one_node = _get_one_node($xml_info, $o_wanted_attributes);
31 0 _do_something_with_xml_info_nodes($xml_info_file, $get_one_node, $do);
32 }
33  
34  
35 0 ▶sub open_lzma {
Subroutine open_lzma: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my ($xml_info_file) = @_;
37  
38 0 $xml_info_file =~ s/'/'\\''/g;
39 0 open(my $F, "xz -dc '$xml_info_file' |");
40 0 $F;
41 }
42  
43 ################################################################################
44 0 ▶sub _open_xml_reader {
Subroutine _open_xml_reader: not called CC=3 SCAR=24.8
45 0 my ($xml_info_file) = @_;
46  
47 0 ▶ my $reader = XML::LibXML::Reader->new(IO => open_lzma($xml_info_file), huge => 1) or die "cannot read $xml_info_file\n";
Branch: 1 branch
BranchTrueFalseTotal
my $reader = "XML::LibXML::Reader"->new("IO", open_lzma($xml_info_file), "huge", 1) or die "cannot read $xml_info_file\n" 0 0 0
48  
49 0 $reader->read;
50 0 ▶ $reader->name eq 'media_info' or die "global <media_info> tag not found\n";
Branch: 1 branch
BranchTrueFalseTotal
$reader->name eq "media_info" or die "global <media_info> tag not found\n" 0 0 0
51  
52 0 $reader->read; # first tag
53  
54 0 $reader;
55 }
56  
57 0 ▶sub _get_all_attributes {
Subroutine _get_all_attributes: not called CC=2 SCAR=17.9
58 0 my ($reader) = @_;
59 0 my %entry;
60  
61 0 $reader->moveToFirstAttribute;
62  
63 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$reader->moveToNextAttribute == 1 and do { do { $entry{$reader->name} = $reader->value } } 0 0 0
64 0 $entry{$reader->name} = $reader->value;
65 } while $reader->moveToNextAttribute == 1;
66
67 0 \%entry;
68 }
69  
70 0 ▶sub _get_attributes {
Subroutine _get_attributes: not called CC=2 SCAR=17.9
71 0 my ($reader, $o_wanted_attributes) = @_;
72  
73 0 ▶ if ($o_wanted_attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o_wanted_attributes) { } 0 0 0
74 0 my %entry = map { $_ => $reader->getAttribute($_) } @$o_wanted_attributes;
75 0 \%entry;
76 } else {
77 0 _get_all_attributes($reader);
78 }
79 }
80  
81 0 ▶sub _get_simple_value_node {
Subroutine _get_simple_value_node: not called CC=1 SCAR=6.9
82 0 my ($value_name, $o_wanted_attributes) = @_;
83  
84 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
85 0 my ($reader) = @_;
86 0 my $entry = _get_attributes($reader, $o_wanted_attributes);
87  
88 0 $reader->read; # get value
89 0 $entry->{$value_name} = $reader->value;
90 0 $entry->{$value_name} =~ s/^\n//;
91  
92 0 $reader->read; # close tag
93 0 $reader->read; # open next tag
94  
95 0 $entry;
96 0 };
97 }
98  
99 0 ▶sub _get_changelog_node {
Subroutine _get_changelog_node: not called CC=3 SCAR=24.8
100 0 my ($reader, $fn) = @_;
101
102 0 $reader->nextElement('log'); # get first <log>
103  
104 0 my @changelogs;
105 my $time;
106 0 ▶ while ($time = $reader->getAttribute('time')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time = $reader->getAttribute("time")) 0 0 0
107 0 push @changelogs, my $e = { time => $time };
108  
109 0 $reader->nextElement('log_name'); $reader->read;
110 0 $e->{name} = $reader->value;
111  
112 0 $reader->nextElement('log_text'); $reader->read;
113 0 $e->{text} = $reader->value;
114
115 0 $reader->read; # </log_text>
116 0 $reader->read; # </log>
117 0 $reader->read; # <log>
118 0 ▶ $reader->read if $reader->readState != 0; # there may be SIGNIFICANT_WHITESPACE between </log_text> and </log>
Branch: 1 branch
BranchTrueFalseTotal
if $reader->readState != 0 0 0 0
119 }
120  
121 0 { fn => $fn, changelogs => \@changelogs };
122 }
123  
124 0 ▶sub _get_one_node {
Subroutine _get_one_node: not called CC=3 SCAR=24.8
125 0 my ($xml_info, $o_wanted_attributes) = @_;
126  
127 0 ▶ if ($xml_info eq 'changelog') {
Branch: 2 branches
BranchTrueFalseTotal
if ($xml_info eq 'changelog') { } 0 0 0
elsif ($xml_info eq 'info') { } 0 0 0
128 0 \&_get_changelog_node;
129 } elsif ($xml_info eq 'info') {
130 0 _get_simple_value_node('description', $o_wanted_attributes);
131 } else {
132 0 _get_simple_value_node('files', $o_wanted_attributes);
133 }
134 }
135  
136 0 ▶sub _get_xml_info_nodes {
Subroutine _get_xml_info_nodes: not called CC=2 SCAR=17.9
137 0 my ($xml_info_file, $get_node, $fullnames) = @_;
138  
139 0 my $fullnames_re = '^(' . join('|', map { quotemeta $_ } @$fullnames) . ')$';
140  
141 0 my %todo = map { $_ => 1 } @$fullnames;
142 0 my %nodes;
143 _iterate_on_nodes($xml_info_file,
144 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
145 0 my ($reader, $fn) = @_;
146 0 ▶ if ($fn =~ /$fullnames_re/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fn =~ /$fullnames_re/) { } 0 0 0
147 0 $nodes{$fn} = $get_node->($reader);
148 0 delete $todo{$fn};
149 0 keys(%todo) == 0;
150 } else {
151 0 $reader->next;
152 0 0;
153 }
154 0 });
155  
156 0 ▶ %todo and die "could not find " . join(', ', keys %todo) . " in $xml_info_file\n";
Branch: 1 branch
BranchTrueFalseTotal
%todo and die 'could not find ' . join(", ", keys %todo) . " in $xml_info_file\n" 0 0 0
157  
158 0 %nodes;
159 }
160  
161 0 ▶sub _do_something_with_xml_info_nodes {
Subroutine _do_something_with_xml_info_nodes: not called CC=1 SCAR=6.9
162 0 my ($xml_info_file, $get_node, $do) = @_;
163  
164 _iterate_on_nodes($xml_info_file,
165 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
166 0 my ($reader, $fn) = @_;
167 0 my $h = $get_node->($reader, $fn); # will read until closing tag
168 0 $do->($h);
169 0 0;
170 0 });
171 }
172  
173 0 ▶sub _iterate_on_nodes {
Subroutine _iterate_on_nodes: not called CC=5 SCAR=34.0
174 0 my ($xml_info_file, $do) = @_;
175  
176 0 my $reader = _open_xml_reader($xml_info_file);
177  
178 0 my $fn;
179 0 ▶ while ($fn = $reader->getAttribute('fn')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fn = $reader->getAttribute("fn")) 0 0 0
180 0 ▶ $do->($reader, $fn) and return; # $do must go to next node otherwise it loops!
Branch: 1 branch
BranchTrueFalseTotal
&$do($reader, $fn) and return 0 0 0
181 }
182  
183 0 ▶ $reader->readState == 3 || $reader->name eq 'media_info'
Branch: 1 branch
BranchTrueFalseTotal
$reader->readState == 3 or $reader->name eq "media_info" or die 'missing attribute "fn" in tag "' . $reader->name . qq["\n] 0 0 0
Condition0%0/3
$reader->readState == 3 or $reader->name eq "media_info"
l!l&&r!l&&!r
000
MC/DC0%0/2
$reader->readState == 3 or $reader->name eq "media_info"
$reader->readState == 3 $reader->name eq "media_info"
Truth table0%0/3
A or B
A= $reader->readState == 3B= $reader->name eq "media_info"
ABresult
1X1
011
000
184 or die qq(missing attribute "fn" in tag ") . $reader->name . qq("\n);
185 }
186  
187 1 1;
188  
189  
190 =back
191  
192 =head1 COPYRIGHT
193  
194 Copyright (C) 2005 MandrakeSoft SA
195  
196 Copyright (C) 2005-2010 Mandriva SA
197  
198 Copyright (C) 2011-2020 Mageia
199  
200 =cut
« gurpm/RPMProgressDialog.pm ↑ Summary urpm/xml_info_pkg.pm »