| 1 | package Perinci::To::PackageBase; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Data::Dump::OneLine qw(dump1); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Log::ger; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Perinci::Object; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 4 | with 'Perinci::To::Doc::Role::Section'; | |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | 4 | has name => (is=>'rw'); | |||||||||||||||||||||||||||||||||||||
| 12 | 4 | has meta => (is=>'rw'); | |||||||||||||||||||||||||||||||||||||
| 13 | 4 | has url => (is=>'rw'); | |||||||||||||||||||||||||||||||||||||
| 14 | 4 | has child_metas => (is=>'rw'); | |||||||||||||||||||||||||||||||||||||
| 15 | 4 | has _pa => (is=>'rw'); | |||||||||||||||||||||||||||||||||||||
| 16 | 4 | has exports => (is=>'rw'); # hash, key=function name, val=0|1|2 (see Perinci::Sub::To::FuncBase's export) | |||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | 4 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||
| 19 | 4 | our $DATE = '2023-07-09'; # DATE | |||||||||||||||||||||||||||||||||||||
| 20 | 4 | our $DIST = 'Perinci-To-Doc'; # DIST | |||||||||||||||||||||||||||||||||||||
| 21 | 4 | our $VERSION = '0.881'; # VERSION | |||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=5 SCAR=17.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | $args->{meta} or die "Please specify meta"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | $args->{child_metas} or die "Please specify child_metas"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 28 | $self->{doc_sections} //= [ | ||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | 'summary', | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"doc_sections"} //= ["summary", "version", "description", "functions", "methods", "links"]
MC/DC0%0/1
$self->{"doc_sections"} //= ["summary", "version", "description", "functions", "methods", "links"]
$self->{"doc_sections"}
Truth table50%1/2
A
A= $self->{"doc_sections"}
| |||||||||||||||||||||||||||||||||||||||
| 30 | 'version', | ||||||||||||||||||||||||||||||||||||||
| 31 | 'description', | ||||||||||||||||||||||||||||||||||||||
| 32 | 'functions', | ||||||||||||||||||||||||||||||||||||||
| 33 | 'methods', | ||||||||||||||||||||||||||||||||||||||
| 34 | 'links', | ||||||||||||||||||||||||||||||||||||||
| 35 | ]; | ||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | $self->{_pa} //= do { | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"_pa"} //= do {
require Perinci::Access;
"Perinci::Access"->new
}
MC/DC0%0/2
$self->{"_pa"} //= do {
require Perinci::Access;
"Perinci::Access"->new
}
$self->{"_pa"}
do {
require Perinci::Access;
"Perinci::Access"->new
}
Truth table33%1/3
A //= B
A= $self->{"_pa"}B= do {
require Perinci::Access;
"Perinci::Access"->new
}
| |||||||||||||||||||||||||||||||||||||||
| 37 | 1 | require Perinci::Access; | |||||||||||||||||||||||||||||||||||||
| 38 | 1 | Perinci::Access->new; | |||||||||||||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub before_gen_doc { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
before_gen_doc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 44 | 0 | log_trace("=> PackageBase's before_gen_doc(opts=%s)", \%opts); | |||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | # initialize hash to store [intermediate] result | ||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $self->{_doc_res} = {}; | |||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | # provide simple default implementation without any text wrapping. subclass such | ||||||||||||||||||||||||||||||||||||||
| 51 | # as Perinci::To::Text will use another implementation, one that supports text | ||||||||||||||||||||||||||||||||||||||
| 52 | # wrapping for example (provided by | ||||||||||||||||||||||||||||||||||||||
| 53 | # Perinci::To::Doc::Role::Section::AddTextLines). | ||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub add_doc_lines { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
add_doc_lines: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $opts; | |||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (ref($_[0]) eq 'HASH') { $opts = shift } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts //= {}
MC/DC0%0/1
$opts //= {}
$opts
Truth table0%0/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my @lines = map { $_ . (/\n\z/s ? "" : "\n") } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | map {/\n/ ? split /\n/ : $_} @_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $indent = $self->doc_indent_str x $self->doc_indent_level; | |||||||||||||||||||||||||||||||||||||
| 64 | 0 | push @{$self->doc_lines}, | |||||||||||||||||||||||||||||||||||||
| 65 | 0 | map {"$indent$_"} @lines; | |||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub gen_doc_section_summary { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_doc_section_summary: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $rimeta = rimeta($self->meta); | |||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $dres = $self->{_doc_res}; | |||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $name = $self->name // $rimeta->langprop("name") // "UnnamedModule"; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
($self->name // $rimeta->langprop("name")) // "UnnamedModule"
$self->name // $rimeta->langprop("name")
MC/DC0%0/2
($self->name // $rimeta->langprop("name")) // "UnnamedModule"
$self->name
$rimeta->langprop("name")
Truth table0%0/3
A // B
A= $self->nameB= $rimeta->langprop("name")
| |||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $summary = $rimeta->langprop("summary"); | |||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $dres->{name} = $name; | |||||||||||||||||||||||||||||||||||||
| 78 | 0 | $dres->{summary} = $summary; | |||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub gen_doc_section_version { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_doc_section_version: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub gen_doc_section_description { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_doc_section_description: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $rimeta = rimeta($self->meta); | |||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $dres = $self->{_doc_res}; | |||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $dres->{description} = $rimeta->langprop("description"); | |||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub gen_doc_section_functions { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_doc_section_functions: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 94 | 0 | require Perinci::Sub::To::FuncBase; | |||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $cmetas = $self->child_metas; | |||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $dres = $self->{_doc_res}; | |||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | # list all functions | ||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my @func_uris = grep {m!(\A|/)\w+\z!} sort keys %$cmetas; | |||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | # generate doc for all functions | ||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $dres->{functions} = {}; | |||||||||||||||||||||||||||||||||||||
| 106 | 0 | $dres->{function_names_by_meta_addr} = {}; | |||||||||||||||||||||||||||||||||||||
| 107 | 0 | for my $furi (@func_uris) { | |||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $fname = $furi; $fname =~ s!.+/!!; | |||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $meta = $cmetas->{$furi}; | |||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | next if $meta->{'x.no_index'} || grep { $_ eq 'hidden' } @{ $meta->{tags} // [] }; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$meta->{"x.no_index"} or grep {$_ eq "hidden";} @{$meta->{"tags"} // [];}
$meta->{"tags"} // []
MC/DC0%0/2
$meta->{"x.no_index"} or grep {$_ eq "hidden";} @{$meta->{"tags"} // [];}
$meta->{"x.no_index"}
grep {$_ eq "hidden";} @{$meta->{"tags"} // [];}
MC/DC0%0/1
$meta->{"tags"} // []
$meta->{"tags"}
Truth table0%0/3
A or B
A= $meta->{"x.no_index"}B= grep {$_ eq "hidden";} @{$meta->{"tags"} // [];}
Truth table0%0/2
A
A= $meta->{"tags"}
| |||||||||||||||||||||||||||||||||||||||
| 111 | 0 | push @{ $dres->{function_names_by_meta_addr}{"$meta"} }, $fname; | |||||||||||||||||||||||||||||||||||||
| 112 | $dres->{functions}{$furi} = | ||||||||||||||||||||||||||||||||||||||
| 113 | $self->_gen_func_doc( | ||||||||||||||||||||||||||||||||||||||
| 114 | parent=>$self, | ||||||||||||||||||||||||||||||||||||||
| 115 | name=>$fname, | ||||||||||||||||||||||||||||||||||||||
| 116 | meta=>$meta, | ||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | url=> ($self->{url}//'') . $furi, | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"url"} // ""
MC/DC0%0/1
$self->{"url"} // ""
$self->{"url"}
Truth table0%0/2
A
A= $self->{"url"}
| |||||||||||||||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $dres->{function_metas}{$furi} = $meta; | |||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub gen_doc_section_methods { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_doc_section_methods: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 124 | # already done by gen_doc_section_functions | ||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub gen_doc_section_links { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_doc_section_links: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||
| 130 | 4 | 1; | |||||||||||||||||||||||||||||||||||||
| 131 | # ABSTRACT: Base class for Perinci::To::* package documentation generators | ||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||||||||||||