File Coverage

blib/lib/Swim/Plugin/cpan.pm
Criterion Covered Total %
statement 82 87 94.2
branch 20 40 50.0
condition 1 3 33.3
subroutine 10 10 100.0
pod 0 8 0.0
total 113 148 76.3


line stmt bran cond sub pod time code
1 2     2   46858 use strict; use warnings;
  2     2   4  
  2         72  
  2         8  
  2         2  
  2         1881  
2             package Swim::Plugin::cpan;
3             our $VERSION = '0.0.5';
4              
5             package Swim::Pod;
6              
7             sub block_func_cpan_head {
8 1     1 0 23 my ($self, $args) = @_;
9 1         5 $self->create_output($args, [ qw(name badge) ]);
10             }
11              
12             sub block_func_cpan_tail {
13 1     1 0 45575 my ($self, $args) = @_;
14 1         6 my $meta = $self->meta;
15 1 50       11 $meta->{author} = [ $meta->{author} ]
16             unless ref($meta->{author}) eq 'ARRAY';
17 1   33     9 $meta->{author}[0]{copyright} ||= $meta->{copyright};
18 1         5 $self->create_output($args, [ qw(author copyright) ]);
19             }
20              
21             sub create_output {
22 2     2 0 4 my ($self, $args, $sections) = @_;
23              
24 2         8 my @args = grep $_, split /\s+/, $args;
25 2 100       8 if (@args) {
26 1 50       5 if (not grep /^[-+]/, @args) {
27 0         0 @$sections = @args;
28             }
29             else {
30 1         3 for my $arg (@args) {
31 1 50       4 if ($arg =~ /^-(.*)/) {
32 0         0 @$sections = grep { $_ ne $1 } @$sections;
  0         0  
33             }
34             else {
35 1         4 $arg =~ s/^\+//;
36 1         2 @$sections = grep { $_ ne $arg } @$sections;
  2         3  
37 1 50       6 if ($arg =~ /^(see)/) {
38 1         3 unshift @$sections, $arg;
39             }
40             else {
41 0         0 push @$sections, $arg;
42             }
43             }
44             }
45             }
46             }
47              
48 2         3 my @output;
49 2         4 for my $section (@$sections) {
50 5         7 my $method = "add_$section";
51 5 50       18 my $output = $self->$method or next;
52 5         9 push @output, $output;
53             }
54 2         10 return join "\n", @output;
55             }
56              
57             sub add_name {
58 1     1 0 1 my ($self) = @_;
59 1         5 my $meta = $self->meta;
60 1         15 my $uc = $self->option->{'pod-upper-head'};
61 1 50       37 my $head_name = $uc ? 'NAME' : 'Name';
62 1         4 (my $name = $meta->{name}) =~ s/-/::/g;
63 1         6 return <<"...";
64             =head1 $head_name
65              
66             $name - $meta->{abstract}
67             ...
68             }
69              
70             sub add_badge {
71 1     1 0 1 my ($self) = @_;
72 1         3 my $meta = $self->meta;
73 1         3 my $out = '';
74 1         1 while (1) {
75 1 50       6 my $badge = $self->{meta}{badge} or return;
76 1 50       3 $badge = [$badge] unless ref $badge;
77 1 50       5 my $repo = $meta->{devel}{git} or return;
78 1 50       13 $repo =~ s!.*[:/]([^/]+)/([^/]+?)(?:\.git)?$!$1/$2!
79             or return;
80 1 50       51 eval "require Swim::Plugin::badge; 1" or return;
81 1         7 $out .= "\n" . $self->phrase_func_badge("@$badge $repo");
82 1         28 $out =~ s/\n+\z/\n/;
83 1         3 $out =~ s/\A\n+//;
84 1         4 return $out;
85             }
86             }
87              
88             sub add_see {
89 1     1 0 1 my ($self, $args) = @_;
90 1         3 my $meta = $self->meta;
91 1         6 my $uc = $self->option->{'pod-upper-head'};
92 1 50       5 my $head_see = $uc ? 'SEE ALSO' : 'See Also';
93 1         2 my $out = '';
94 1 50       27 if (my $see = $meta->{see}) {
95 1         5 $out .= "=head1 $head_see\n\n=over\n\n";
96 1 50       4 $see = [$see] unless ref $see;
97 1         4 for (@$see) {
98 2         7 $out .= "=item * L<$_>\n\n";
99             }
100 1         3 $out .= "=back\n";
101             }
102 1         7 return $out;
103             }
104              
105             sub add_author {
106 1     1 0 3 my ($self) = @_;
107 1         4 my $meta = $self->meta;
108 1         8 my $uc = $self->option->{'pod-upper-head'};
109 1 50       9 my $head_author = $uc ? 'AUTHOR' : 'Author';
110 1         1 my $authors = $meta->{author};
111 1 50       4 if (@$authors > 1) {
112 0 0       0 $head_author = $uc ? 'AUTHORS' : 'Authors';
113             }
114 1         3 my $out .= "=head1 $head_author\n\n";
115 1         2 for my $author (@$authors) {
116 1         4 $out .= "$author->{name} <$author->{email}>\n\n";
117             }
118 1         2 chomp $out;
119 1         3 return $out;
120             }
121              
122             sub add_copyright {
123 1     1 0 2 my ($self, $args) = @_;
124 1         3 my $meta = $self->meta;
125 1         5 my $uc = $self->option->{'pod-upper-head'};
126 1 50       6 my $head_copyright = $uc
127             ? 'COPYRIGHT AND LICENSE'
128             : 'Copyright and License';
129 1         3 my $authors = $meta->{author};
130 1         3 my $out = "=head1 $head_copyright\n\n";
131 1         2 for my $author (@$authors) {
132 1 50       3 if ($author->{copyright}) {
133 1         4 $out .= "Copyright $author->{copyright}. $author->{name}.\n\n";
134             }
135             }
136              
137 1         3 return $out . <<'...';
138             This program is free software; you can redistribute it and/or modify it under
139             the same terms as Perl itself.
140              
141             See L
142             ...
143             }
144              
145             1;