| 1 | # Copyrights 2003-2015 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.01. | ||
| 5 | |||
| 6 | package OODoc::Text::Section; | ||
| 7 | use vars '$VERSION'; | ||
| 8 | $VERSION = '2.01'; | ||
| 9 | |||
| 10 | use base 'OODoc::Text::Structure'; | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use warnings; | ||
| 14 | |||
| 15 | use Log::Report 'oodoc'; | ||
| 16 | use List::Util 'first'; | ||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 | sub init($) | ||
| 21 | { my ($self, $args) = @_; | ||
| 22 | $args->{type} ||= 'Section'; | ||
| 23 | $args->{level} ||= 2; | ||
| 24 | $args->{container} ||= delete $args->{chapter} or panic; | ||
| 25 | |||
| 26 | $self->SUPER::init($args) or return; | ||
| 27 | |||
| 28 | $self->{OTS_subsections} = []; | ||
| 29 | $self; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub emptyExtension($) | ||
| 33 | { my ($self, $container) = @_; | ||
| 34 | my $empty = $self->SUPER::emptyExtension($container); | ||
| 35 | my @subsections = map $_->emptyExtension($empty), $self->subsections; | ||
| 36 | $empty->subsections(@subsections); | ||
| 37 | $empty; | ||
| 38 | } | ||
| 39 | |||
| 40 | #------------------------------------------- | ||
| 41 | |||
| 42 | |||
| 43 | sub chapter() { shift->container } | ||
| 44 | |||
| 45 | sub path() | ||
| 46 | { my $self = shift; | ||
| 47 | $self->chapter->path . '/' . $self->name; | ||
| 48 | } | ||
| 49 | |||
| 50 | sub findSubroutine($) | ||
| 51 | { my ($self, $name) = @_; | ||
| 52 | my $sub = $self->SUPER::findSubroutine($name); | ||
| 53 | return $sub if defined $sub; | ||
| 54 | |||
| 55 | foreach my $subsection ($self->subsections) | ||
| 56 | { my $sub = $subsection->findSubroutine($name); | ||
| 57 | return $sub if defined $sub; | ||
| 58 | } | ||
| 59 | |||
| 60 | undef; | ||
| 61 | } | ||
| 62 | |||
| 63 | sub findEntry($) | ||
| 64 | { my ($self, $name) = @_; | ||
| 65 | return $self if $self->name eq $name; | ||
| 66 | my $subsect = $self->subsection($name); | ||
| 67 | defined $subsect ? $subsect : (); | ||
| 68 | } | ||
| 69 | |||
| 70 | sub all($@) | ||
| 71 | { my $self = shift; | ||
| 72 | ($self->SUPER::all(@_), map {$_->all(@_)} $self->subsections); | ||
| 73 | } | ||
| 74 | |||
| 75 | #------------------------------------------- | ||
| 76 | |||
| 77 | |||
| 78 | sub subsection($) | ||
| 79 | { my ($self, $thing) = @_; | ||
| 80 | if(ref $thing) | ||
| 81 | { push @{$self->{OTS_subsections}}, $thing; | ||
| 82 | return $thing; | ||
| 83 | } | ||
| 84 | |||
| 85 | first {$_->name eq $thing} $self->subsections; | ||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 89 | sub subsections(;@) | ||
| 90 | { my $self = shift; | ||
| 91 | if(@_) | ||
| 92 | { $self->{OTS_subsections} = [ @_ ]; | ||
| 93 | $_->container($self) for @_; | ||
| 94 | } | ||
| 95 | |||
| 96 | @{$self->{OTS_subsections}}; | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | 1; |