Initial Windows agent repository
This commit is contained in:
commit
a0db0c2e5b
10589 changed files with 3844063 additions and 0 deletions
37
OGP64/usr/share/perl5/5.40/Memoize/AnyDBM_File.pm
Normal file
37
OGP64/usr/share/perl5/5.40/Memoize/AnyDBM_File.pm
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use strict; use warnings;
|
||||
|
||||
package Memoize::AnyDBM_File;
|
||||
our $VERSION = '1.16';
|
||||
|
||||
our @ISA = qw(DB_File GDBM_File Memoize::NDBM_File SDBM_File ODBM_File) unless @ISA;
|
||||
|
||||
for my $mod (@ISA) {
|
||||
if (eval "require $mod") {
|
||||
$mod = 'NDBM_File'
|
||||
if $mod eq 'Memoize::NDBM_File'
|
||||
and eval { NDBM_File->VERSION( '1.16' ) };
|
||||
print STDERR "AnyDBM_File => Selected $mod.\n" if our $Verbose;
|
||||
@ISA = $mod;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
die "No DBM package was successfully found or installed";
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Memoize::AnyDBM_File - glue to provide EXISTS for AnyDBM_File for Storable use
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This class does the same thing as L<AnyDBM_File>, except that instead of
|
||||
L<NDBM_File> itself it loads L<Memoize::NDBM_File> if L<NDBM_File> lacks
|
||||
L<EXISTS|perltie/C<EXISTS>> support.
|
||||
|
||||
Code which requires perl 5.37.3 or newer should simply use L<AnyBDM_File> directly.
|
||||
|
||||
=cut
|
||||
352
OGP64/usr/share/perl5/5.40/Memoize/Expire.pm
Normal file
352
OGP64/usr/share/perl5/5.40/Memoize/Expire.pm
Normal file
|
|
@ -0,0 +1,352 @@
|
|||
use strict; use warnings;
|
||||
|
||||
package Memoize::Expire;
|
||||
our $VERSION = '1.16';
|
||||
|
||||
use Carp;
|
||||
our $DEBUG;
|
||||
|
||||
# The format of the metadata is:
|
||||
# (4-byte number of last-access-time) (For LRU when I implement it)
|
||||
# (4-byte expiration time: unsigned seconds-since-unix-epoch)
|
||||
# (2-byte number-of-uses-before-expire)
|
||||
|
||||
BEGIN {
|
||||
eval {require Time::HiRes};
|
||||
unless ($@) {
|
||||
Time::HiRes->import('time');
|
||||
}
|
||||
}
|
||||
|
||||
sub TIEHASH {
|
||||
my ($package, %args) = @_;
|
||||
my %cache;
|
||||
if ($args{TIE}) {
|
||||
my ($module, @opts) = @{$args{TIE}};
|
||||
my $modulefile = $module . '.pm';
|
||||
$modulefile =~ s{::}{/}g;
|
||||
eval { require $modulefile };
|
||||
if ($@) {
|
||||
croak "Memoize::Expire: Couldn't load hash tie module `$module': $@; aborting";
|
||||
}
|
||||
my $rc = (tie %cache => $module, @opts);
|
||||
unless ($rc) {
|
||||
croak "Memoize::Expire: Couldn't tie hash to `$module': $@; aborting";
|
||||
}
|
||||
}
|
||||
$args{LIFETIME} ||= 0;
|
||||
$args{NUM_USES} ||= 0;
|
||||
$args{C} = delete $args{HASH} || \%cache;
|
||||
bless \%args => $package;
|
||||
}
|
||||
|
||||
sub STORE {
|
||||
$DEBUG and print STDERR " >> Store $_[1] $_[2]\n";
|
||||
my ($self, $key, $value) = @_;
|
||||
my $expire_time = $self->{LIFETIME} > 0 ? $self->{LIFETIME} + time : 0;
|
||||
# The call that results in a value to store into the cache is the
|
||||
# first of the NUM_USES allowed calls.
|
||||
my $header = _make_header(time, $expire_time, $self->{NUM_USES}-1);
|
||||
@{$self->{C}}{"H$key", "V$key"} = ($header, $value);
|
||||
$value;
|
||||
}
|
||||
|
||||
sub FETCH {
|
||||
$DEBUG and print STDERR " >> Fetch cached value for $_[1]\n";
|
||||
my ($last_access, $expire_time, $num_uses_left) = _get_header($_[0]{C}{"H$_[1]"});
|
||||
$DEBUG and print STDERR " >> (ttl: ", ($expire_time-time()), ", nuses: $num_uses_left)\n";
|
||||
$_[0]{C}{"H$_[1]"} = _make_header(time, $expire_time, --$num_uses_left);
|
||||
$_[0]{C}{"V$_[1]"};
|
||||
}
|
||||
|
||||
sub EXISTS {
|
||||
$DEBUG and print STDERR " >> Exists $_[1]\n";
|
||||
unless (exists $_[0]{C}{"V$_[1]"}) {
|
||||
$DEBUG and print STDERR " Not in underlying hash at all.\n";
|
||||
return 0;
|
||||
}
|
||||
my $item = $_[0]{C}{"H$_[1]"};
|
||||
my ($last_access, $expire_time, $num_uses_left) = _get_header($item);
|
||||
my $ttl = $expire_time - time;
|
||||
if ($DEBUG) {
|
||||
$_[0]{LIFETIME} and print STDERR " Time to live for this item: $ttl\n";
|
||||
$_[0]{NUM_USES} and print STDERR " Uses remaining: $num_uses_left\n";
|
||||
}
|
||||
if ( (! $_[0]{LIFETIME} || $expire_time > time)
|
||||
&& (! $_[0]{NUM_USES} || $num_uses_left > 0 )) {
|
||||
$DEBUG and print STDERR " (Still good)\n";
|
||||
return 1;
|
||||
} else {
|
||||
$DEBUG and print STDERR " (Expired)\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
sub FIRSTKEY {
|
||||
scalar keys %{$_[0]{C}};
|
||||
&NEXTKEY;
|
||||
}
|
||||
|
||||
sub NEXTKEY {
|
||||
while (defined(my $key = each %{$_[0]{C}})) {
|
||||
return substr $key, 1 if 'V' eq substr $key, 0, 1;
|
||||
}
|
||||
undef;
|
||||
}
|
||||
|
||||
# Arguments: last access time, expire time, number of uses remaining
|
||||
sub _make_header {
|
||||
pack "N N n", @_;
|
||||
}
|
||||
|
||||
# Return last access time, expire time, number of uses remaining
|
||||
sub _get_header {
|
||||
unpack "N N n", substr($_[0], 0, 10);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Memoize::Expire - Plug-in module for automatic expiration of memoized values
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Memoize;
|
||||
use Memoize::Expire;
|
||||
tie my %cache => 'Memoize::Expire',
|
||||
LIFETIME => $lifetime, # In seconds
|
||||
NUM_USES => $n_uses;
|
||||
|
||||
memoize 'function', SCALAR_CACHE => [HASH => \%cache ];
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Memoize::Expire is a plug-in module for Memoize. It allows the cached
|
||||
values for memoized functions to expire automatically. This manual
|
||||
assumes you are already familiar with the Memoize module. If not, you
|
||||
should study that manual carefully first, paying particular attention
|
||||
to the HASH feature.
|
||||
|
||||
Memoize::Expire is a layer of software that you can insert in between
|
||||
Memoize itself and whatever underlying package implements the cache.
|
||||
The layer presents a hash variable whose values expire whenever they
|
||||
get too old, have been used too often, or both. You tell C<Memoize> to
|
||||
use this forgetful hash as its cache instead of the default, which is
|
||||
an ordinary hash.
|
||||
|
||||
To specify a real-time timeout, supply the C<LIFETIME> option with a
|
||||
numeric value. Cached data will expire after this many seconds, and
|
||||
will be looked up afresh when it expires. When a data item is looked
|
||||
up afresh, its lifetime is reset.
|
||||
|
||||
If you specify C<NUM_USES> with an argument of I<n>, then each cached
|
||||
data item will be discarded and looked up afresh after the I<n>th time
|
||||
you access it. When a data item is looked up afresh, its number of
|
||||
uses is reset.
|
||||
|
||||
If you specify both arguments, data will be discarded from the cache
|
||||
when either expiration condition holds.
|
||||
|
||||
Memoize::Expire uses a real hash internally to store the cached data.
|
||||
You can use the C<HASH> option to Memoize::Expire to supply a tied
|
||||
hash in place of the ordinary hash that Memoize::Expire will normally
|
||||
use. You can use this feature to add Memoize::Expire as a layer in
|
||||
between a persistent disk hash and Memoize. If you do this, you get a
|
||||
persistent disk cache whose entries expire automatically. For
|
||||
example:
|
||||
|
||||
# Memoize
|
||||
# |
|
||||
# Memoize::Expire enforces data expiration policy
|
||||
# |
|
||||
# DB_File implements persistence of data in a disk file
|
||||
# |
|
||||
# Disk file
|
||||
|
||||
use Memoize;
|
||||
use Memoize::Expire;
|
||||
use DB_File;
|
||||
|
||||
# Set up persistence
|
||||
tie my %disk_cache => 'DB_File', $filename, O_CREAT|O_RDWR, 0666];
|
||||
|
||||
# Set up expiration policy, supplying persistent hash as a target
|
||||
tie my %cache => 'Memoize::Expire',
|
||||
LIFETIME => $lifetime, # In seconds
|
||||
NUM_USES => $n_uses,
|
||||
HASH => \%disk_cache;
|
||||
|
||||
# Set up memoization, supplying expiring persistent hash for cache
|
||||
memoize 'function', SCALAR_CACHE => [ HASH => \%cache ];
|
||||
|
||||
=head1 INTERFACE
|
||||
|
||||
There is nothing special about Memoize::Expire. It is just an
|
||||
example. If you don't like the policy that it implements, you are
|
||||
free to write your own expiration policy module that implements
|
||||
whatever policy you desire. Here is how to do that. Let us suppose
|
||||
that your module will be named MyExpirePolicy.
|
||||
|
||||
Short summary: You need to create a package that defines four methods:
|
||||
|
||||
=over 4
|
||||
|
||||
=item
|
||||
TIEHASH
|
||||
|
||||
Construct and return cache object.
|
||||
|
||||
=item
|
||||
EXISTS
|
||||
|
||||
Given a function argument, is the corresponding function value in the
|
||||
cache, and if so, is it fresh enough to use?
|
||||
|
||||
=item
|
||||
FETCH
|
||||
|
||||
Given a function argument, look up the corresponding function value in
|
||||
the cache and return it.
|
||||
|
||||
=item
|
||||
STORE
|
||||
|
||||
Given a function argument and the corresponding function value, store
|
||||
them into the cache.
|
||||
|
||||
=item
|
||||
CLEAR
|
||||
|
||||
(Optional.) Flush the cache completely.
|
||||
|
||||
=back
|
||||
|
||||
The user who wants the memoization cache to be expired according to
|
||||
your policy will say so by writing
|
||||
|
||||
tie my %cache => 'MyExpirePolicy', args...;
|
||||
memoize 'function', SCALAR_CACHE => [HASH => \%cache];
|
||||
|
||||
This will invoke C<< MyExpirePolicy->TIEHASH(args) >>.
|
||||
MyExpirePolicy::TIEHASH should do whatever is appropriate to set up
|
||||
the cache, and it should return the cache object to the caller.
|
||||
|
||||
For example, MyExpirePolicy::TIEHASH might create an object that
|
||||
contains a regular Perl hash (which it will to store the cached
|
||||
values) and some extra information about the arguments and how old the
|
||||
data is and things like that. Let us call this object I<C<C>>.
|
||||
|
||||
When Memoize needs to check to see if an entry is in the cache
|
||||
already, it will invoke C<< C->EXISTS(key) >>. C<key> is the normalized
|
||||
function argument. MyExpirePolicy::EXISTS should return 0 if the key
|
||||
is not in the cache, or if it has expired, and 1 if an unexpired value
|
||||
is in the cache. It should I<not> return C<undef>, because there is a
|
||||
bug in some versions of Perl that will cause a spurious FETCH if the
|
||||
EXISTS method returns C<undef>.
|
||||
|
||||
If your EXISTS function returns true, Memoize will try to fetch the
|
||||
cached value by invoking C<< C->FETCH(key) >>. MyExpirePolicy::FETCH should
|
||||
return the cached value. Otherwise, Memoize will call the memoized
|
||||
function to compute the appropriate value, and will store it into the
|
||||
cache by calling C<< C->STORE(key, value) >>.
|
||||
|
||||
Here is a very brief example of a policy module that expires each
|
||||
cache item after ten seconds.
|
||||
|
||||
package Memoize::TenSecondExpire;
|
||||
|
||||
sub TIEHASH {
|
||||
my ($package, %args) = @_;
|
||||
my $cache = $args{HASH} || {};
|
||||
bless $cache => $package;
|
||||
}
|
||||
|
||||
sub EXISTS {
|
||||
my ($cache, $key) = @_;
|
||||
if (exists $cache->{$key} &&
|
||||
$cache->{$key}{EXPIRE_TIME} > time) {
|
||||
return 1
|
||||
} else {
|
||||
return 0; # Do NOT return undef here
|
||||
}
|
||||
}
|
||||
|
||||
sub FETCH {
|
||||
my ($cache, $key) = @_;
|
||||
return $cache->{$key}{VALUE};
|
||||
}
|
||||
|
||||
sub STORE {
|
||||
my ($cache, $key, $newvalue) = @_;
|
||||
$cache->{$key}{VALUE} = $newvalue;
|
||||
$cache->{$key}{EXPIRE_TIME} = time + 10;
|
||||
}
|
||||
|
||||
To use this expiration policy, the user would say
|
||||
|
||||
use Memoize;
|
||||
tie my %cache10sec => 'Memoize::TenSecondExpire';
|
||||
memoize 'function', SCALAR_CACHE => [HASH => \%cache10sec];
|
||||
|
||||
Memoize would then call C<function> whenever a cached value was
|
||||
entirely absent or was older than ten seconds.
|
||||
|
||||
You should always support a C<HASH> argument to C<TIEHASH> that ties
|
||||
the underlying cache so that the user can specify that the cache is
|
||||
also persistent or that it has some other interesting semantics. The
|
||||
example above demonstrates how to do this, as does C<Memoize::Expire>.
|
||||
|
||||
Another sample module, L<Memoize::Saves>, is available in a separate
|
||||
distribution on CPAN. It implements a policy that allows you to
|
||||
specify that certain function values would always be looked up afresh.
|
||||
See the documentation for details.
|
||||
|
||||
=head1 ALTERNATIVES
|
||||
|
||||
Brent Powers has a L<Memoize::ExpireLRU> module that was designed to
|
||||
work with Memoize and provides expiration of least-recently-used data.
|
||||
The cache is held at a fixed number of entries, and when new data
|
||||
comes in, the least-recently used data is expired.
|
||||
|
||||
Joshua Chamas's Tie::Cache module may be useful as an expiration
|
||||
manager. (If you try this, let me know how it works out.)
|
||||
|
||||
If you develop any useful expiration managers that you think should be
|
||||
distributed with Memoize, please let me know.
|
||||
|
||||
=head1 CAVEATS
|
||||
|
||||
This module is experimental, and may contain bugs. Please report bugs
|
||||
to the address below.
|
||||
|
||||
Number-of-uses is stored as a 16-bit unsigned integer, so can't exceed
|
||||
65535.
|
||||
|
||||
Because of clock granularity, expiration times may occur up to one
|
||||
second sooner than you expect. For example, suppose you store a value
|
||||
with a lifetime of ten seconds, and you store it at 12:00:00.998 on a
|
||||
certain day. Memoize will look at the clock and see 12:00:00. Then
|
||||
9.01 seconds later, at 12:00:10.008 you try to read it back. Memoize
|
||||
will look at the clock and see 12:00:10 and conclude that the value
|
||||
has expired. This will probably not occur if you have
|
||||
C<Time::HiRes> installed.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Mark-Jason Dominus
|
||||
|
||||
Mike Cariaso provided valuable insight into the best way to solve this
|
||||
problem.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
perl(1)
|
||||
|
||||
The Memoize man page.
|
||||
|
||||
=cut
|
||||
38
OGP64/usr/share/perl5/5.40/Memoize/NDBM_File.pm
Normal file
38
OGP64/usr/share/perl5/5.40/Memoize/NDBM_File.pm
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use strict; use warnings;
|
||||
|
||||
package Memoize::NDBM_File;
|
||||
our $VERSION = '1.16';
|
||||
|
||||
use NDBM_File;
|
||||
our @ISA = qw(NDBM_File);
|
||||
|
||||
# NDBM_File cannot store undef and will store an empty string if you try
|
||||
# but it does return undef if you try to read a non-existent key
|
||||
# so we can emulate exists() using defined()
|
||||
sub EXISTS {
|
||||
defined shift->FETCH(@_);
|
||||
}
|
||||
|
||||
# Perl 5.37.3 adds this EXISTS emulation to NDBM_File itself
|
||||
delete $Memoize::NDBM_File::{'EXISTS'}
|
||||
if eval { NDBM_File->VERSION( '1.16' ) };
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Memoize::NDBM_File - glue to provide EXISTS for NDBM_File for Storable use
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This class provides L<EXISTS|perltie/C<EXISTS>> support for L<NDBM_File>.
|
||||
|
||||
L<In Perl 5.37.3|https://github.com/Perl/perl5/commit/c0a1a377c02ed789f5eff667f46a2314a05c5a4c>,
|
||||
support for C<EXISTS> was added to L<NDBM_File> itself.
|
||||
Code which requires such a perl should simply use L<NBDM_File> directly.
|
||||
|
||||
=cut
|
||||
27
OGP64/usr/share/perl5/5.40/Memoize/SDBM_File.pm
Normal file
27
OGP64/usr/share/perl5/5.40/Memoize/SDBM_File.pm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use strict; use warnings;
|
||||
|
||||
package Memoize::SDBM_File;
|
||||
our $VERSION = '1.16';
|
||||
|
||||
use SDBM_File 1.01; # for EXISTS support
|
||||
our @ISA = qw(SDBM_File);
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Memoize::SDBM_File - DEPRECATED compability shim
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This class used to provide L<EXISTS|perltie/C<EXISTS>> support for L<SDBM_File>
|
||||
before support for C<EXISTS> was added to L<SDBM_File> itself
|
||||
L<in Perl 5.6.0|perl56delta/SDBM_File>.
|
||||
|
||||
Any code still using this class should be rewritten to use L<SBDM_File> directly.
|
||||
|
||||
=cut
|
||||
75
OGP64/usr/share/perl5/5.40/Memoize/Storable.pm
Normal file
75
OGP64/usr/share/perl5/5.40/Memoize/Storable.pm
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
use strict; use warnings;
|
||||
|
||||
package Memoize::Storable;
|
||||
our $VERSION = '1.16';
|
||||
|
||||
use Storable 1.002 (); # for lock_* function variants
|
||||
|
||||
our $Verbose;
|
||||
|
||||
sub TIEHASH {
|
||||
my $package = shift;
|
||||
my $filename = shift;
|
||||
my $truehash = (-e $filename) ? Storable::lock_retrieve($filename) : {};
|
||||
my %options;
|
||||
print STDERR "Memoize::Storable::TIEHASH($filename, @_)\n" if $Verbose;
|
||||
@options{@_} = (1) x @_;
|
||||
my $self =
|
||||
{FILENAME => $filename,
|
||||
H => $truehash,
|
||||
OPTIONS => \%options
|
||||
};
|
||||
bless $self => $package;
|
||||
}
|
||||
|
||||
sub STORE {
|
||||
my $self = shift;
|
||||
print STDERR "Memoize::Storable::STORE(@_)\n" if $Verbose;
|
||||
$self->{H}{$_[0]} = $_[1];
|
||||
}
|
||||
|
||||
sub FETCH {
|
||||
my $self = shift;
|
||||
print STDERR "Memoize::Storable::FETCH(@_)\n" if $Verbose;
|
||||
$self->{H}{$_[0]};
|
||||
}
|
||||
|
||||
sub EXISTS {
|
||||
my $self = shift;
|
||||
print STDERR "Memoize::Storable::EXISTS(@_)\n" if $Verbose;
|
||||
exists $self->{H}{$_[0]};
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my $self= shift;
|
||||
print STDERR "Memoize::Storable::DESTROY(@_)\n" if $Verbose;
|
||||
if ($self->{OPTIONS}{'nstore'}) {
|
||||
Storable::lock_nstore($self->{H}, $self->{FILENAME});
|
||||
} else {
|
||||
Storable::lock_store($self->{H}, $self->{FILENAME});
|
||||
}
|
||||
}
|
||||
|
||||
sub FIRSTKEY {
|
||||
'Fake hash from Memoize::Storable';
|
||||
}
|
||||
|
||||
sub NEXTKEY {
|
||||
undef;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Memoize::Storable - store Memoized data in Storable database
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
See L<Memoize>.
|
||||
|
||||
=cut
|
||||
Loading…
Add table
Add a link
Reference in a new issue