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.3.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   162365 use v5.14;
  2         8  
14 2     2   14 use warnings;
  2         6  
  2         165  
15              
16             package Protocol::Sys::Virt::URI v12.3.0;
17              
18 2     2   831 use parent qw(Exporter);
  2         472  
  2         11  
19              
20 2     2   97 use Carp qw(croak);
  2         3  
  2         94  
21 2     2   1003 use Log::Any qw($log);
  2         15298  
  2         13  
22 2     2   5057 use URI::Encode qw(uri_encode uri_decode);
  2         32773  
  2         912  
23              
24             our @EXPORT = qw( parse_url );
25              
26             sub parse_url {
27 12     12 1 135844 my $url = shift;
28 12         34 my ($base, $query) = split( /\?/, $url, 2 );
29 12   100     37 $query //= '';
30             my %args = map {
31 16         7774 uri_decode($_)
32             }
33             map {
34 12         24 my ($key, $val) = split( /=/, $_, 2 );
  8         17  
35 8   50     15 $val //= '';
36 8         22 ($key, $val);
37             }
38             split( /&/, $query );
39              
40 12 50       7300 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         102 my $bare = "$+{hypervisor}:///$+{type}";
53 12 100 66     49 $bare .= '?' if ($args{mode} or $args{socket});
54             $bare .= 'mode=' . uri_encode($args{mode},
55             { encode_reserved => 1 })
56 12 100       35 if $args{mode};
57 12 50 66     6641 $bare .= '&' if ($args{mode} and $args{socket});
58             $bare .= 'socket=' . uri_encode($args{socket},
59             { encode_reserved => 1 })
60 12 50       23 if $args{socket};
61 12         305 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__