File Coverage

blib/lib/Software/Catalog/Role/Software.pm
Criterion Covered Total %
statement 6 20 30.0
branch 0 4 0.0
condition n/a
subroutine 2 4 50.0
pod 1 2 50.0
total 9 30 30.0


line stmt bran cond sub pod time code
1             package Software::Catalog::Role::Software;
2              
3 1     1   371159 use Role::Tiny;
  1         7956  
  1         8  
4              
5 1     1   2348 use PerlX::Maybe;
  1         6322  
  1         15  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2024-07-17'; # DATE
9             our $DIST = 'Software-Catalog'; # DIST
10             our $VERSION = '1.0.8'; # VERSION
11              
12             sub available_platform_labels {
13 0     0 1   my $self = shift;
14 0           sort keys %{ $self->platform_labels_to_specs };
  0            
15             }
16              
17             sub first_matching_platform_label {
18 0     0 0   require Devel::Platform::Info;
19 0           require Devel::Platform::Match;
20              
21 0           my ($self, $platform_info) = @_;
22 0 0         if (!defined($platform_info)) {
23 0           $platform_info = Devel::Platform::Info->new->get_info;
24             }
25              
26 0           my $platform_labels_to_specs = $self->platform_labels_to_specs;
27 0           for my $platform_label (keys %$platform_labels_to_specs) {
28 0           my $platform_spec = $platform_labels_to_specs->{$platform_label};
29 0 0         if (Devel::Platform::Match::match_platform_bool($platform_spec, $platform_info)) {
30 0           return $platform_label;
31             }
32             }
33 0           undef;
34             }
35              
36             requires 'archive_info';
37              
38             around archive_info => sub {
39             my $orig = shift;
40             my ($self, %args) = @_;
41              
42             # supply default for 'platform_label' argument
43             if (!defined $args{platform_label}) {
44             $args{platform_label} = $self->first_matching_platform_label or
45             return [412, "Platform not supported"];
46             }
47              
48             # supply default for 'version' argument
49             if (!defined $args{version}) {
50             my $verres = $self->latest_version(maybe platform_label => $args{platform_label});
51             return [500, "Can't get latest version: $verres->[0] - $verres->[1]"]
52             unless $verres->[0] == 200;
53             $args{version} = $verres->[2];
54             $args{alternate_version} = $verres->[3]{'func.alternate_version'}
55             if defined $verres->[3]{'func.alternate_version'};
56             }
57              
58             $orig->($self, %args);
59             };
60              
61             requires 'available_versions';
62              
63             around available_versions => sub {
64             my $orig = shift;
65             my ($self, %args) = @_;
66              
67             # supply default for 'platform_label' argument
68             if (!defined $args{platform_label}) {
69             $args{platform_label} = $self->first_matching_platform_label or
70             return [412, "Platform not supported"];
71             }
72              
73             $orig->($self, %args);
74             };
75              
76             requires 'cmp_version'; # usually from versioning scheme role
77              
78             requires 'homepage_url';
79              
80             requires 'is_dedicated_profile';
81              
82             requires 'is_valid_version'; # usually from versioning scheme role
83              
84             requires 'latest_version';
85              
86             around latest_version => sub {
87             my $orig = shift;
88             my ($self, %args) = @_;
89              
90             # supply default for 'platform_label' argument
91             if (!defined $args{platform_label}) {
92             $args{platform_label} = $self->first_matching_platform_label or
93             return [412, "Platform not supported"];
94             }
95              
96             $orig->($self, %args);
97             };
98              
99             requires 'platform_labels_to_specs';
100              
101             requires 'download_url';
102              
103             around download_url => sub {
104             my $orig = shift;
105             my ($self, %args) = @_;
106              
107             # supply default for 'platform_label' argument
108             if (!defined $args{platform_label}) {
109             $args{platform_label} = $self->first_matching_platform_label or
110             return [412, "Platform not supported"];
111             }
112              
113             # supply default for 'version' argument
114             if (!defined $args{version}) {
115             my $verres = $self->latest_version(maybe platform_label => $args{platform_label});
116             return [500, "Can't get latest version: $verres->[0] - $verres->[1]"]
117             unless $verres->[0] == 200;
118             $args{version} = $verres->[2];
119             $args{alternate_version} = $verres->[3]{'func.alternate_version'}
120             if defined $verres->[3]{'func.alternate_version'};
121             }
122              
123             $orig->($self, %args);
124             };
125              
126             requires 'release_note';
127              
128             around release_note => sub {
129             my $orig = shift;
130             my ($self, %args) = @_;
131              
132             # supply default for 'platform_label' argument
133             if (!defined $args{platform_label}) {
134             $args{platform_label} = $self->first_matching_platform_label or
135             return [412, "Platform not supported"];
136             }
137              
138             # supply default for 'version' argument
139             if (!defined $args{version}) {
140             my $verres = $self->latest_version(maybe platform_label => $args{platform_label});
141             return [500, "Can't get latest version: $verres->[0] - $verres->[1]"]
142             unless $verres->[0] == 200;
143             $args{version} = $verres->[2];
144             $args{alternate_version} = $verres->[3]{'func.alternate_version'}
145             if defined $verres->[3]{'func.alternate_version'};
146             }
147              
148             $orig->($self, %args);
149             };
150              
151             1;
152             # ABSTRACT: Role for software
153              
154             __END__