/[Search-Estraier]/trunk/Estraier.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by dpavlin, Wed Jan 4 13:11:43 2006 UTC revision 6 by dpavlin, Wed Jan 4 14:48:11 2006 UTC
# Line 58  sub new { Line 58  sub new {
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 {
# Line 72  sub add_attr { Line 81  sub add_attr {
81          my $attrs = {@_};          my $attrs = {@_};
82    
83          while (my ($name, $value) = each %{ $attrs }) {          while (my ($name, $value) = each %{ $attrs }) {
84                  $name =~ s/\s\s+/ /gs;                  push @{ $self->{attrs}->{_s($name)} }, _s($value);
85                  $value =~ s/\s\s+/ /gs;          }
86                  push @{$self->{$name}}, $value;  }
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
145    
146    Empty document object
147    
148      $doc->delete;
149    
150    =cut
151    
152    sub delete {
153            my $self = shift;
154    
155            foreach my $data (qw/attrs dtexts stexts/) {
156                    delete($self->{$data});
157          }          }
158    
159            return 1;
160    }
161    
162    
163    =head2 _s
164    
165    Remove multiple whitespaces from string, as well as whitespaces at beginning or end
166    
167     my $text = _s(" this  is a text  ");
168     $text = 'this is a text';
169    
170    =cut
171    
172    sub _s {
173            my $text = shift || return;
174            $text =~ s/\s\s+/ /gs;
175            $text =~ s/^\s+//;
176            $text =~ s/\s+$//;
177            return $text;
178  }  }
179    
180    

Legend:
Removed from v.2  
changed lines
  Added in v.6

  ViewVC Help
Powered by ViewVC 1.1.26