File Coverage

blib/lib/Perinci/To/PackageBase.pm
Criterion Covered Total %
statement 21 66 31.8
branch 2 12 16.6
condition 2 19 10.5
subroutine 6 14 42.8
pod 0 9 0.0
total 31 120 25.8


line stmt bran cond sub pod time code
1             package Perinci::To::PackageBase;
2              
3             our $DATE = '2021-02-21'; # DATE
4             our $VERSION = '0.875'; # VERSION
5              
6 1     1   795 use 5.010;
  1         4  
7 1     1   524 use Data::Dump::OneLine qw(dump1);
  1         3306  
  1         82  
8 1     1   12 use Log::ger;
  1         3  
  1         12  
9 1     1   244 use Moo;
  1         2  
  1         10  
10 1     1   436 use Perinci::Object;
  1         2  
  1         1002  
11              
12             with 'Perinci::To::Doc::Role::Section';
13              
14             has name => (is=>'rw');
15             has meta => (is=>'rw');
16             has url => (is=>'rw');
17             has child_metas => (is=>'rw');
18             has _pa => (is=>'rw');
19             has exports => (is=>'rw'); # hash, key=function name, val=0|1|2 (see Perinci::Sub::To::FuncBase's export)
20              
21             sub BUILD {
22 1     1 0 12 my ($self, $args) = @_;
23              
24 1 50       5 $args->{meta} or die "Please specify meta";
25 1 50       5 $args->{child_metas} or die "Please specify child_metas";
26             $self->{doc_sections} //= [
27 1   50     11 'summary',
28             'version',
29             'description',
30             'functions',
31             'methods',
32             'links',
33             ];
34 1   33     8 $self->{_pa} //= do {
35 1         1104 require Perinci::Access;
36 1         1297 Perinci::Access->new;
37             };
38             }
39              
40             sub before_gen_doc {
41 0     0 0   my ($self, %opts) = @_;
42 0           log_trace("=> PackageBase's before_gen_doc(opts=%s)", \%opts);
43              
44             # initialize hash to store [intermediate] result
45 0           $self->{_doc_res} = {};
46             }
47              
48             # provide simple default implementation without any text wrapping. subclass such
49             # as Perinci::To::Text will use another implementation, one that supports text
50             # wrapping for example (provided by
51             # Perinci::To::Doc::Role::Section::AddTextLines).
52             sub add_doc_lines {
53 0     0 0   my $self = shift;
54 0           my $opts;
55 0 0         if (ref($_[0]) eq 'HASH') { $opts = shift }
  0            
56 0   0       $opts //= {};
57              
58 0 0         my @lines = map { $_ . (/\n\z/s ? "" : "\n") }
59 0 0         map {/\n/ ? split /\n/ : $_} @_;
  0            
60              
61 0           my $indent = $self->doc_indent_str x $self->doc_indent_level;
62 0           push @{$self->doc_lines},
63 0           map {"$indent$_"} @lines;
  0            
64             }
65              
66             sub gen_doc_section_summary {
67 0     0 0   my ($self) = @_;
68              
69 0           my $rimeta = rimeta($self->meta);
70 0           my $dres = $self->{_doc_res};
71              
72 0   0       my $name = $self->name // $rimeta->langprop("name") // "UnnamedModule";
      0        
73 0           my $summary = $rimeta->langprop("summary");
74              
75 0           $dres->{name} = $name;
76 0           $dres->{summary} = $summary;
77             }
78              
79       0 0   sub gen_doc_section_version {
80             }
81              
82             sub gen_doc_section_description {
83 0     0 0   my ($self) = @_;
84              
85 0           my $rimeta = rimeta($self->meta);
86 0           my $dres = $self->{_doc_res};
87              
88 0           $dres->{description} = $rimeta->langprop("description");
89             }
90              
91             sub gen_doc_section_functions {
92 0     0 0   require Perinci::Sub::To::FuncBase;
93              
94 0           my ($self) = @_;
95              
96 0           my $cmetas = $self->child_metas;
97 0           my $dres = $self->{_doc_res};
98              
99             # list all functions
100 0           my @func_uris = grep {m!(\A|/)\w+\z!} sort keys %$cmetas;
  0            
101              
102             # generate doc for all functions
103 0           $dres->{functions} = {};
104 0           $dres->{function_names_by_meta_addr} = {};
105 0           for my $furi (@func_uris) {
106 0           my $fname = $furi; $fname =~ s!.+/!!;
  0            
107 0           my $meta = $cmetas->{$furi};
108 0 0 0       next if $meta->{'x.no_index'} || grep { $_ eq 'hidden' } @{ $meta->{tags} // [] };
  0   0        
  0            
109 0           push @{ $dres->{function_names_by_meta_addr}{"$meta"} }, $fname;
  0            
110             $dres->{functions}{$furi} =
111             $self->_gen_func_doc(
112             parent=>$self,
113             name=>$fname,
114             meta=>$meta,
115 0   0       url=> ($self->{url}//'') . $furi,
116             );
117 0           $dres->{function_metas}{$furi} = $meta;
118             }
119             }
120              
121       0 0   sub gen_doc_section_methods {
122             # already done by gen_doc_section_functions
123             }
124              
125       0 0   sub gen_doc_section_links {
126             }
127              
128             1;
129             # ABSTRACT: Base class for Perinci::To::* package documentation generators
130              
131             __END__
132              
133             =pod
134              
135             =encoding UTF-8
136              
137             =head1 NAME
138              
139             Perinci::To::PackageBase - Base class for Perinci::To::* package documentation generators
140              
141             =head1 VERSION
142              
143             This document describes version 0.875 of Perinci::To::PackageBase (from Perl distribution Perinci-To-Doc), released on 2021-02-21.
144              
145             =for Pod::Coverage .+
146              
147             =head1 HOMEPAGE
148              
149             Please visit the project's homepage at L<https://metacpan.org/release/Perinci-To-Doc>.
150              
151             =head1 SOURCE
152              
153             Source repository is at L<https://github.com/perlancar/perl-Perinci-To-Doc>.
154              
155             =head1 BUGS
156              
157             Please report any bugs or feature requests on the bugtracker website L<https://github.com/perlancar/perl-Perinci-To-Doc/issues>
158              
159             When submitting a bug or request, please include a test-file or a
160             patch to an existing test-file that illustrates the bug or desired
161             feature.
162              
163             =head1 AUTHOR
164              
165             perlancar <perlancar@cpan.org>
166              
167             =head1 COPYRIGHT AND LICENSE
168              
169             This software is copyright (c) 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013 by perlancar@cpan.org.
170              
171             This is free software; you can redistribute it and/or modify it under
172             the same terms as the Perl 5 programming language system itself.
173              
174             =cut