| 1 | package App::cpm::Task; | ||
| 2 | use v5.24; | ||
| 3 | use warnings; | ||
| 4 | use experimental qw(lexical_subs signatures); | ||
| 5 | use CPAN::DistnameInfo; | ||
| 6 | |||
| 7 | sub new ($class, %argv) { | ||
| 8 | my $self = bless {%argv}, $class; | ||
| 9 | $self->{uid} = $self->_uid; | ||
| 10 | $self; | ||
| 11 | } | ||
| 12 | |||
| 13 | sub uid ($self) { $self->{uid} } | ||
| 14 | |||
| 15 | sub _uid ($self) { | ||
| 16 | my $type = $self->type; | ||
| 17 | if (grep { $type eq $_ } qw(fetch configure build test)) { | ||
| 18 | "$type " . $self->distfile; | ||
| 19 | } elsif ($type eq "resolve") { | ||
| 20 | "$type " . $self->{package}; | ||
| 21 | } else { | ||
| 22 | die "unknown type: " . ($type || "(undef)"); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | sub distfile ($self) { | ||
| 27 | $self->{distfile} || $self->{uri}; | ||
| 28 | } | ||
| 29 | |||
| 30 | sub distvname ($self) { | ||
| 31 | return $self->{_distvname} if $self->{_distvname}; | ||
| 32 | if ($self->{distfile}) { | ||
| 33 | $self->{_distvname} ||= CPAN::DistnameInfo->new($self->{distfile})->distvname; | ||
| 34 | } elsif ($self->{uri}) { | ||
| 35 | $self->{uri}; | ||
| 36 | } elsif ($self->{package}) { | ||
| 37 | $self->{package}; | ||
| 38 | } else { | ||
| 39 | "UNKNOWN"; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | sub distname ($self) { | ||
| 44 | $self->{_distname} ||= CPAN::DistnameInfo->new($self->distfile)->dist || 'UNKNOWN'; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub cpanid ($self) { | ||
| 48 | $self->{_cpanid} ||= CPAN::DistnameInfo->new($self->distfile)->cpanid || 'UNKNOWN'; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub type ($self) { | ||
| 52 | $self->{type}; | ||
| 53 | } | ||
| 54 | |||
| 55 | sub in_charge ($self, @argv) { | ||
| 56 | @argv ? $self->{in_charge} = $argv[0] : $self->{in_charge}; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub is_success ($self) { | ||
| 60 | $self->{ok}; | ||
| 61 | } | ||
| 62 | |||
| 63 | sub equals ($self, $that) { | ||
| 64 | $self->uid eq $that->uid; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub merge ($self, $that) { | ||
| 68 | for my $key (keys $that->%*) { | ||
| 69 | $self->{$key} = $that->{$key}; | ||
| 70 | } | ||
| 71 | $self; | ||
| 72 | } | ||
| 73 | |||
| 74 | 1; |