File Coverage

lib/CPAN/Changes/Dependencies/Details.pm
Criterion Covered Total %
statement 61 61 100.0
branch 6 6 100.0
condition n/a
subroutine 16 16 100.0
pod 2 2 100.0
total 85 85 100.0


line stmt bran cond sub pod time code
1 3     3   15744 use 5.008; # utf8
  3         6  
  3         101  
2 3     3   11 use strict;
  3         5  
  3         84  
3 3     3   18 use warnings;
  3         4  
  3         109  
4 3     3   999 use utf8;
  3         19  
  3         17  
5              
6             package CPAN::Changes::Dependencies::Details;
7              
8             our $VERSION = '0.001004';
9              
10             # ABSTRACT: Create CPAN::Changes style file only containing dependency change information
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14 3     3   1597 use Moo qw( extends around );
  3         33592  
  3         17  
15 3     3   5007 use MooX::Lsub qw( lsub );
  3         15715  
  3         15  
16 3     3   1098 use Carp qw( croak );
  3         6  
  3         119  
17 3     3   1338 use CPAN::Changes::Release;
  3         17074  
  3         137  
18 3     3   1814 use CPAN::Changes::Group::Dependencies::Details 0.001001; # First useful version
  3         289033  
  3         2306  
19              
20             extends 'CPAN::Changes';
21              
22 1     1   368 lsub change_types => sub { [qw( Added Changed Removed )] };
23 1     1   314 lsub phases => sub { [qw( configure build runtime test )] };
24 1     1   365 lsub types => sub { [qw( requires )] };
25              
26 1     1 1 209 sub load { croak 'This module can only generate dependency details, not read them' }
27 1     1 1 103 sub load_string { croak 'This module can only generate dependency details, not read them' }
28              
29             my $release_keys = [ 'changes', 'version', 'date', 'note', ];
30             my $group_keys = [ 'new_prereqs', 'old_prereqs', 'prereqs_diff', 'all_diffs', ];
31              
32             sub _mk_release {
33 3     3   4 my ( $self, $release ) = @_;
34 3         5 my $input_args = { %{$release} };
  3         11  
35 3         7 my $release_args = {};
36 3         4 my $group_args = {};
37              
38 3         5 for my $release_key ( @{$release_keys} ) {
  3         6  
39 12 100       28 next unless exists $input_args->{$release_key};
40 6         15 $release_args->{$release_key} = delete $input_args->{$release_key};
41             }
42              
43 3         6 for my $group_key ( @{$group_keys} ) {
  3         8  
44 12 100       21 next unless exists $input_args->{$group_key};
45 6         9 $group_args->{$group_key} = delete $input_args->{$group_key};
46             }
47              
48 3         22 my $release_object = CPAN::Changes::Release->new( %{$release_args} );
  3         21  
49              
50 3         23 for my $change_type ( @{ $self->change_types } ) {
  3         45  
51 9         2390 for my $phase ( @{ $self->phases } ) {
  9         143  
52 36         21465 for my $type ( @{ $self->types } ) {
  36         603  
53 36         555 my $group = CPAN::Changes::Group::Dependencies::Details->new(
54             change_type => $change_type,
55             phase => $phase,
56             type => $type,
57 36         183 %{$group_args},
58             );
59 36 100       6402 next unless $group->has_changes;
60 3         3171 $release_object->attach_group($group);
61             }
62             }
63             }
64 3         1232 return $release_object;
65             }
66              
67             around add_release => sub {
68             my ( $orig, $self, @releases ) = @_;
69             for my $release (@releases) {
70             my $release_object = $self->_mk_release($release);
71             $self->$orig($release_object);
72             }
73             return;
74             };
75              
76 3     3   26 no Moo;
  3         6  
  3         14  
77              
78             1;
79              
80             __END__
81              
82             =pod
83              
84             =encoding UTF-8
85              
86             =head1 NAME
87              
88             CPAN::Changes::Dependencies::Details - Create CPAN::Changes style file only containing dependency change information
89              
90             =head1 VERSION
91              
92             version 0.001004
93              
94             =head1 SYNOPSIS
95              
96             use CPAN::Changes::Dependencies::Details;
97             my $details = CPAN::Changes::Dependencies::Details->new(
98             preamble => "Some message",
99             change_types => [qw( Added Changed Removed )],
100             phases => [qw( build configure runtime test )],
101             types => [qw( requires recommends )],
102             );
103              
104             $changes->add_release({
105             version => '0.002',
106             date => '2009-07-06',
107             old_prereqs => CPAN::Meta->load_file('Dist-Foo-0.001/META.json')->effective_prereqs,
108             new_prereqs => CPAN::Meta->load_file('Dist-Foo-0.002/META.json')->effective_prereqs,
109             });
110              
111             print $changes->serialize;
112              
113             =head1 AUTHOR
114              
115             Kent Fredric <kentnl@cpan.org>
116              
117             =head1 COPYRIGHT AND LICENSE
118              
119             This software is copyright (c) 2014 by Kent Fredric <kentfredric@gmail.com>.
120              
121             This is free software; you can redistribute it and/or modify it under
122             the same terms as the Perl 5 programming language system itself.
123              
124             =cut