File Coverage

lib/Pod/PseudoPod/DOM/Corpus.pm
Criterion Covered Total %
statement 21 60 35.0
branch 0 2 0.0
condition n/a
subroutine 7 17 41.1
pod 0 10 0.0
total 28 89 31.4


line stmt bran cond sub pod time code
1             package Pod::PseudoPod::DOM::Corpus;
2             # ABSTRACT: a collection of documents which share metadata elements
3              
4 1     1   7 use strict;
  1         2  
  1         35  
5 1     1   5 use warnings;
  1         2  
  1         35  
6              
7 1     1   5 use Moose;
  1         2  
  1         6  
8 1     1   8222 use Path::Class;
  1         28958  
  1         71  
9              
10 1     1   459 use Pod::PseudoPod::DOM::Index;
  1         391  
  1         46  
11 1     1   587 use Pod::PseudoPod::DOM::TableOfContents;
  1         384  
  1         37  
12 1     1   7 use Pod::PseudoPod::DOM::App 'open_fh';
  1         2  
  1         801  
13              
14             has 'documents', is => 'ro', default => sub { [] };
15             has 'references', is => 'ro', default => sub { {} };
16             has 'index', is => 'ro',
17             default => sub { Pod::PseudoPod::DOM::Index->new };
18             has 'contents', is => 'ro',
19             default => sub { Pod::PseudoPod::DOM::TableOfContents->new };
20              
21             sub add_document
22             {
23 0     0 0   my ($self, $document) = @_;
24 0           push @{ $self->documents }, $document;
  0            
25 0           $self->add_index_from_document( $document );
26 0           $self->add_references_from_document( $document );
27 0           $self->add_contents_from_document( $document );
28             }
29              
30             sub add_index_from_document
31             {
32 0     0 0   my ($self, $document) = @_;
33 0           $self->index->add_document( $document );
34             }
35              
36             sub add_references_from_document
37             {
38 0     0 0   my ($self, $document) = @_;
39             }
40              
41             sub add_contents_from_document
42             {
43 0     0 0   my ($self, $document) = @_;
44 0           $self->contents->add_document( $document );
45             }
46              
47             sub get_index
48             {
49 0     0 0   my $self = shift;
50 0           return $self->index->emit_index;
51             }
52              
53             sub get_toc
54             {
55 0     0 0   my $self = shift;
56 0           return $self->contents->emit_toc;
57             }
58              
59             sub write_documents
60             {
61 0     0 0   my $self = shift;
62 0           my $documents = $self->documents;
63              
64 0           $_->resolve_anchors for @$documents;
65              
66 0           for my $doc (@$documents)
67             {
68 0           my $output = $doc->filename;
69 0           my $outfh = open_fh( $output, '>' );
70 0           print {$outfh} $doc->emit;
  0            
71             }
72             }
73              
74             sub write_index
75             {
76 0     0 0   my $self = shift;
77 0           my $outfh = $self->get_fh_in_path( 'theindex', '>' );
78 0           print {$outfh} $self->get_index;
  0            
79             }
80              
81             sub write_toc
82             {
83 0     0 0   my $self = shift;
84 0           my $outfh = $self->get_fh_in_path( 'index', '>' );
85 0           print {$outfh} $self->get_toc;
  0            
86             }
87              
88             sub get_fh_in_path
89             {
90 0     0 0   my ($self, $filename, $mode) = @_;
91 0           my $docs = $self->documents;
92 0 0         return unless @$docs;
93              
94 0           my $docfile = $docs->[0]->filename;
95 0           my ($suffix) = $docfile =~ /\.(.+)$/;
96 0           my $dir = file( $docfile )->dir;
97 0           my $file = $dir->file( $filename . '.' . $suffix );
98              
99 0           return open_fh( $file->stringify, $mode );
100             }
101              
102             __PACKAGE__->meta->make_immutable;
103              
104             __END__
105              
106             =pod
107              
108             =encoding UTF-8
109              
110             =head1 NAME
111              
112             Pod::PseudoPod::DOM::Corpus - a collection of documents which share metadata elements
113              
114             =head1 VERSION
115              
116             version 1.20210620.2004
117              
118             =head1 AUTHOR
119              
120             chromatic <chromatic@wgz.org>
121              
122             =head1 COPYRIGHT AND LICENSE
123              
124             This software is copyright (c) 2021 by chromatic.
125              
126             This is free software; you can redistribute it and/or modify it under
127             the same terms as the Perl 5 programming language system itself.
128              
129             =cut