File Coverage

blib/lib/Protocol/Sys/Virt/URI.pm
Criterion Covered Total %
statement 32 33 96.9
branch 7 10 70.0
condition 7 10 70.0
subroutine 7 7 100.0
pod 1 1 100.0
total 54 61 88.5


line stmt bran cond sub pod time code
1             ####################################################################
2             #
3             # This file was generated using XDR::Parse version v1.0.1,
4             # XDR::Gen version 1.1.2 and LibVirt version v12.1.0
5             #
6             # Don't edit this file, use the source template instead
7             #
8             # ANY CHANGES HERE WILL BE LOST !
9             #
10             ####################################################################
11              
12              
13 2     2   195657 use v5.14;
  2         11  
14 2     2   15 use warnings;
  2         4  
  2         196  
15              
16             package Protocol::Sys::Virt::URI v12.1.0;
17              
18 2     2   999 use parent qw(Exporter);
  2         695  
  2         12  
19              
20 2     2   155 use Carp qw(croak);
  2         5  
  2         148  
21 2     2   1216 use Log::Any qw($log);
  2         22252  
  2         12  
22 2     2   7625 use URI::Encode qw(uri_encode uri_decode);
  2         45105  
  2         1438  
23              
24             our @EXPORT = qw( parse_url );
25              
26             sub parse_url {
27 12     12 1 161180 my $url = shift;
28 12         41 my ($base, $query) = split( /\?/, $url, 2 );
29 12   100     51 $query //= '';
30             my %args = map {
31 16         8754 uri_decode($_)
32             }
33             map {
34 12         27 my ($key, $val) = split( /=/, $_, 2 );
  8         19  
35 8   50     18 $val //= '';
36 8         20 ($key, $val);
37             }
38             split( /&/, $query );
39              
40 12 50       8518 if ($base =~ m#^
41             (?[a-z0-9_]+)
42             (?:\+(?[a-z0-9_]+))?
43             ://
44             (?:(?[^@]+)@)?
45             ((?[a-z0-9_\-\.]+)
46             (?:\:(?\d+))?
47             )?
48             /
49             (?system|session)
50             $
51             #xi) {
52 12         127 my $bare = "$+{hypervisor}:///$+{type}";
53 12 100 66     56 $bare .= '?' if ($args{mode} or $args{socket});
54             $bare .= 'mode=' . uri_encode($args{mode},
55             { encode_reserved => 1 })
56 12 100       38 if $args{mode};
57 12 50 66     7567 $bare .= '&' if ($args{mode} and $args{socket});
58             $bare .= 'socket=' . uri_encode($args{socket},
59             { encode_reserved => 1 })
60 12 50       27 if $args{socket};
61 12         371 return (base => $base,
62             proxy => $bare,
63             name => "$+{hypervisor}:///$+{type}",
64             %+,
65             query => \%args);
66             }
67              
68 0           die "Malformed hypervisor URI $url";
69             }
70              
71             1;
72              
73              
74             __END__