1####################################################################################################################################
2# DOC HTML ELEMENT MODULE
3####################################################################################################################################
4package pgBackRestDoc::Html::DocHtmlElement;
5
6use strict;
7use warnings FATAL => qw(all);
8use Carp qw(confess);
9
10use Exporter qw(import);
11    our @EXPORT = qw();
12use Scalar::Util qw(blessed);
13
14use pgBackRestDoc::Common::Log;
15
16####################################################################################################################################
17# Html Element Types
18####################################################################################################################################
19use constant HTML_A                                                 => 'a';
20    push @EXPORT, qw(HTML_A);
21use constant HTML_BODY                                              => 'body';
22    push @EXPORT, qw(HTML_BODY);
23use constant HTML_PRE                                               => 'pre';
24    push @EXPORT, qw(HTML_PRE);
25use constant HTML_DIV                                               => 'div';
26    push @EXPORT, qw(HTML_DIV);
27use constant HTML_SPAN                                              => 'span';
28    push @EXPORT, qw(HTML_SPAN);
29use constant HTML_TABLE                                             => 'table';
30    push @EXPORT, qw(HTML_TABLE);
31use constant HTML_TABLE_CAPTION                                     => 'caption';
32    push @EXPORT, qw(HTML_TABLE_CAPTION);
33use constant HTML_TD                                                => 'td';
34    push @EXPORT, qw(HTML_TD);
35use constant HTML_TH                                                => 'th';
36    push @EXPORT, qw(HTML_TH);
37use constant HTML_TR                                                => 'tr';
38    push @EXPORT, qw(HTML_TR);
39use constant HTML_UL                                                => 'ul';
40    push @EXPORT, qw(HTML_UL);
41use constant HTML_LI                                                => 'li';
42    push @EXPORT, qw(HTML_LI);
43
44####################################################################################################################################
45# CONSTRUCTOR
46####################################################################################################################################
47sub new
48{
49    my $class = shift;       # Class name
50
51    # Create the class hash
52    my $self = {};
53    bless $self, $class;
54
55    $self->{strClass} = $class;
56
57    # Assign function parameters, defaults, and log debug info
58    (
59        my $strOperation,
60        $self->{strType},
61        $self->{strClass},
62        my $oParam
63    ) =
64        logDebugParam
65        (
66            __PACKAGE__ . '->new', \@_,
67            {name => 'strType', trace => true},
68            {name => 'strClass', required => false, trace => true},
69            {name => 'oParam', required => false, trace => true}
70        );
71
72    $self->{oyElement} = [];
73    $self->{strContent} = $$oParam{strContent};
74    $self->{strId} = $$oParam{strId};
75    $self->{strRef} = $$oParam{strRef};
76    $self->{strExtra} = $$oParam{strExtra};
77    $self->{bPre} = $$oParam{bPre};
78
79    # Return from function and log return values if any
80    return logDebugReturn
81    (
82        $strOperation,
83        {name => 'self', value => $self}
84    );
85}
86
87####################################################################################################################################
88# addNew
89#
90# Create a new element and add it.
91####################################################################################################################################
92sub addNew
93{
94    my $self = shift;
95
96    # Assign function parameters, defaults, and log debug info
97    my (
98        $strOperation,
99        $strType,
100        $strClass,
101        $oParam
102    ) =
103        logDebugParam
104        (
105            __PACKAGE__ . '->addNew', \@_,
106            {name => 'strType', trace => true},
107            {name => 'strClass', required => false, trace => true},
108            {name => 'oParam', required => false, trace => true}
109        );
110
111    my $oElement = new pgBackRestDoc::Html::DocHtmlElement($strType, $strClass, $oParam);
112
113    $self->add($oElement);
114
115    # Return from function and log return values if any
116    return logDebugReturn
117    (
118        $strOperation,
119        {name => 'oElement', value => $oElement, trace => true}
120    );
121}
122
123####################################################################################################################################
124# add
125#
126# Add an element.
127####################################################################################################################################
128sub add
129{
130    my $self = shift;
131
132    # Assign function parameters, defaults, and log debug info
133    my (
134        $strOperation,
135        $oElement
136    ) =
137        logDebugParam
138        (
139            __PACKAGE__ . '->add', \@_,
140            {name => 'oElement', trace => true}
141        );
142
143    if (!(blessed($oElement) && $oElement->isa('pgBackRestDoc::Html::DocHtmlElement')))
144    {
145        confess &log(ASSERT, 'oElement must be a valid element object');
146    }
147
148    push(@{$self->{oyElement}}, $oElement);
149
150    # Return from function and log return values if any
151    return logDebugReturn
152    (
153        $strOperation,
154        {name => 'oElement', value => $oElement, trace => true}
155    );
156}
157
1581;
159