File Coverage

blib/lib/RDF/DOAP/Version.pm
Criterion Covered Total %
statement 69 69 100.0
branch 11 12 91.6
condition 6 8 75.0
subroutine 15 15 100.0
pod 0 1 0.0
total 101 105 96.1


line stmt bran cond sub pod time code
1             package RDF::DOAP::Version;
2              
3             our $AUTHORITY = 'cpan:TOBYINK';
4             our $VERSION = '0.103';
5              
6 2     2   16 use Moose;
  2         6  
  2         16  
7             extends qw(RDF::DOAP::Resource);
8              
9 2     2   15447 use RDF::DOAP::ChangeSet;
  2         115  
  2         102  
10 2     2   16 use RDF::DOAP::Change;
  2         4  
  2         43  
11 2     2   11 use RDF::DOAP::Person;
  2         4  
  2         58  
12 2     2   10 use RDF::DOAP::Types -types;
  2         5  
  2         18  
13 2     2   11597 use RDF::DOAP::Utils -traits;
  2         5  
  2         19  
14 2     2   734 use List::Util qw(uniq);
  2         6  
  2         171  
15 2     2   14 use Text::Wrap qw(wrap);
  2         6  
  2         114  
16              
17 2     2   17 use RDF::Trine::Namespace qw(rdf rdfs owl xsd);
  2         3  
  2         18  
18             my $doap = 'RDF::Trine::Namespace'->new('http://usefulinc.com/ns/doap#');
19             my $dc = 'RDF::Trine::Namespace'->new('http://purl.org/dc/terms/');
20             my $dcs = 'RDF::Trine::Namespace'->new('http://ontologi.es/doap-changeset#');
21              
22             has $_ => (
23             traits => [ WithURI ],
24             is => 'ro',
25             isa => String,
26             coerce => 1,
27             uri => $doap->$_,
28             ) for qw( revision name branch );
29              
30             has issued => (
31             traits => [ WithURI ],
32             is => 'ro',
33             isa => String,
34             coerce => 1,
35             uri => $dc->issued,
36             );
37              
38             has changesets => (
39             traits => [ WithURI ],
40             is => 'ro',
41             isa => ArrayRef[ChangeSet],
42             coerce => 1,
43             uri => $dcs->changeset,
44             multi => 1,
45             trigger => sub { $_[0]->clear_changes },
46             );
47              
48             has changes => (
49             is => 'ro',
50             isa => ArrayRef[Change],
51             coerce => 1,
52             lazy => 1,
53             builder => '_build_changes',
54             clearer => 'clear_changes',
55             );
56              
57             has released_by => (
58             traits => [ WithURI, Gathering ],
59             is => 'ro',
60             isa => Person,
61             coerce => 1,
62             uri => $dcs->uri('released-by'),
63             gather_as => ['maintainer'],
64             );
65              
66             has _changelog_subsections => (
67             is => 'ro',
68             isa => ArrayRef[ArrayRef],
69             lazy => 1,
70             builder => '_build_changelog_subsections',
71             );
72              
73             sub _build_changes
74             {
75 7     7   12 my $self = shift;
76 7 100       11 [ map { @{$_->items} } @{$self->changesets || []} ];
  6         11  
  6         151  
  7         179  
77             }
78              
79             sub changelog_section
80             {
81 7     7 0 16 my $self = shift;
82            
83 7         10 my @ss = @{ $self->_changelog_subsections };
  7         185  
84            
85 7 100 100     34 if (@ss == 1 and $ss[0][0] eq 'Other')
86             {
87             # If there's only an "Other" section, then avoid
88             # printing a section header for it.
89             return join(
90             "\n",
91             $self->_changelog_section_header,
92             map {
93 1         6 my ($head, @lines) = @$_;
  1         5  
94 1         9 (sort(@lines), '');
95             } @ss,
96             );
97             }
98            
99             return join(
100             "\n",
101             $self->_changelog_section_header,
102             map {
103 6         23 my ($head, @lines) = @$_;
  7         26  
104 7         63 (" [ $head ]", sort(@lines), '');
105             } @ss,
106             );
107             }
108              
109             sub _changelog_section_header
110             {
111 8     8   16 my $self = shift;
112 8   50     208 return join(
      66        
113             "\t",
114             grep(
115             defined,
116             $self->revision,
117             ($self->issued // 'Unknown'),
118             ($self->name // $self->label),
119             ),
120             ) . "\n";
121             }
122              
123             sub _subsection_order
124             {
125 7     7   14 my $self = shift;
126 7         26 uniq(map $_->[1], $self->_subsection_classification);
127             }
128              
129             sub _subsection_classification
130             {
131             (
132 14     14   105 [$dcs->SecurityFix => 'SECURITY', 'Fix'],
133             [$dcs->SecurityRegression => 'SECURITY', 'Regression'],
134             [$dcs->BackCompat => 'BACK COMPAT'],
135             [$dcs->Regression => 'REGRESSIONS'],
136             [$dcs->Bugfix => 'Bug Fixes'],
137             [$dcs->Documentation => 'Documentation'],
138             [$dcs->Tests => 'Test Suite'],
139             [$dcs->Packaging => 'Packaging'],
140             [$dcs->Addition => 'Other', 'Added'],
141             [$dcs->Removal => 'Other', 'Removed'],
142             [$dcs->Update => 'Other', 'Updated'],
143             [$dcs->Change => 'Other'],
144             );
145             }
146              
147             sub _build_changelog_subsections
148             {
149 7     7   14 my $self = shift;
150            
151 7         10 my %sections;
152 7         17 my @classifications = $self->_subsection_classification;
153            
154 7         2871 for my $ch (@{ $self->changes })
  7         201  
155             {
156 8         12 my $found_section;
157 8         20 for my $class (@classifications)
158             {
159 54         6139 my ($type, $section, $tag) = @$class;
160 54 100       138 if ( $ch->isa($type) )
161             {
162 7         1169 my $text = join "\n", $ch->changelog_lines(1);
163 7 50       53 $text = "$tag: $text" if $tag;
164 7         15 push @{ $sections{$section} }, wrap(" - ", " ", $text);
  7         39  
165 7         2235 $found_section++;
166 7         19 last;
167             }
168             }
169 8 100       23 unless ($found_section)
170             {
171 1         5 my $text = join "\n", $ch->changelog_lines(1);
172 1         3 push @{ $sections{Other} }, wrap(" - ", " ", $text);
  1         7  
173             }
174             }
175            
176             return [
177 7 100       305 map { exists($sections{$_}) ? [$_, @{$sections{$_}}] : (); }
  56         3248  
  8         26  
178             $self->_subsection_order
179             ];
180             }
181              
182             1;