Skip to content

Commit

Permalink
import Memoize 1.00 from CPAN
Browse files Browse the repository at this point in the history
git-cpan-module:   Memoize
git-cpan-version:  1.00
git-cpan-authorid: MJD
git-cpan-file:     authors/id/M/MJ/MJD/Memoize-1.00.tar.gz
  • Loading branch information
mjdominus authored and schwern committed Dec 12, 2009
1 parent a1e2489 commit f192e71
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 25 deletions.
6 changes: 3 additions & 3 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ t/tie_sdbm.t
t/tie_ndbm.t
t/tie_storable.t
t/expire.t
t/expire_module_n.t
t/expire_module_t.t
t/expire_file.t
t/expmod_n.t
t/expmod_t.t
t/expfile.t
t/flush.t
t/array_confusion.t
article.html
Expand Down
39 changes: 21 additions & 18 deletions Memoize.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# same terms as Perl itself. If in doubt,
# write to mjd-perl-memoize+@plover.com for a license.
#
# Version 0.66 $Revision: 1.18 $ $Date: 2001/06/24 17:16:47 $
# Version 1.00 $Revision: 1.18 $ $Date: 2001/06/24 17:16:47 $

package Memoize;
$VERSION = '0.66';
$VERSION = '1.00';

# Compile-time constants
sub SCALAR () { 0 }
Expand Down Expand Up @@ -167,6 +167,8 @@ sub memoize {
$wrapper # Return just memoized version
}

use warnings::register;

# This function tries to load a tied hash class and tie the hash to it.
sub _my_tie {
my ($context, $hash, $options) = @_;
Expand All @@ -176,8 +178,8 @@ sub _my_tie {
my $shortopt = (ref $fullopt) ? $fullopt->[0] : $fullopt;

return unless defined $shortopt && $shortopt eq 'TIE';
carp("TIE option to memoize() is deprecated; use HASH instead") if $^W;

carp("TIE option to memoize() is deprecated; use HASH instead")
if warnings::enabled('deprecated');

my @args = ref $fullopt ? @$fullopt : ();
shift @args;
Expand Down Expand Up @@ -357,10 +359,11 @@ sub _crap_out {

=head1 NAME
Memoize - Make your functions faster by trading space for time
Memoize - Make functions faster by trading space for time
=head1 SYNOPSIS
# This is the documentation for Memoize 1.00
use Memoize;
memoize('slow_function');
slow_function(arguments); # Is faster than it was before
Expand Down Expand Up @@ -462,7 +465,7 @@ this:
Since there are relatively few objects in a picture, there are only a
few colors, which get looked up over and over again. Memoizing
C<ColorToRGB> speeded up the program by several percent.
C<ColorToRGB> sped up the program by several percent.
=head1 DETAILS
Expand Down Expand Up @@ -692,15 +695,18 @@ because all its results have been precomputed.
=item C<TIE>
This option is B<strongly deprecated> and will be removed
in the B<next> release of C<Memoize>. Use the C<HASH> option instead.
This option is no longer supported. It is still documented only to
aid in the debugging of old programs that use it. Old programs should
be converted to use the C<HASH> option instead.
memoize ... [TIE, PACKAGE, ARGS...]
is merely a shortcut for
require PACKAGE;
tie my %cache, PACKAGE, ARGS...;
{ my %cache;
tie %cache, PACKAGE, ARGS...;
}
memoize ... [HASH => \%cache];
=item C<FAULT>
Expand Down Expand Up @@ -975,15 +981,12 @@ in Perl, and until it is resolved, memoized functions will see a
slightly different C<caller()> and will perform a little more slowly
on threaded perls than unthreaded perls.
Here's a bug that isn't my fault: Some versions of C<DB_File> won't
let you store data under a key of length 0. That means that if you
have a function C<f> which you memoized and the cache is in a
C<DB_File> database, then the value of C<f()> (C<f> called with no
arguments) will not be memoized. Let us all breathe deeply and repeat
this mantra: ``Gosh, Keith, that sure was a stupid thing to do.'' If
this is a big problem, you can write a tied hash class which is a
front-end to C<DB_File> that prepends <x> to every key before storing
it.
Some versions of C<DB_File> won't let you store data under a key of
length 0. That means that if you have a function C<f> which you
memoized and the cache is in a C<DB_File> database, then the value of
C<f()> (C<f> called with no arguments) will not be memoized. If this
is a big problem, you can supply a normalizer function that prepends
C<"x"> to every key.
=head1 MAILING LIST
Expand Down
6 changes: 3 additions & 3 deletions Memoize/Expire.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Memoize::Expire;
# require 5.00556;
use Carp;
$DEBUG = 0;
$VERSION = '0.66';
$VERSION = '1.00';

# This package will implement expiration by prepending a fixed-length header
# to the font of the cached data. The format of the header will be:
Expand Down Expand Up @@ -313,13 +313,13 @@ example above demonstrates how to do this, as does C<Memoize::Expire>.
Another sample module, C<Memoize::Saves>, is included with this
package. It implements a policy that allows you to specify that
certain function values whould always be looked up afresh. See the
certain function values would always be looked up afresh. See the
documentation for details.
=head1 ALTERNATIVES
Brent Powers has a C<Memoize::ExpireLRU> module that was designed to
wotk with Memoize and provides expiration of least-recently-used data.
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. See
L<http://search.cpan.org/search?mode=module&query=ExpireLRU>.
Expand Down
7 changes: 6 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Name: Memoize
What: Transparently speed up functions by caching return values.
Version: 0.66
Version: 1.00
Author: Mark-Jason Dominus (mjd-perl-memoize+@plover.com)

################################################################
Expand All @@ -24,6 +24,11 @@ If the tests work,
If not, please send me a report that mentions which tests failed.
The address is: mjd-perl-memoize+@plover.com.

################################################################
What's new since 0.66:

Minor documentation and test changes only.

################################################################
What's new since 0.65:

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f192e71

Please sign in to comment.