Changeset 1920
- Timestamp:
- 03/04/07 21:32:53 (1 year ago)
- Files:
-
- libswish3/trunk/bindings/perl/3.xs (modified) (8 diffs)
- libswish3/trunk/bindings/perl/MANIFEST (modified) (1 diff)
- libswish3/trunk/bindings/perl/Makefile.PL (modified) (1 diff)
- libswish3/trunk/bindings/perl/lib/SWISH/3.pm (modified) (7 diffs)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Config.pm (modified) (1 diff)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Index.pm (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Indexer (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Indexer.pm (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Indexer/Doc.pm (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Indexer/Xapian (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Indexer/Xapian.pm (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Indexer/Xapian/Doc.pm (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Object.pm (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Parser (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Parser.pm (added)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Data.pm (moved) (moved from libswish3/trunk/bindings/perl/lib/SWISH/3/Data.pm) (3 diffs)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Doc.pm (moved) (moved from libswish3/trunk/bindings/perl/lib/SWISH/3/Doc.pm) (1 diff)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/MetaName.pm (moved) (moved from libswish3/trunk/bindings/perl/lib/SWISH/3/MetaName.pm) (1 diff)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Property.pm (moved) (moved from libswish3/trunk/bindings/perl/lib/SWISH/3/Property.pm) (1 diff)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Word.pm (moved) (moved from libswish3/trunk/bindings/perl/lib/SWISH/3/Word.pm) (2 diffs)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/WordList.pm (moved) (moved from libswish3/trunk/bindings/perl/lib/SWISH/3/WordList.pm) (1 diff)
- libswish3/trunk/bindings/perl/t/01slurp.t (modified) (1 diff)
- libswish3/trunk/bindings/perl/t/02xml2_version.t (modified) (1 diff)
- libswish3/trunk/bindings/perl/t/03parse_file.t (modified) (1 diff)
- libswish3/trunk/bindings/perl/t/04subclass.t (modified) (2 diffs)
- libswish3/trunk/bindings/perl/t/05latin1.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/bindings/perl/3.xs
r1914 r1920 44 44 static char * callback_method = "handler"; 45 45 static HV * SubClasses = (HV*)NULL; 46 static int nClasses = 7;46 static int nClasses = 5; /* match Classes[] ?? */ 47 47 static char * Classes[] = { 48 48 "Doc", … … 215 215 216 216 /*************************************************************************************/ 217 218 MODULE = SWISH::3 PACKAGE = SWISH::3 217 MODULE = SWISH::3 PACKAGE = SWISH::3 218 219 PROTOTYPES: disable 220 221 SV* 222 xml2_version(self) 223 SV* self; 224 225 CODE: 226 RETVAL = newSVpvn( LIBXML_DOTTED_VERSION, strlen(LIBXML_DOTTED_VERSION) ); 227 228 OUTPUT: 229 RETVAL 230 231 232 SV* 233 swish_version(self) 234 SV* self; 235 236 CODE: 237 RETVAL = newSVpvn( SWISH_VERSION, strlen(SWISH_VERSION) ); 238 239 OUTPUT: 240 RETVAL 241 242 # ********************************************************************************* 243 244 MODULE = SWISH::3 PACKAGE = SWISH::3::Parser 219 245 220 246 PROTOTYPES: enable 221 247 248 void 249 _make_subclasses (self) 250 SV * self 251 252 PREINIT: 253 char* class; 254 255 CODE: 256 class = sv_reftype(SvRV(self), 1); 257 //printf("parent class is %s\n", class); 258 _make_subclasses(class); 259 222 260 223 261 void … … 241 279 RETVAL 242 280 243 244 SV*245 libxml2_version(self)246 SV* self;247 248 CODE:249 RETVAL = newSVpvn( LIBXML_DOTTED_VERSION, strlen(LIBXML_DOTTED_VERSION) );250 251 OUTPUT:252 RETVAL253 254 255 void256 _make_subclasses (self)257 SV * self258 259 PREINIT:260 char* class;261 262 CODE:263 class = sv_reftype(SvRV(self), 1);264 //printf("parent class is %s\n", class);265 _make_subclasses(class);266 267 281 268 282 void … … 345 359 # ******************************************************************************* 346 360 347 MODULE = SWISH::3 PACKAGE = SWISH::3:: Word361 MODULE = SWISH::3 PACKAGE = SWISH::3::Parser::Word 348 362 349 363 PROTOTYPES: disable … … 399 413 # ******************************************************************************* 400 414 401 MODULE = SWISH::3 PACKAGE = SWISH::3:: Doc415 MODULE = SWISH::3 PACKAGE = SWISH::3::Parser::Doc 402 416 403 417 PROTOTYPES: disable … … 484 498 # ******************************************************************************* 485 499 486 MODULE = SWISH::3 PACKAGE = SWISH::3::P roperty500 MODULE = SWISH::3 PACKAGE = SWISH::3::Parser::Property 487 501 488 502 PROTOTYPES: disable … … 492 506 # ******************************************************************************* 493 507 494 MODULE = SWISH::3 PACKAGE = SWISH::3:: WordList508 MODULE = SWISH::3 PACKAGE = SWISH::3::Parser::WordList 495 509 496 510 PROTOTYPES: disable … … 523 537 # ******************************************************************************* 524 538 525 MODULE = SWISH::3 PACKAGE = SWISH::3:: Data539 MODULE = SWISH::3 PACKAGE = SWISH::3::Parser::Data 526 540 527 541 PROTOTYPES: disable libswish3/trunk/bindings/perl/MANIFEST
r1914 r1920 7 7 t/SWISH-3.t 8 8 lib/SWISH/3.pm 9 lib/SWISH/3/Doc.pm 10 lib/SWISH/3/Property.pm 11 lib/SWISH/3/MetaName.pm 12 lib/SWISH/3/Word.pm 13 lib/SWISH/3/WordList.pm 9 lib/SWISH/3/Parser.pm 10 lib/SWISH/3/Parser/Doc.pm 11 lib/SWISH/3/Parser/Property.pm 12 lib/SWISH/3/Parser/MetaName.pm 13 lib/SWISH/3/Parser/Word.pm 14 lib/SWISH/3/Parser/WordList.pm 14 15 lib/SWISH/3/Config.pm 15 lib/SWISH/3/ Data.pm16 lib/SWISH/3/Parser/Data.pm libswish3/trunk/bindings/perl/Makefile.PL
r1914 r1920 9 9 (ABSTRACT_FROM => 'lib/SWISH/3.pm', 10 10 AUTHOR => 'Peter Karman <perl@peknet.com>') : ()), 11 LIBS => ['-L/ usr/local/lib -lswish3 -lxml2'],11 LIBS => ['-L/opt/local/lib -L/usr/local/lib -lswish3 -lxml2'], 12 12 DEFINE => '', # e.g., '-DHAVE_SOMETHING' 13 INC => '-I/ usr/include/libxml2 -I/usr/local/include/libxml2 -I.',13 INC => '-I/opt/local/include/libxml2 -I/usr/local/include/libxml2 -I.', 14 14 # Un-comment this if you add C files to link with later: 15 15 # OBJECT => '$(O_FILES)', # link all the C files too libswish3/trunk/bindings/perl/lib/SWISH/3.pm
r1914 r1920 1 1 package SWISH::3; 2 2 3 use 5.8.3; 3 4 use strict; 4 5 use warnings; … … 9 10 use Data::Dump qw(pp); 10 11 11 use base qw(Class::Accessor::Fast);12 13 12 require XSLoader; 14 13 XSLoader::load('SWISH::3', $VERSION); … … 16 15 # defer till runtime so any constants can load 17 16 require SWISH::3::Config; 18 require SWISH::3::Data; 19 require SWISH::3::Doc; 20 require SWISH::3::MetaName; 21 require SWISH::3::Property; 22 require SWISH::3::Word; 23 require SWISH::3::WordList; 24 require SWISH::Doc; 25 26 use Devel::Peek; 17 require SWISH::3::Parser; 27 18 28 19 29 __PACKAGE__->mk_accessors(qw/ config handler /); 30 31 sub new 32 { 33 my $proto = shift; 34 my $class = ref($proto) || $proto; 35 my $self = {}; 36 37 bless($self, $class); 38 $self->_make_subclasses; 39 $self->_init(@_); 40 $self->_init_parser; 41 return $self; 42 } 43 44 sub DESTROY 45 { 46 my $self = shift; 47 48 #carp "about to DESTROY 3 object"; 49 #Dump $self; 50 51 $self->_free; 52 $self->_cleanup; 53 } 54 55 sub _init 56 { 57 my $self = shift; 58 if (@_) 59 { 60 my %extra = @_; 61 @$self{keys %extra} = values %extra; 62 } 63 64 my $conf = SWISH::3::Config->new; 65 66 if ($self->config) 67 { 68 $conf->add($self->config); 69 } 70 71 $self->config($conf); 72 73 unless (exists($self->{handler}) && ref($self->{handler}) eq 'CODE') 74 { 75 carp 76 "WARNING: using default 3 handler -- that's likely not what you want"; 77 $self->handler(\&def_handler); 78 } 79 } 80 81 sub debug 82 { 83 my $self = shift; 84 85 $self->config->debug; 86 87 } 88 89 sub def_handler 90 { 91 my $data = shift; 92 93 select(STDERR); 94 95 #print '~' x 80, "\n"; 96 97 my $props = $data->config->properties; 98 99 #print "Properties\n"; 100 for my $p (keys %$props) 101 { 102 my $v = $data->property($p); 103 my $type = $props->{$p}; 104 105 #print " <$p type='$type'>$v</$p>\n"; 106 } 107 108 #print "Doc\n"; 109 for my $d (@SWISH::Doc::Fields) 110 { 111 112 #printf("%15s: %s\n", $d, $data->doc->$d); 113 } 114 115 #print "WordList\n"; 116 while (my $swishword = $data->wordlist->next) 117 { 118 for my $w (@SWISH::3::Word::Fields) 119 { 120 121 #printf("%15s: %s\n", $w, $swishword->$w); 122 } 123 } 124 125 } 20 # variables used by various classes 21 our @DocFields = qw( mtime size encoding mime uri nwords ext parser ); 22 our @WordFields = qw( word position metaname start_offset end_offset ); 126 23 127 24 1; … … 136 33 use SWISH::3; 137 34 138 my $parser = SWISH::3->new( 139 config => 'path/to/my_file.conf', 140 handler => \&handler 141 ); 142 143 my $indexer = MyIndexer->new(); 35 my $xml2_version = SWISH::3->xml2_version; 36 my $swish3_version = $SWISH::3::VERSION; 144 37 145 $indexer->open_index;146 147 for my $file (@list_of_files_from_somewhere)148 {149 $parser->parse_file($file);150 }151 152 $indexer->close_index;153 154 sub handler155 {156 my $data = shift;157 158 my $doc_id = $indexer->add_doc( $data );159 $indexer->add_properties( $data, $doc_id );160 $indexer->add_words( $data, $doc_id );161 }162 163 38 164 39 =head1 DESCRIPTION … … 166 41 167 42 168 =head1 METHODS43 =head1 CLASS METHODS 169 44 170 =head2 new 171 172 =head2 parse_file 173 174 =head2 parse_buf 45 =head2 make_subclasses 175 46 176 47 … … 178 49 =head1 UTILITY METHODS 179 50 180 =head2 libxml2_version 181 182 =head2 slurp_file 51 =head2 xml2_version 183 52 184 53 … … 187 56 L<http://swish-e.org/> 188 57 189 SWISH::Prog , SWISH::Index, SWISH::Doc, SWISH::Search58 SWISH::Prog 190 59 191 60 =cut libswish3/trunk/bindings/perl/lib/SWISH/3/Config.pm
r1914 r1920 60 60 =head1 NAME 61 61 62 SWISH::3::Config - Swish -e XML-styleconfiguration62 SWISH::3::Config - Swish3 configuration 63 63 64 64 =head1 SYNOPSIS libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Data.pm
r1914 r1920 1 package SWISH::3:: Data;1 package SWISH::3::Parser::Data; 2 2 3 3 use strict; … … 8 8 our $VERSION = '0.01'; 9 9 10 sub handler 11 { 12 my $data = shift; 13 14 select(STDERR); 15 16 #print '~' x 80, "\n"; 17 18 my $props = $data->config->properties; 19 20 #print "Properties\n"; 21 for my $p (keys %$props) 22 { 23 my $v = $data->property($p); 24 my $type = $props->{$p}; 25 26 #print " <$p type='$type'>$v</$p>\n"; 27 } 28 29 #print "Doc\n"; 30 for my $d (@SWISH::3::DocFields) 31 { 32 33 #printf("%15s: %s\n", $d, $data->doc->$d); 34 } 35 36 #print "WordList\n"; 37 while (my $swishword = $data->wordlist->next) 38 { 39 for my $w (@SWISH::3::WordFields) 40 { 41 42 #printf("%15s: %s\n", $w, $swishword->$w); 43 } 44 } 45 46 } 10 47 11 48 1; … … 14 51 =head1 NAME 15 52 16 SWISH::3:: Data - handle the data returned from the SWISH3::353 SWISH::3::Parser::Data - handle the data returned from the SWISH3::3::Parser 17 54 18 55 libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Doc.pm
r1914 r1920 1 package SWISH::3:: Doc;1 package SWISH::3::Parser::Doc; 2 2 3 3 use strict; libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/MetaName.pm
r1914 r1920 1 package SWISH::3:: MetaName;1 package SWISH::3::Parser::MetaName; 2 2 3 3 use strict; 4 4 use warnings; 5 use Carp;6 use Data::Dump qw/ pp /;5 use base qw( SWISH::3::Object ); 6 __PACKAGE__->mk_accessors(qw( name bias )); 7 7 8 use base qw( Class::Accessor::Fast );9 __PACKAGE__->mk_accessors(qw/ name bias /);10 11 sub new12 {13 my $proto = shift;14 my $class = ref($proto) || $proto;15 my $self = {};16 bless($self, $class);17 $self->_init(@_);18 return $self;19 }20 21 22 sub _init23 {24 my $self = shift;25 if (@_)26 {27 my %extra = @_;28 @$self{keys %extra} = values %extra;29 }30 }31 8 32 9 1; libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Property.pm
r1914 r1920 1 package SWISH::3::P roperty;1 package SWISH::3::Parser::Property; 2 2 3 3 use strict; libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Word.pm
r1914 r1920 1 package SWISH::3:: Word;1 package SWISH::3::Parser::Word; 2 2 3 3 use strict; … … 7 7 our $VERSION = '0.01'; 8 8 9 our @Fields = qw( word position metaname start_offset end_offset );10 11 9 1; libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/WordList.pm
r1914 r1920 1 package SWISH::3:: WordList;1 package SWISH::3::Parser::WordList; 2 2 3 3 use strict; libswish3/trunk/bindings/perl/t/01slurp.t
r1914 r1920 5 5 BEGIN { use_ok('SWISH::3') }; 6 6 7 ok( my $parser = SWISH::3 ->new, "new object");7 ok( my $parser = SWISH::3::Parser->new, "new object"); 8 8 9 9 ok( my $buf = $parser->slurp_file("t/test.html"), "slurp file"); libswish3/trunk/bindings/perl/t/02xml2_version.t
r1914 r1920 5 5 BEGIN { use_ok('SWISH::3') }; 6 6 7 ok( my $parser = SWISH::3->new, "new object"); 7 ok( my $x = SWISH::3->xml2_version, "libxml2 version"); 8 diag($x); 8 9 9 ok( my $ v = $parser->libxml2_version, "libxml2version");10 diag($ v);10 ok( my $s = SWISH::3->swish_version, "swish version"); 11 diag($s); 11 12 12 13 #Dump $v; libswish3/trunk/bindings/perl/t/03parse_file.t
r1914 r1920 10 10 } 11 11 12 ok(my $parser = SWISH::3 ->new(handler => sub { }),12 ok(my $parser = SWISH::3::Parser->new(handler => sub { }), 13 13 "new parser"); 14 14 libswish3/trunk/bindings/perl/t/04subclass.t
r1914 r1920 3 3 use Test::More tests => 201; 4 4 5 use base qw/ SWISH::3 /; 6 5 use base qw( SWISH::3::Parser ); 7 6 8 7 ok( … … 28 27 1; 29 28 29 30 30 package MyApp::Data; 31 use base qw( SWISH::3:: Data );31 use base qw( SWISH::3::Parser::Data ); 32 32 1; 33 33 34 34 35 35 package MyApp::Doc; 36 use base qw( SWISH::3:: Doc );36 use base qw( SWISH::3::Parser::Doc ); 37 37 1; 38 38 39 39 package MyApp::Property; 40 use base qw( SWISH::3::P roperty );40 use base qw( SWISH::3::Parser::Property ); 41 41 1; 42 42 43 43 package MyApp::Word; 44 use base qw( SWISH::3:: Word );44 use base qw( SWISH::3::Parser::Word ); 45 45 1; 46 46 47 47 package MyApp::WordList; 48 use base qw( SWISH::3:: WordList );48 use base qw( SWISH::3::Parser::WordList ); 49 49 1; libswish3/trunk/bindings/perl/t/05latin1.t
r1914 r1920 9 9 } 10 10 11 ok(my $parser = SWISH::3 ->new, "new parser");11 ok(my $parser = SWISH::3::Parser->new, "new parser"); 12 12 13 13 #monitor('parser' => \$parser);
