/[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

Contents of /trunk/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations)
Wed Jan 4 13:33:07 2006 UTC (18 years, 2 months ago) by dpavlin
File size: 2988 byte(s)
added $doc->delete and internal _s
1 package Search::Estraier;
2
3 use 5.008;
4 use strict;
5 use warnings;
6
7 require Exporter;
8
9 our @ISA = qw(Exporter);
10
11 our %EXPORT_TAGS = ( 'all' => [ qw(
12 ) ] );
13
14 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
15
16 our @EXPORT = qw(
17 );
18
19 our $VERSION = '0.00';
20
21 use Carp;
22
23 =head1 NAME
24
25 Search::Estraier - pure perl module to use Hyper Estraier search engine
26
27 =head1 SYNOPSIS
28
29 use Search::Estraier;
30 my $est = new Search::Estraier();
31
32 =head1 DESCRIPTION
33
34 This module is implementation of node API of Hyper Estraier. Since it's
35 perl-only module with dependencies only on standard perl modules, it will
36 run on all platforms on which perl runs. It doesn't require compilation
37 or Hyper Estraier development files on target machine.
38
39 It is implemented as multiple packages which closly resamble Ruby
40 implementation. It also includes methods to manage nodes.
41
42 =cut
43
44 package Search::Estraier::Document;
45
46 =head1 Search::Estraier::Document
47
48 Document for HyperEstraier
49
50 =head2 new
51
52 my $doc = new Search::HyperEstraier::Document;
53
54 =cut
55
56 sub new {
57 my $class = shift;
58 my $self = {@_};
59 bless($self, $class);
60
61 $self ? return $self : return undef;
62 }
63
64
65 =head2 add_attr
66
67 $doc->add_attr( name => 'value' );
68
69 =cut
70
71 sub add_attr {
72 my $self = shift;
73 my $attrs = {@_};
74
75 while (my ($name, $value) = each %{ $attrs }) {
76 push @{$self->{attrs}->{_s($name)}}, _s($value);
77 }
78 }
79
80 =head2 delete
81
82 Empty document object
83
84 $doc->delete;
85
86 =cut
87
88 sub delete {
89 my $self = shift;
90
91 delete($self->{attrs});
92
93 return 1;
94 }
95
96
97 =head2 _s
98
99 Remove multiple whitespaces from string, as well as whitespaces at beginning or end
100
101 my $text = _s(" this is a text ");
102 $text = 'this is a text';
103
104 =cut
105
106 sub _s {
107 my $text = shift || return;
108 $text =~ s/\s\s+/ /gs;
109 $text =~ s/^\s+//;
110 $text =~ s/\s+$//;
111 return $text;
112 }
113
114
115
116 package Search::Estraier::Master;
117
118 use Carp;
119
120 =head1 Search::Estraier::Master
121
122 Controll node master. This requires user with administration priviledges.
123
124 =cut
125
126 {
127 package RequestAgent;
128 @ISA = qw(LWP::UserAgent);
129
130 sub new {
131 my $self = LWP::UserAgent::new(@_);
132 $self->agent("Search-Estraier/$Search::Estraer::VERSION");
133 $self;
134 }
135
136 sub get_basic_credentials {
137 my($self, $realm, $uri) = @_;
138 # return ($user, $password);
139 }
140 }
141
142
143
144 =head2 new
145
146 Create new connection to node master.
147
148 my $master = new Search::Estraier::Master(
149 url => 'http://localhost:1978',
150 user => 'admin',
151 passwd => 'admin',
152 );
153
154 =cut
155
156 sub new {
157 my $class = shift;
158 my $self = {@_};
159 bless($self, $class);
160
161 foreach my $p (qw/url user passwd/) {
162 croak "need $p" unless ($self->{$p});
163 }
164
165 $self ? return $self : return undef;
166 }
167
168
169
170 ###
171
172 =head1 EXPORT
173
174 Nothing.
175
176 =head1 SEE ALSO
177
178 L<http://hyperestraier.sourceforge.net/>
179
180 Hyper Estraier Ruby interface on which this module is based.
181
182 =head1 AUTHOR
183
184 Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt>
185
186
187 =head1 COPYRIGHT AND LICENSE
188
189 Copyright (C) 2005 by Dobrica Pavlinusic
190
191 This library is free software; you can redistribute it and/or modify
192 it under the GPL v2 or later.
193
194 =cut
195
196 1;

  ViewVC Help
Powered by ViewVC 1.1.26