File Coverage

blib/lib/Stardoc/Document/Pod.pm
Criterion Covered Total %
statement 52 53 98.1
branch 12 16 75.0
condition 7 7 100.0
subroutine 12 13 92.3
pod 0 3 0.0
total 83 92 90.2


line stmt bran cond sub pod time code
1             ##
2             # name: Stardoc::Document::Pod
3             # abstract: Stardoc Pod Generator
4             # author: Ingy döt Net
5             # copyright: 2011
6             # license: perl
7              
8             package Stardoc::Document::Pod;
9 1     1   15 use Mouse;
  1         3  
  1         6  
10              
11 1     1   1734 use Template::Toolkit::Simple;
  1         105497  
  1         87  
12 1     1   14 use IO::All;
  1         2  
  1         11  
13              
14             has module => (
15             is => 'ro',
16             );
17              
18             my $layout = [
19             {name => 'encoding', requires => ['encoding']},
20             {name => 'name', requires => ['name', 'abstract']},
21             'synopsis',
22             'description',
23             'other',
24             {name => 'see', requires => ['see']},
25             {name => 'author', requires => ['author']},
26             {name => 'license', requires => ['copyright']},
27             {name => 'cut'},
28             ];
29              
30             sub format {
31 2     2 0 4 my ($self) = @_;
32 2         6 my $module = $self->module;
33 2         12 my $data = $module->meta;
34 2         3 my $pod = '';
35              
36             OUTER:
37 2         5 for my $entry (@$layout) {
38 18 100       195482 my $name = ref($entry) ? $entry->{name} : $entry;
39 18 100 100     223 if ($name eq 'other') {
    100          
    50          
40 2         3 for my $section (@{$module->other}) {
  2         12  
41 2 50       7 $pod .= "\n" if $pod;
42 2         9 $pod .= $section->{text};
43             }
44             }
45             elsif ($module->can($name) and $module->$name) {
46 4 50       14 $pod .= "\n" if $pod;
47 4         19 $pod .= $module->$name->{text};
48             }
49             elsif (ref $entry) {
50 12   100     52 my $requires = $entry->{requires} || [];
51 12   100     63 $data->{$_} or next OUTER for @$requires;
52 11 100       33 $pod .= "\n" if $pod;
53 11         34 $pod .= $self->format_template($name, $data);
54             }
55             }
56 2         3079 return $pod;
57             }
58              
59             sub format_template {
60 11     11 0 22 my ($self, $name, $data) = @_;
61 11 50       20 my $template = eval {
62 11         82 Stardoc::Pod::Templates->$name;
63             } or next;
64 11         42 tt->render(\$template, $data);
65             }
66              
67 0     0 0   sub format_section {
68             }
69              
70             package Stardoc::Pod::Templates;
71              
72 1     1   1185 use constant name => <<'...';
  1         2  
  1         114  
73             =head1 NAME
74              
75             [% name %] - [% abstract %]
76             ...
77              
78 1     1   6 use constant status => <<'...';
  1         1  
  1         126  
79             =head1 STATUS
80              
81             [% status %]
82             ...
83              
84 1     1   5 use constant encoding => <<'...';
  1         3  
  1         60  
85             =encoding [% encoding %]
86             ...
87              
88 1     1   5 use constant see => <<'...';
  1         1  
  1         51  
89             =head1 SEE ALSO
90              
91             =over
92             [% FOR also = see %]
93             =item *
94              
95             L<[% also %]>
96             [% END %]
97             =back
98             ...
99              
100 1     1   5 use constant author => <<'...';
  1         2  
  1         60  
101             =head1 AUTHOR
102              
103             [% author.0.name %][% IF author.0.email %] <[% author.0.email %]>[% END %]
104             ...
105              
106 1     1   5 use constant license => <<'...';
  1         3  
  1         51  
107             =head1 COPYRIGHT AND LICENSE
108              
109             Copyright (c) [% copyright %]. [% author.0.name %].
110              
111             This program is free software; you can redistribute it and/or modify it
112             under the same terms as Perl itself.
113              
114             See http://www.perl.com/perl/misc/Artistic.html
115             ...
116              
117 1     1   5 use constant cut => <<'...';
  1         2  
  1         57  
118             =cut
119             ...
120              
121             1;