line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::ChangesFromYaml::Convert; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.005'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
48
|
use 5.010; |
|
2
|
|
|
|
|
4
|
|
7
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
39
|
|
8
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
9
|
2
|
|
|
2
|
|
7
|
use Carp; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
118
|
|
10
|
2
|
|
|
2
|
|
751
|
use YAML::XS; |
|
2
|
|
|
|
|
3890
|
|
|
2
|
|
|
|
|
92
|
|
11
|
2
|
|
|
2
|
|
874
|
use CPAN::Changes; |
|
2
|
|
|
|
|
11309
|
|
|
2
|
|
|
|
|
57
|
|
12
|
2
|
|
|
2
|
|
1064
|
use DateTime::Format::CLDR; |
|
2
|
|
|
|
|
151670
|
|
|
2
|
|
|
|
|
176
|
|
13
|
2
|
|
|
2
|
|
42
|
use Exporter 'import'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
756
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(convert); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub convert { |
17
|
2
|
|
|
2
|
0
|
4
|
my ( $changes_yml, $dateformat ) = @_; |
18
|
2
|
|
|
|
|
15
|
my $changes = CPAN::Changes->new; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
255
|
my @releases = Load($changes_yml); |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
8
|
for (@releases) { |
23
|
6
|
100
|
|
|
|
55
|
if ($dateformat) { |
24
|
3
|
|
|
|
|
9
|
$_->{date} = _convert_date( $_->{date}, $dateformat ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
my $rel = CPAN::Changes::Release->new( |
27
|
|
|
|
|
|
|
version => $_->{version}, |
28
|
|
|
|
|
|
|
date => $_->{date}, |
29
|
6
|
|
|
|
|
1851
|
); |
30
|
|
|
|
|
|
|
|
31
|
6
|
|
|
|
|
57
|
$rel->add_changes($_) for @{ $_->{changes} }; |
|
6
|
|
|
|
|
23
|
|
32
|
6
|
|
|
|
|
177
|
$changes->add_release($rel); |
33
|
|
|
|
|
|
|
} |
34
|
2
|
|
|
|
|
26
|
return $changes->serialize; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _convert_date { |
38
|
3
|
|
|
3
|
|
4
|
my ( $date, $format ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# `date` outputs: |
41
|
|
|
|
|
|
|
# pattern => 'ccc MMM dd HH:mm:ss zzz yyyy' |
42
|
|
|
|
|
|
|
# Ugly hack. ccc doesn't seem to recognize UTC |
43
|
|
|
|
|
|
|
# I don't know if this replacement is technically correct but solves my problem now. |
44
|
3
|
50
|
33
|
|
|
23
|
if ($format =~ /ccc/ and $date =~ /UTC/) { |
45
|
0
|
|
|
|
|
0
|
$date =~ s/UTC/GMT/; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
16
|
my $dt = |
49
|
|
|
|
|
|
|
DateTime::Format::CLDR->new( pattern => $format )->parse_datetime($date); |
50
|
|
|
|
|
|
|
|
51
|
3
|
50
|
|
|
|
9028
|
croak "Failed to parse date ($date) using dateformat ($format)" |
52
|
|
|
|
|
|
|
unless $dt; |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
|
|
119
|
return DateTime::Format::CLDR->new( pattern => 'yyyy-MM-dd HH:mm:ss zzz' ) |
55
|
|
|
|
|
|
|
->format_datetime($dt); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |