| 1 | # Copyrights 2003-2021 by [Mark Overmeer]. | ||
| 2 | # For other contributors see ChangeLog. | ||
| 3 | # See the manual pages for details on the licensing terms. | ||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||
| 5 | # This code is part of perl distribution OODoc. It is licensed under the | ||
| 6 | # same terms as Perl itself: https://spdx.org/licenses/Artistic-2.0.html | ||
| 7 | |||
| 8 | package OODoc::Text::Chapter; | ||
| 9 | use vars '$VERSION'; | ||
| 10 | $VERSION = '2.02'; | ||
| 11 | |||
| 12 | use base 'OODoc::Text::Structure'; | ||
| 13 | |||
| 14 | use strict; | ||
| 15 | use warnings; | ||
| 16 | |||
| 17 | use Log::Report 'oodoc'; | ||
| 18 | use List::Util 'first'; | ||
| 19 | |||
| 20 | |||
| 21 | sub init($) | ||
| 22 | { my ($self, $args) = @_; | ||
| 23 | $args->{type} ||= 'Chapter'; | ||
| 24 | $args->{container} ||= delete $args->{manual} or panic; | ||
| 25 | $args->{level} ||= 1; | ||
| 26 | |||
| 27 | $self->SUPER::init($args) | ||
| 28 | or return; | ||
| 29 | |||
| 30 | $self->{OTC_sections} = []; | ||
| 31 | |||
| 32 | $self; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub emptyExtension($) | ||
| 36 | { my ($self, $container) = @_; | ||
| 37 | my $empty = $self->SUPER::emptyExtension($container); | ||
| 38 | my @sections = map $_->emptyExtension($empty), $self->sections; | ||
| 39 | $empty->sections(@sections); | ||
| 40 | $empty; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub manual() {shift->container} | ||
| 44 | sub path() {shift->name} | ||
| 45 | |||
| 46 | sub findSubroutine($) | ||
| 47 | { my ($self, $name) = @_; | ||
| 48 | my $sub = $self->SUPER::findSubroutine($name); | ||
| 49 | return $sub if defined $sub; | ||
| 50 | |||
| 51 | foreach my $section ($self->sections) | ||
| 52 | { my $sub = $section->findSubroutine($name); | ||
| 53 | return $sub if defined $sub; | ||
| 54 | } | ||
| 55 | |||
| 56 | undef; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub findEntry($) | ||
| 60 | { my ($self, $name) = @_; | ||
| 61 | return $self if $self->name eq $name; | ||
| 62 | |||
| 63 | foreach my $section ($self->sections) | ||
| 64 | { my $entry = $section->findEntry($name); | ||
| 65 | return $entry if defined $entry; | ||
| 66 | } | ||
| 67 | |||
| 68 | (); | ||
| 69 | } | ||
| 70 | |||
| 71 | sub all($@) | ||
| 72 | { my $self = shift; | ||
| 73 | ($self->SUPER::all(@_), map {$_->all(@_)} $self->sections); | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | sub section($) | ||
| 78 | { my ($self, $thing) = @_; | ||
| 79 | |||
| 80 | if(ref $thing) | ||
| 81 | { push @{$self->{OTC_sections}}, $thing; | ||
| 82 | return $thing; | ||
| 83 | } | ||
| 84 | |||
| 85 | first {$_->name eq $thing} $self->sections; | ||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 89 | sub sections() | ||
| 90 | { my $self = shift; | ||
| 91 | if(@_) | ||
| 92 | { $self->{OTC_sections} = [ @_ ]; | ||
| 93 | $_->container($self) for @_; | ||
| 94 | } | ||
| 95 | @{$self->{OTC_sections}}; | ||
| 96 | } | ||
| 97 | |||
| 98 | 1; |