File Coverage

blib/script/url
Criterion Covered Total %
statement 20 20 100.0
branch 2 4 50.0
condition 1 3 33.3
subroutine 4 4 100.0
pod n/a
total 27 31 87.1


line stmt bran cond sub pod time code
1             #!/usr/local/bin/perl
2 53     53   277709 use v5.26;
  53         181  
3              
4 53     53   24308 use App::url 1.009;
  53         5899  
  53         3212  
5              
6             =encoding utf8
7              
8             =head1 NAME
9              
10             url - format a URL according to a sprintf-like template
11              
12             =head1 SYNOPSIS
13              
14             # format as just the host
15             $ url '%H' http://www.example.com/a/b/c
16             www.example.com
17              
18             # handle more than one.
19             $ url '%H' http://www.example.com/a/b/c http://www.github.com
20             www.example.com
21             www.github.com
22              
23             # get the path
24             $ url '%P' http://www.example.com/a/b/c
25             /a/b/c
26              
27             =head1 DESCRIPTION
28              
29             Decompose the URL and reformat it according to a template.
30              
31             =head2 The formats
32              
33             =over 4
34              
35             =item * C<%a> - the path
36              
37             =item * C<%A> - the addresses
38              
39             =item * C<%f> - the fragment
40              
41             =item * C<%h> - the hostname, with domain info
42              
43             =item * C<%H> - the hostname without domain info
44              
45             =item * C<%i> - the hostname in punycode
46              
47             =item * C<%I> - space-separated list of IP addresses for the host
48              
49             =item * C<%P> - the password of the userinfo portion
50              
51             =item * C<%p> - the port
52              
53             =item * C<%q> - the query string
54              
55             =item * C<%s> - the scheme
56              
57             =item * C<%S> - the public suffix
58              
59             =item * C<%u> - the complete URL
60              
61             =item * C<%U> - the username of the userinfo portion
62              
63             =back
64              
65             =head1 COPYRIGHT
66              
67             Copyright © 2020-2025, brian d foy, all rights reserved.
68              
69             =head1 LICENSE
70              
71             You can use this code under the terms of the Artistic License 2.
72              
73             =cut
74              
75 53     53   382 use Encode qw(decode encode);
  53         89  
  53         3458  
76 53     53   31861 use I18N::Langinfo qw(langinfo CODESET);
  53         55301  
  53         110107  
77              
78 53         9417707 my $langinfo = langinfo(CODESET);
79 53 50 33     452 $langinfo = "cp-$langinfo" if( $^O eq 'MSWin32' and $langinfo =~ /\A\d+\z/a );
80              
81 53         249 @ARGV = map { decode( $langinfo, $_ ) } @ARGV;
  106         39029  
82              
83 53         2192 my $results = App::url->run( @ARGV );
84 53 50       248 exit if $results->@* == 0;
85              
86 53         338 binmode STDOUT, ':raw';
87 53         158 say join "\n", map { encode( $langinfo, $_ ) } $results->@*;
  53         355