Alvis-Convert

 view release on metacpan or  search on metacpan

lib/Alvis/Buffer.pm  view on Meta::CPAN

Basic initialisation and checking to ensure the output buffer
is OK, and have the current document count and size in memory.
Returns 1 if everything is OK, else 0.

If runtime stops or aborts while the output buffer is
still being built, a restart will safely recover the
contents as long as no data was lost on the file.

=head2 add()

 &Buffer::add($xml);

Add an XML chunk to the current buffer and updates current 
document count and size in memory.

=head2 save()

 $filename = &Buffer::save();
 if ( !$filename ) {
     die "Cannot Buffer::save";
 } else {
     print STDERR "New XML file $filename saved\n";
 }

Save the current buffer into "xml-add/" as an appropriote integer
name, such as "xml-add/$N.xml", where $N will be determined at the point 
of saving as the next biggest integer.   Returns the filename used
if everything is OK, else returns undef.  This needs to be called
explicitly so the variables $Buffer::docs and $Buffer:.size should be
checked to determine when this should be done.

=head2 close()

 &Buffer::close();

Close the output buffer.

=head1 VARIABLES and PARAMETERS

Global variables are of two kinds.
There are those intended to define
characteristics of general use.  These should be set by the user
before the functions are used, but reasonable defaults are used.

=head2 BUFFER

name of the output buffer file that collects XML chunks.  Don't
include the randomising string "$$" if you want this file to
be available during a restart.

=head2 HEADER

text to enter at the front of a sequence of <documentRecord> elements.

=head2 FOOTER

text to enter at the end of a sequence of <documentRecord> elements.

=head2 verbose

set to a non-zero value if more debugging shoulöd be reported to STDERR.

Then the are variables that are read-only and define current buffer
statistics.

=head2 size

Count of characters in the current buffer.

=head2 docs

Count of documents, as determined by occurrences of <documentRecord> elements.


=head1 SEE ALSO

Alvis::Pipeline

=head1 AUTHOR

Wray Buntine, E<lt>buntine@hiit.fiE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2006 by Wray Buntine.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.4 or,
at your option, any later version of Perl 5 you may have available.

=cut




#############################################
#  parameters - fixed per instance
our $BUFFER="building.xml-ish";
our $HEADER='<?xml version="1.0" encoding="UTF-8"?>
<documentCollection xmlns="http://alvis.info/enriched/" version="1.1">
';
our $TRAILER='</documentCollection>
';

#############################################
#  run time variables
our $docs = 0;
our $size = 0;
our $verbose = 0;

############################################
#
#  add XML chunk
sub add() {
  my $xml = shift();
  my $xc = $xml;
  my $count = $xc =~ s/<\/documentRecord>//g;
  #  now save
  print ABUF $xml,"\n";
  if ( $verbose ) {
    my $tt = Time::Simple->new;



( run in 2.085 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )