File Coverage

blib/lib/App/GitGot/Repo.pm
Criterion Covered Total %
statement 39 39 100.0
branch 9 10 90.0
condition 6 6 100.0
subroutine 10 10 100.0
pod 3 4 75.0
total 67 69 97.1


line stmt bran cond sub pod time code
1             package App::GitGot::Repo;
2             our $AUTHORITY = 'cpan:GENEHACK';
3             $App::GitGot::Repo::VERSION = '1.339';
4             # ABSTRACT: Base repository objects
5 16     16   146977 use 5.014;
  16         72  
6              
7 16     16   99 use List::Util qw/ uniq /;
  16         30  
  16         1245  
8 16     16   770 use Types::Standard -types;
  16         75928  
  16         163  
9              
10 16     16   76727 use App::GitGot::Types;
  16         43  
  16         123  
11              
12 16     16   3895 use Moo;
  16         8624  
  16         117  
13 16     16   8594 use namespace::autoclean;
  16         12405  
  16         127  
14              
15              
16             has label => (
17             is => 'ro' ,
18             isa => Str ,
19             );
20              
21              
22             has name => (
23             is => 'ro',
24             isa => Str,
25             required => 1 ,
26             );
27              
28              
29             has number => (
30             is => 'ro',
31             isa => Int,
32             required => 1 ,
33             );
34              
35              
36             has path => (
37             is => 'ro',
38             isa => Str,
39             required => 1 ,
40             coerce => sub { ref $_[0] && $_[0]->isa('Path::Tiny') ? "$_[0]" : $_[0] } ,
41             );
42              
43              
44             has repo => (
45             is => 'ro',
46             isa => Str,
47             );
48              
49              
50             has tags => (
51             is => 'rw',
52             isa => Str,
53             );
54              
55              
56             has type => (
57             is => 'ro',
58             isa => Str,
59             required => 1 ,
60             );
61              
62             sub BUILDARGS {
63 101     101 0 187356 my( $class , $args ) = @_;
64              
65 101   100     477 my $count = $args->{count} || 0;
66              
67             die "Must provide entry" unless
68 101 100       474 my $entry = $args->{entry};
69              
70 99   100     498 my $repo = $entry->{repo} //= '';
71              
72 99 100       308 if ( ! defined $entry->{name} ) {
73             ### FIXME this is unnecessarily Git-specific
74 2 50       42 $entry->{name} = ( $repo =~ m|([^/]+).git$| ) ? $1 : '';
75             }
76              
77 99   100     543 $entry->{tags} //= '';
78              
79             my $return = {
80             number => $count ,
81             name => $entry->{name} ,
82             path => $entry->{path} ,
83             repo => $repo ,
84             type => $entry->{type} ,
85             tags => $entry->{tags} ,
86 99         593 };
87              
88 99 100       353 $return->{label} = $args->{label} if $args->{label};
89              
90 99         1817 return $return;
91             }
92              
93              
94             sub add_tags {
95 1     1 1 56 my( $self, @tags ) = @_;
96              
97 1         26 $self->tags( join ' ', uniq sort @tags, split ' ', $self->tags );
98             }
99              
100              
101             sub in_writable_format {
102 23     23 1 6371 my $self = shift;
103              
104 23         303 my $writeable = {
105             name => $self->name ,
106             path => $self->path ,
107             };
108              
109 23         91 foreach ( qw/ repo tags type /) {
110 69 100       1558 $writeable->{$_} = $self->$_ if $self->$_;
111             }
112              
113 23         275 return $writeable;
114             }
115              
116              
117             sub remove_tags {
118 1     1 1 47 my( $self, @tags ) = @_;
119              
120 1         5 my %verboten = map { $_ => 1 } @tags;
  1         5  
121              
122 1         22 $self->tags( join ' ', grep { !$verboten{$_} } split ' ', $self->tags );
  2         29  
123             }
124              
125              
126             1;
127              
128             __END__