58 |
my $self = {@_}; |
my $self = {@_}; |
59 |
bless($self, $class); |
bless($self, $class); |
60 |
|
|
61 |
|
$self->{id} = -1; |
62 |
|
|
63 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
64 |
} |
} |
65 |
|
|
66 |
|
|
67 |
=head2 add_attr |
=head2 add_attr |
68 |
|
|
69 |
|
Add an attribute. |
70 |
|
|
71 |
$doc->add_attr( name => 'value' ); |
$doc->add_attr( name => 'value' ); |
72 |
|
|
73 |
|
B<FIXME>: delete attribute using |
74 |
|
|
75 |
|
$doc->add_attr( name => undef ); |
76 |
|
|
77 |
=cut |
=cut |
78 |
|
|
79 |
sub add_attr { |
sub add_attr { |
81 |
my $attrs = {@_}; |
my $attrs = {@_}; |
82 |
|
|
83 |
while (my ($name, $value) = each %{ $attrs }) { |
while (my ($name, $value) = each %{ $attrs }) { |
84 |
push @{$self->{attrs}->{_s($name)}}, _s($value); |
push @{ $self->{attrs}->{_s($name)} }, _s($value); |
85 |
} |
} |
86 |
} |
} |
87 |
|
|
88 |
|
|
89 |
|
=head2 add_text |
90 |
|
|
91 |
|
Add a sentence of text. |
92 |
|
|
93 |
|
$doc->add_text('this is example text to display'); |
94 |
|
|
95 |
|
=cut |
96 |
|
|
97 |
|
sub add_text { |
98 |
|
my $self = shift; |
99 |
|
my $text = shift; |
100 |
|
return unless defined($text); |
101 |
|
|
102 |
|
push @{ $self->{dtexts} }, _s($text); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
=head2 add_hidden_text |
107 |
|
|
108 |
|
Add a hidden sentence. |
109 |
|
|
110 |
|
$doc->add_hidden_text('this is example text just for search'); |
111 |
|
|
112 |
|
=cut |
113 |
|
|
114 |
|
sub add_hidden_text { |
115 |
|
my $self = shift; |
116 |
|
my $text = shift; |
117 |
|
return unless defined($text); |
118 |
|
|
119 |
|
push @{ $self->{htexts} }, _s($text); |
120 |
|
} |
121 |
|
|
122 |
|
=head2 id |
123 |
|
|
124 |
|
Get the ID number of document. If the object has never been registred, C<-1> is returned. |
125 |
|
|
126 |
|
print $doc->id; |
127 |
|
|
128 |
|
=cut |
129 |
|
|
130 |
|
sub id { |
131 |
|
my $self = shift; |
132 |
|
return $self->{id}; |
133 |
|
} |
134 |
|
|
135 |
|
=head2 dump_draft |
136 |
|
|
137 |
|
print $doc->dump_draft; |
138 |
|
|
139 |
|
=cut |
140 |
|
|
141 |
|
sub dump_draft { |
142 |
|
} |
143 |
|
|
144 |
=head2 delete |
=head2 delete |
145 |
|
|
146 |
Empty document object |
Empty document object |
152 |
sub delete { |
sub delete { |
153 |
my $self = shift; |
my $self = shift; |
154 |
|
|
155 |
delete($self->{attrs}); |
foreach my $data (qw/attrs dtexts stexts/) { |
156 |
|
delete($self->{$data}); |
157 |
|
} |
158 |
|
|
159 |
return 1; |
return 1; |
160 |
} |
} |