File: Type.pm

package info (click to toggle)
naturaldocs 1.51-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,304 kB
  • sloc: perl: 17,534; javascript: 1,925; makefile: 6; sh: 1
file content (152 lines) | stat: -rw-r--r-- 5,237 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
###############################################################################
#
#   Package: NaturalDocs::Topics::Type
#
###############################################################################
#
#   A class storing information about a <TopicType>.
#
###############################################################################

# This file is part of Natural Docs, which is Copyright  2003-2010 Greg Valure
# Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
# Refer to License.txt for the complete details

use strict;
use integer;


package NaturalDocs::Topics::Type;

use NaturalDocs::DefineMembers 'NAME',                         'Name()',
                                                 'PLURAL_NAME',             'PluralName()',      'SetPluralName()',
                                                 'INDEX',                        'Index()',              'SetIndex()',
                                                 'SCOPE',                       'Scope()',              'SetScope()',
                                                 'PAGE_TITLE_IF_FIRST', 'PageTitleIfFirst()', 'SetPageTitleIfFirst()',
                                                 'BREAK_LISTS',             'BreakLists()',        'SetBreakLists()',
                                                 'CLASS_HIERARCHY',    'ClassHierarchy()',  'SetClassHierarchy()',
                                                 'CAN_GROUP_WITH';

# Dependency: New() depends on the order of these and that there are no parent classes.

use base 'Exporter';
our @EXPORT = ('SCOPE_NORMAL', 'SCOPE_START', 'SCOPE_END', 'SCOPE_ALWAYS_GLOBAL');

#
#   Constants: Members
#
#   The object is implemented as a blessed arrayref, with the following constants as its indexes.
#
#   NAME - The topic's name.
#   PLURAL_NAME - The topic's plural name.
#   INDEX - Whether the topic is indexed.
#   SCOPE - The topic's <ScopeType>.
#   PAGE_TITLE_IF_FIRST - Whether the topic becomes the page title if it's first in a file.
#   BREAK_LISTS - Whether list topics should be broken into individual topics in the output.
#   CLASS_HIERARCHY - Whether the topic is part of the class hierarchy.
#   CAN_GROUP_WITH - The existence hashref of <TopicTypes> the type can be grouped with.
#



###############################################################################
# Group: Types


#
#   Constants: ScopeType
#
#   The possible values for <Scope()>.
#
#   SCOPE_NORMAL - The topic stays in the current scope without affecting it.
#   SCOPE_START - The topic starts a scope.
#   SCOPE_END - The topic ends a scope, returning it to global.
#   SCOPE_ALWAYS_GLOBAL - The topic is always global, but it doesn't affect the current scope.
#
use constant SCOPE_NORMAL => 1;
use constant SCOPE_START => 2;
use constant SCOPE_END => 3;
use constant SCOPE_ALWAYS_GLOBAL => 4;



###############################################################################
# Group: Functions


#
#   Function: New
#
#   Creates and returns a new object.
#
#   Parameters:
#
#       name - The topic name.
#       pluralName - The topic's plural name.
#       index - Whether the topic is indexed.
#       scope - The topic's <ScopeType>.
#       pageTitleIfFirst - Whether the topic becomes the page title if it's the first one in a file.
#       breakLists - Whether list topics should be broken into individual topics in the output.
#
sub New #(name, pluralName, index, scope, pageTitleIfFirst, breakLists)
    {
    my ($self, @params) = @_;

    # Dependency: Depends on the parameter order matching the member order and that there are no parent classes.

    my $object = [ @params ];
    bless $object, $self;

    return $object;
    };


#
#   Functions: Accessors
#
#   Name - Returns the topic name.
#   PluralName - Returns the topic's plural name.
#   SetPluralName - Replaces the topic's plural name.
#   Index - Whether the topic is indexed.
#   SetIndex - Sets whether the topic is indexed.
#   Scope - Returns the topic's <ScopeType>.
#   SetScope - Replaces the topic's <ScopeType>.
#   PageTitleIfFirst - Returns whether the topic becomes the page title if it's first in the file.
#   SetPageTitleIfFirst - Sets whether the topic becomes the page title if it's first in the file.
#   BreakLists - Returns whether list topics should be broken into individual topics in the output.
#   SetBreakLists - Sets whether list topics should be broken into individual topics in the output.
#   ClassHierarchy - Returns whether the topic is part of the class hierarchy.
#   SetClassHierarchy - Sets whether the topic is part of the class hierarchy.
#


#
#   Function: CanGroupWith
#
#   Returns whether the type can be grouped with the passed <TopicType>.
#
sub CanGroupWith #(TopicType type) -> bool
    {
    my ($self, $type) = @_;
    return ( defined $self->[CAN_GROUP_WITH] && exists $self->[CAN_GROUP_WITH]->{$type} );
    };


#
#   Function: SetCanGroupWith
#
#   Sets the list of <TopicTypes> the type can be grouped with.
#
sub SetCanGroupWith #(TopicType[] types)
    {
    my ($self, $types) = @_;

    $self->[CAN_GROUP_WITH] = { };

    foreach my $type (@$types)
        {  $self->[CAN_GROUP_WITH]->{$type} = 1;  };
    };



1;