/usr/share/perl5/XML/Filter/Sort/DiskBuffer.pm is in libxml-filter-sort-perl 1.01-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | # $Id: DiskBuffer.pm,v 1.1.1.1 2002/06/14 20:40:05 grantm Exp $
package XML::Filter::Sort::DiskBuffer;
use strict;
require XML::Filter::Sort::Buffer;
use Storable;
##############################################################################
# G L O B A L V A R I A B L E S
##############################################################################
use vars qw($VERSION @ISA);
$VERSION = '0.91';
@ISA = qw(XML::Filter::Sort::Buffer);
##############################################################################
# M E T H O D S
##############################################################################
##############################################################################
# Method: freeze()
#
# Serialises a buffer and either writes it to a supplied file descriptor or
# returns it as a scalar.
#
# If a list of sort key values is supplied (presumably a filtered version), it
# will replace any values currently stored in the object.
#
sub freeze {
my $self = shift;
my $fd = shift;
$self->{key_values} = [ @_ ] if(@_);
my $data = Storable::freeze( [ $self->{key_values}, $self->{tree} ] );
if($fd) {
$fd->print(pack('L', length($data)));
$fd->print($data);
return;
}
return($data);
}
##############################################################################
# Constructor: thaw()
#
# Alternative constructor for reconstructing buffer objects serialised using
# Storable.pm. Argument can be a scalar containing the raw serialised data, or
# a filehandle from which the next object will be read.
# Returns false on EOF.
# If called in a list context, returns the thawed object followed by an integer
# approximating the object's in-memory byte count.
#
sub thaw {
my $class = shift;
my $data = shift;
if(ref($data)) { # Read the data from the file if required
my $fd = $data;
$fd->read($data, 4) || return;
my($size) = unpack('L', $data);
$fd->read($data, $size) || return;
}
my $ref = Storable::thaw($data);
my $self = bless( { tree => $ref->[1], key_values => $ref->[0], }, $class);
if(wantarray) {
my $size = length($data) * 2; # Approximation of in-memory size
return($self, $size);
}
else {
return($self);
}
}
##############################################################################
# Method: close()
#
# Returns keys if this is a thawed buffer or calls base class method to get
# keys if buffer has never been frozen.
#
sub close {
my $self = shift;
unless($self->{key_values}) {
$self->{key_values} = [ $self->SUPER::close() ];
}
return(@{$self->{key_values}});
}
##############################################################################
# Method: key_values()
#
# Returns the stored values for each of the sort keys. In a scalar context,
# returns a reference to an array of key values.
#
sub key_values {
my $self = shift;
return(@{$self->{key_values}}) if(wantarray);
return($self->{key_values});
}
1;
__END__
=head1 NAME
XML::Filter::Sort::DiskBuffer - Implementation class used by XML::Filter::Sort
=head1 DESCRIPTION
The documentation is targetted at developers wishing to extend or replace
this class. For user documentation, see L<XML::Filter::Sort>.
For an overview of the classes and methods used for buffering, see
L<XML::Filter::Sort::BufferMgr>.
=head1 METHODS
This class inherits from B<XML::Filter::Sort::Buffer> and adds the following
methods:
...
=head1 COPYRIGHT
Copyright 2002 Grant McLean E<lt>grantm@cpan.orgE<gt>
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
|