43 |
|
|
44 |
package Search::Estraier::Document; |
package Search::Estraier::Document; |
45 |
|
|
46 |
use Carp qw/confess/; |
use Carp qw/croak confess/; |
47 |
|
|
48 |
=head1 Search::Estraier::Document |
=head1 Search::Estraier::Document |
49 |
|
|
72 |
|
|
73 |
$doc->add_attr( name => 'value' ); |
$doc->add_attr( name => 'value' ); |
74 |
|
|
75 |
B<FIXME>: delete attribute using |
Delete attribute using |
76 |
|
|
77 |
$doc->add_attr( name => undef ); |
$doc->add_attr( name => undef ); |
78 |
|
|
83 |
my $attrs = {@_}; |
my $attrs = {@_}; |
84 |
|
|
85 |
while (my ($name, $value) = each %{ $attrs }) { |
while (my ($name, $value) = each %{ $attrs }) { |
86 |
$self->{attrs}->{_s($name)} = _s($value); |
if (! defined($value)) { |
87 |
|
delete( $self->{attrs}->{_s($name)} ); |
88 |
|
} else { |
89 |
|
$self->{attrs}->{_s($name)} = _s($value); |
90 |
|
} |
91 |
} |
} |
92 |
|
|
93 |
return 1; |
return 1; |
142 |
|
|
143 |
=head2 attr_names |
=head2 attr_names |
144 |
|
|
145 |
Get a list of attribute names of a document object. |
Returns array with attribute names from document object. |
146 |
|
|
147 |
my @attrs = $doc->attr_names; |
my @attrs = $doc->attr_names; |
148 |
|
|
150 |
|
|
151 |
sub attr_names { |
sub attr_names { |
152 |
my $self = shift; |
my $self = shift; |
153 |
confess "attr_names return array, not scalar" if (! wantarray); |
croak "attr_names return array, not scalar" if (! wantarray); |
154 |
return sort keys %{ $self->{attrs} }; |
return sort keys %{ $self->{attrs} }; |
155 |
} |
} |
156 |
|
|
157 |
|
|
158 |
=head2 attr |
=head2 attr |
159 |
|
|
160 |
Get the value of an attribute. |
Returns value of an attribute. |
161 |
|
|
162 |
my $value = $doc->attr( 'attribute' ); |
my $value = $doc->attr( 'attribute' ); |
163 |
|
|
170 |
return $self->{'attrs'}->{ $name }; |
return $self->{'attrs'}->{ $name }; |
171 |
} |
} |
172 |
|
|
173 |
|
|
174 |
|
=head2 texts |
175 |
|
|
176 |
|
Returns array with text sentences. |
177 |
|
|
178 |
|
my @texts = $doc->texts; |
179 |
|
|
180 |
|
=cut |
181 |
|
|
182 |
|
sub texts { |
183 |
|
my $self = shift; |
184 |
|
confess "attr_names return array, not scalar" if (! wantarray); |
185 |
|
return $self->{dtexts}; |
186 |
|
} |
187 |
|
|
188 |
=head2 dump_draft |
=head2 dump_draft |
189 |
|
|
190 |
print $doc->dump_draft; |
print $doc->dump_draft; |
192 |
=cut |
=cut |
193 |
|
|
194 |
sub dump_draft { |
sub dump_draft { |
195 |
|
return 'FIXME'; |
196 |
} |
} |
197 |
|
|
198 |
=head2 delete |
=head2 delete |