| 1 | package URI::VersionRange::App; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use feature ':5.10'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Getopt::Long qw(GetOptionsFromArray :config gnu_compat); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Pod::Usage qw(pod2usage); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use JSON::PP (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use Data::Dumper (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | use URI::VersionRange (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | our $VERSION = '2.25'; | |||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub cli_error { | ||||||||
|
Subroutine
cli_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 19 | 0 | my ($error) = @_; | |||||||||
| 20 | 0 | $error =~ s/ at .* line \d+.*//; | |||||||||
| 21 | 0 | print STDERR "ERROR: $error\n"; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=16 SCAR=42.3
Pod
documented
| |||||||||||
| 25 | |||||||||||
| 26 | 1 | my ($class, @args) = @_; | |||||||||
| 27 | |||||||||||
| 28 | 1 | my %options = (format => 'json'); | |||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | GetOptionsFromArray( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | \@args, \%options, qw( | ||||||||||
| 32 | help | ||||||||||
| 33 | man | ||||||||||
| 34 | v | ||||||||||
| 35 | |||||||||||
| 36 | contains=s | ||||||||||
| 37 | |||||||||||
| 38 | null|0 | ||||||||||
| 39 | format=s | ||||||||||
| 40 | |||||||||||
| 41 | json | ||||||||||
| 42 | human-readable|h | ||||||||||
| 43 | ) | ||||||||||
| 44 | ) or pod2usage(-verbose => 0); | ||||||||||
| 45 | |||||||||||
| 46 | 1 | ▶ | pod2usage(-exitstatus => 0, -verbose => 2) if defined $options{man}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 1 | ▶ | pod2usage(-exitstatus => 0, -verbose => 0) if defined $options{help}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | |||||||||||
| 49 | 1 | ▶ | if (defined $options{v}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | 0 | (my $progname = $0) =~ s/.*\///; | |||||||||
| 52 | |||||||||||
| 53 | 0 | say <<"VERSION"; | |||||||||
| 54 | $progname version $URI::VersionRange::VERSION | ||||||||||
| 55 | |||||||||||
| 56 | Copyright 2022-2026, Giuseppe Di Terlizzi <gdt\@cpan.org> | ||||||||||
| 57 | |||||||||||
| 58 | This program is part of the "URI-PackageURL" distribution and is free software; | ||||||||||
| 59 | you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||
| 60 | |||||||||||
| 61 | Complete documentation for $progname can be found using 'man $progname' | ||||||||||
| 62 | or on the internet at <https://metacpan.org/dist/URI-PackageURL>. | ||||||||||
| 63 | VERSION | ||||||||||
| 64 | |||||||||||
| 65 | 0 | return 0; | |||||||||
| 66 | |||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 1 | my ($vers_string) = @args; | |||||||||
| 70 | |||||||||||
| 71 | 1 | ▶ | pod2usage(-verbose => 1) if !$vers_string; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | |||||||||||
| 73 | 1 | ▶ | $options{format} = 'json' if defined $options{json}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 1 | ▶ | $options{format} = 'human-readable' if defined $options{'human-readable'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | |||||||||||
| 76 | 1 | my $vers = eval { URI::VersionRange->from_string($vers_string) }; | |||||||||
| 77 | |||||||||||
| 78 | 1 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | cli_error($@); | |||||||||
| 80 | 0 | return 1; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 1 | ▶ | if (defined $options{contains}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | |||||||||||
| 85 | 0 | my $vers_comparator_class = join '::', 'URI::VersionRange::Version', $vers->scheme; | |||||||||
| 86 | |||||||||||
| 87 | 0 | ▶ | if (!$vers_comparator_class->can('new')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 0 | say STDERR 'WARNING: Loaded the fallback scheme class comparator.'; | |||||||||
| 89 | 0 | say STDERR ' The comparison may not work correctly!'; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | my $res = eval { $vers->contains($options{contains}) }; | |||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 0 | cli_error($@); | |||||||||
| 96 | 0 | return 1; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 0 | ▶ | say STDERR $res ? 'true' : 'false'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | return !$res; | |||||||||
| 101 | |||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 1 | ▶ | if ($options{format} eq 'json') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 1 | print JSON::PP->new->canonical->pretty(1)->convert_blessed(1)->encode($vers); | |||||||||
| 106 | 1 | return 0; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | 0 | ▶ | if ($options{format} eq 'human-readable') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 0 | say $vers->scheme; | |||||||||
| 111 | 0 | say "- " . $_->to_human_string for (@{$vers->constraints}); | |||||||||
| 112 | 0 | return 0; | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 2 | 1; | |||||||||
| 118 | |||||||||||
| 119 | __END__ | ||||||||||