| 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; | ||
| 7 | use vars '$VERSION'; | ||
| 8 | $VERSION = '2.01'; | ||
| 9 | |||
| 10 | use base 'OODoc::Object'; | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use warnings; | ||
| 14 | |||
| 15 | use Log::Report 'oodoc'; | ||
| 16 | |||
| 17 | |||
| 18 | use overload '==' => sub {$_[0]->unique == $_[1]->unique} | ||
| 19 | , '!=' => sub {$_[0]->unique != $_[1]->unique} | ||
| 20 | , '""' => sub {$_[0]->name} | ||
| 21 | , 'cmp' => sub {$_[0]->name cmp "$_[1]"} | ||
| 22 | , 'bool' => sub {1}; | ||
| 23 | |||
| 24 | #------------------------------------------- | ||
| 25 | |||
| 26 | |||
| 27 | my $unique = 1; | ||
| 28 | |||
| 29 | sub init($) | ||
| 30 | { my ($self, $args) = @_; | ||
| 31 | $self->SUPER::init($args) or return; | ||
| 32 | |||
| 33 | $self->{OT_name} = delete $args->{name}; | ||
| 34 | |||
| 35 | my $nr = $self->{OT_linenr} = delete $args->{linenr} or panic; | ||
| 36 | $self->{OT_type} = delete $args->{type} or panic; | ||
| 37 | |||
| 38 | exists $args->{container} # may be explicit undef | ||
| 39 | or panic "no text container specified for the {pkg} object" | ||
| 40 | , pkg => ref $self; | ||
| 41 | |||
| 42 | # may be undef | ||
| 43 | $self->{OT_container}= delete $args->{container}; | ||
| 44 | |||
| 45 | $self->{OT_descr} = delete $args->{description} || ''; | ||
| 46 | $self->{OT_examples} = []; | ||
| 47 | $self->{OT_unique} = $unique++; | ||
| 48 | |||
| 49 | $self; | ||
| 50 | } | ||
| 51 | |||
| 52 | #------------------------------------------- | ||
| 53 | |||
| 54 | |||
| 55 | sub name() {shift->{OT_name}} | ||
| 56 | |||
| 57 | |||
| 58 | sub type() {shift->{OT_type}} | ||
| 59 | |||
| 60 | |||
| 61 | sub description() | ||
| 62 | { my $text = shift->{OT_descr}; | ||
| 63 | my @lines = split /^/m, $text; | ||
| 64 | shift @lines while @lines && $lines[ 0] =~ m/^\s*$/; | ||
| 65 | pop @lines while @lines && $lines[-1] =~ m/^\s*$/; | ||
| 66 | join '', @lines; | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | sub container(;$) | ||
| 71 | { my $self = shift; | ||
| 72 | @_ ? ($self->{OT_container} = shift) : $self->{OT_container}; | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | sub manual(;$) | ||
| 77 | { my $self = shift; | ||
| 78 | @_ ? $self->SUPER::manual(@_) | ||
| 79 | : $self->container->manual; | ||
| 80 | } | ||
| 81 | |||
| 82 | |||
| 83 | sub unique() {shift->{OT_unique}} | ||
| 84 | |||
| 85 | |||
| 86 | sub where() | ||
| 87 | { my $self = shift; | ||
| 88 | ($self->manual->source, $self->{OT_linenr}); | ||
| 89 | } | ||
| 90 | |||
| 91 | #------------------------------------------- | ||
| 92 | |||
| 93 | |||
| 94 | sub openDescription() { \shift->{OT_descr} } | ||
| 95 | |||
| 96 | |||
| 97 | sub findDescriptionObject() | ||
| 98 | { my $self = shift; | ||
| 99 | return $self if length $self->description; | ||
| 100 | |||
| 101 | my @descr = map { $_->findDescriptionObject } $self->extends; | ||
| 102 | wantarray ? @descr : $descr[0]; | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | sub example($) | ||
| 107 | { my ($self, $example) = @_; | ||
| 108 | push @{$self->{OT_examples}}, $example; | ||
| 109 | $example; | ||
| 110 | } | ||
| 111 | |||
| 112 | |||
| 113 | sub examples() { @{shift->{OT_examples}} } | ||
| 114 | |||
| 115 | #------------------------------------------- | ||
| 116 | |||
| 117 | |||
| 118 | 1; |