--- trunk/Estraier.pm 2006/01/04 13:11:43 2 +++ trunk/Estraier.pm 2006/01/04 14:38:35 5 @@ -61,10 +61,15 @@ $self ? return $self : return undef; } + =head2 add_attr $doc->add_attr( name => 'value' ); +B: delete attribute using + + $doc->add_attr( name => undef ); + =cut sub add_attr { @@ -72,10 +77,83 @@ my $attrs = {@_}; while (my ($name, $value) = each %{ $attrs }) { - $name =~ s/\s\s+/ /gs; - $value =~ s/\s\s+/ /gs; - push @{$self->{$name}}, $value; + push @{ $self->{attrs}->{_s($name)} }, _s($value); + } +} + + +=head2 add_text + + $doc->add_text('this is example text to display'); + +=cut + +sub add_text { + my $self = shift; + my $text = shift; + return unless defined($text); + + push @{ $self->{dtexts} }, _s($text); +} + + +=head2 add_hidden_text + + $doc->add_hidden_text('this is example text just for search'); + +=cut + +sub add_hidden_text { + my $self = shift; + my $text = shift; + return unless defined($text); + + push @{ $self->{htexts} }, _s($text); +} + +=head2 dump_draft + + print $doc->dump_draft; + +=cut + +sub dump_draft { +} + +=head2 delete + +Empty document object + + $doc->delete; + +=cut + +sub delete { + my $self = shift; + + foreach my $data (qw/attrs dtexts stexts/) { + delete($self->{$data}); } + + return 1; +} + + +=head2 _s + +Remove multiple whitespaces from string, as well as whitespaces at beginning or end + + my $text = _s(" this is a text "); + $text = 'this is a text'; + +=cut + +sub _s { + my $text = shift || return; + $text =~ s/\s\s+/ /gs; + $text =~ s/^\s+//; + $text =~ s/\s+$//; + return $text; }