| 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::Structure; | ||
| 9 | use vars '$VERSION'; | ||
| 10 | $VERSION = '2.02'; | ||
| 11 | |||
| 12 | use base 'OODoc::Text'; | ||
| 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 | $self->SUPER::init($args) or return; | ||
| 24 | $self->{OTS_subs} = []; | ||
| 25 | $self->{OTS_level} = delete $args->{level} | ||
| 26 | or panic "no level defined for structural component"; | ||
| 27 | $self; | ||
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | sub emptyExtension($) | ||
| 32 | { my ($self, $container) = @_; | ||
| 33 | |||
| 34 | my $new = ref($self)->new | ||
| 35 | ( name => $self->name | ||
| 36 | , linenr => -1 | ||
| 37 | , level => $self->level | ||
| 38 | , container => $container | ||
| 39 | ); | ||
| 40 | $new->extends($self); | ||
| 41 | $new; | ||
| 42 | } | ||
| 43 | |||
| 44 | #------------------------------------------- | ||
| 45 | |||
| 46 | |||
| 47 | sub level() {shift->{OTS_level}} | ||
| 48 | |||
| 49 | |||
| 50 | sub niceName() | ||
| 51 | { my $name = shift->name; | ||
| 52 | $name =~ m/[a-z]/ ? $name : ucfirst(lc $name); | ||
| 53 | } | ||
| 54 | |||
| 55 | #------------------------------------------- | ||
| 56 | |||
| 57 | |||
| 58 | sub path() { panic "Not implemented" } | ||
| 59 | |||
| 60 | |||
| 61 | sub findEntry($) { panic "Not implemented" } | ||
| 62 | |||
| 63 | #------------------------------------------- | ||
| 64 | |||
| 65 | |||
| 66 | sub all($@) | ||
| 67 | { my ($self, $method) = (shift, shift); | ||
| 68 | $self->$method(@_); | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | sub isEmpty() | ||
| 73 | { my $self = shift; | ||
| 74 | |||
| 75 | my $manual = $self->manual; | ||
| 76 | return 0 if $self->description !~ m/^\s*$/; | ||
| 77 | return 0 if first {!$manual->inherited($_)} | ||
| 78 | $self->examples, $self->subroutines; | ||
| 79 | |||
| 80 | my @nested | ||
| 81 | = $self->isa('OODoc::Text::Chapter') ? $self->sections | ||
| 82 | : $self->isa('OODoc::Text::Section') ? $self->subsections | ||
| 83 | : $self->isa('OODoc::Text::SubSection') ? $self->subsubsections | ||
| 84 | : return 1; | ||
| 85 | |||
| 86 | not first {!$_->isEmpty} @nested; | ||
| 87 | } | ||
| 88 | |||
| 89 | #------------------- | ||
| 90 | |||
| 91 | sub addSubroutine(@) | ||
| 92 | { my $self = shift; | ||
| 93 | push @{$self->{OTS_subs}}, @_; | ||
| 94 | $_->container($self) for @_; | ||
| 95 | $self; | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 99 | sub subroutines() { @{shift->{OTS_subs}} } | ||
| 100 | |||
| 101 | |||
| 102 | sub subroutine($) | ||
| 103 | { my ($self, $name) = @_; | ||
| 104 | first {$_->name eq $name} $self->subroutines; | ||
| 105 | } | ||
| 106 | |||
| 107 | |||
| 108 | sub setSubroutines($) | ||
| 109 | { my $self = shift; | ||
| 110 | $self->{OTS_subs} = shift || []; | ||
| 111 | } | ||
| 112 | |||
| 113 | #------------------------------------------- | ||
| 114 | |||
| 115 | |||
| 116 | |||
| 117 | 1; |