--- trunk/Estraier.pm 2006/01/04 14:57:27 7 +++ trunk/Estraier.pm 2006/01/04 19:28:30 12 @@ -43,7 +43,7 @@ package Search::Estraier::Document; -use Carp qw/confess/; +use Carp qw/croak confess/; =head1 Search::Estraier::Document @@ -72,7 +72,7 @@ $doc->add_attr( name => 'value' ); -B: delete attribute using +Delete attribute using $doc->add_attr( name => undef ); @@ -83,8 +83,14 @@ my $attrs = {@_}; while (my ($name, $value) = each %{ $attrs }) { - push @{ $self->{attrs}->{_s($name)} }, _s($value); + if (! defined($value)) { + delete( $self->{attrs}->{_s($name)} ); + } else { + $self->{attrs}->{_s($name)} = _s($value); + } } + + return 1; } @@ -136,7 +142,7 @@ =head2 attr_names -Get a list of attribute names of a document object. +Returns array with attribute names from document object. my @attrs = $doc->attr_names; @@ -144,10 +150,54 @@ sub attr_names { my $self = shift; - confess "attr_names return array, not scalar" if (! wantarray); + croak "attr_names return array, not scalar" if (! wantarray); return sort keys %{ $self->{attrs} }; } + +=head2 attr + +Returns value of an attribute. + + my $value = $doc->attr( 'attribute' ); + +=cut + +sub attr { + my $self = shift; + my $name = shift; + + return $self->{'attrs'}->{ $name }; +} + + +=head2 texts + +Returns array with text sentences. + + my @texts = $doc->texts; + +=cut + +sub texts { + my $self = shift; + confess "texts return array, not scalar" if (! wantarray); + return @{ $self->{dtexts} }; +} + +=head2 cat_texts + +Return whole text as single scalar. + + my $text = $doc->cat_texts; + +=cut + +sub cat_texts { + my $self = shift; + return join(' ',@{ $self->{dtexts} }); +} + =head2 dump_draft print $doc->dump_draft; @@ -155,6 +205,7 @@ =cut sub dump_draft { + return 'FIXME'; } =head2 delete @@ -172,6 +223,8 @@ delete($self->{$data}); } + $self->{id} = -1; + return 1; }