X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=perl%2Fdemo%2Fpod.pm;fp=perl%2Fdemo%2Fpod.pm;h=e20e78d52e3bc82426b4f379a1143c4d81cca3e2;hb=af03c4a4f5320b52c7cc5f47bab7c9ad4b3e384d;hp=0000000000000000000000000000000000000000;hpb=54867e37cc72f7a550a15ed77de30e0c1837b57d;p=idzebra-moved-to-github.git diff --git a/perl/demo/pod.pm b/perl/demo/pod.pm new file mode 100644 index 0000000..e20e78d --- /dev/null +++ b/perl/demo/pod.pm @@ -0,0 +1,65 @@ +#!/usr/bin/perl +use strict; +# ---------------------------------------------------------------------------- +# A dummy example to demonstrate perl filters for zebra. This is going to +# extract information from the .pm perl module files. +# ---------------------------------------------------------------------------- +package pod; + +use IDZebra::Filter; +use IDZebra::Data1; +use Pod::Text; +our @ISA=qw(IDZebra::Filter); +1; + + +sub init { + # Initialization code may come here +} + +sub process { + my ($self, $d1) = @_; + + my $tempfile_in = "/tmp/strucc.in"; + my $tempfile_out = "/tmp/strucc.out"; + my $parser = Pod::Text->new (sentence => 0, width => 78); + + my $r1=$d1->mk_root('pod'); + my $root=$d1->mk_tag($r1,'pod'); + + # This is dirty... Pod::Parser doesn't seems to support + # parsing a string, so we have to write the whole thing out into a + # temporary file + open (TMP, ">$tempfile_in"); + print TMP $self->readall(10240); + close (TMP); + + $parser->parse_from_file ($tempfile_in, $tempfile_out); + + my $section; + my $data; + open (TMP, "$tempfile_out"); + while() { + chomp; + if (/^([A-Z]+)\s*$/) { + my $ss = $1; + if ($section) { + my $tag = $d1->mk_tag($root,$section); + $d1->mk_text($tag,$data) if ($data); + } + $section = $ss; + $data = ""; + next; + } + s/^\s+|\s+$//g; + $data.="$_\n"; + } + + if ($section) { + my $tag = $d1->mk_tag($root,$section); + $d1->mk_text($tag,$data) if ($data); + } + close (TMP); + + return ($r1); +}