5338ed2b26
We set "use warnings" in most of our perl code to catch problems. But as the name implies, warnings just emit a message to stderr and don't otherwise affect the program. So our tests are quite likely to miss that warnings are being spewed, as most of them do not look at stderr. We could ask perl to make all warnings fatal, but this is likely annoying for non-developers, who would rather have a running program with a warning than something that refuses to work at all. So instead, let's teach the perl code to respect an environment variable (GIT_PERL_FATAL_WARNINGS) to increase the severity of the warnings. This can be set for day-to-day running if people want to be really pedantic, but the primary use is to trigger it within the test suite. We could also trigger that for every test run, but likewise even the tests failing may be annoying to distro builders, etc (just as -Werror would be for compiling C code). So we'll tie it to a special test-mode variable (GIT_TEST_PERL_FATAL_WARNINGS) that can be set in the environment or as a Makefile knob, and we'll automatically turn the knob when DEVELOPER=1 is set. That should give developers and CI the more careful view without disrupting normal users or packagers. Note that the mapping from the GIT_TEST_* form to the GIT_* form in test-lib.sh is necessary even if they had the same name: the perl scripts need it to be normalized to a perl truth value, and we also have to make sure it's exported (we might have gotten it from the environment, but we might also have gotten it from GIT-BUILD-OPTIONS directly). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
94 lines
1.8 KiB
Perl
94 lines
1.8 KiB
Perl
package Git::SVN::Memoize::YAML;
|
|
use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
|
|
use strict;
|
|
use YAML::Any ();
|
|
|
|
# based on Memoize::Storable.
|
|
|
|
sub TIEHASH {
|
|
my $package = shift;
|
|
my $filename = shift;
|
|
my $truehash = (-e $filename) ? YAML::Any::LoadFile($filename) : {};
|
|
my $self = {FILENAME => $filename, H => $truehash};
|
|
bless $self => $package;
|
|
}
|
|
|
|
sub STORE {
|
|
my $self = shift;
|
|
$self->{H}{$_[0]} = $_[1];
|
|
}
|
|
|
|
sub FETCH {
|
|
my $self = shift;
|
|
$self->{H}{$_[0]};
|
|
}
|
|
|
|
sub EXISTS {
|
|
my $self = shift;
|
|
exists $self->{H}{$_[0]};
|
|
}
|
|
|
|
sub DESTROY {
|
|
my $self = shift;
|
|
YAML::Any::DumpFile($self->{FILENAME}, $self->{H});
|
|
}
|
|
|
|
sub SCALAR {
|
|
my $self = shift;
|
|
scalar(%{$self->{H}});
|
|
}
|
|
|
|
sub FIRSTKEY {
|
|
'Fake hash from Git::SVN::Memoize::YAML';
|
|
}
|
|
|
|
sub NEXTKEY {
|
|
undef;
|
|
}
|
|
|
|
1;
|
|
__END__
|
|
|
|
=head1 NAME
|
|
|
|
Git::SVN::Memoize::YAML - store Memoized data in YAML format
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
use Memoize;
|
|
use Git::SVN::Memoize::YAML;
|
|
|
|
tie my %cache => 'Git::SVN::Memoize::YAML', $filename;
|
|
memoize('slow_function', SCALAR_CACHE => [HASH => \%cache]);
|
|
slow_function(arguments);
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This module provides a class that can be used to tie a hash to a
|
|
YAML file. The file is read when the hash is initialized and
|
|
rewritten when the hash is destroyed.
|
|
|
|
The intent is to allow L<Memoize> to back its cache with a file in
|
|
YAML format, just like L<Memoize::Storable> allows L<Memoize> to
|
|
back its cache with a file in Storable format. Unlike the Storable
|
|
format, the YAML format is platform-independent and fairly stable.
|
|
|
|
Carps on error.
|
|
|
|
=head1 DIAGNOSTICS
|
|
|
|
See L<YAML::Any>.
|
|
|
|
=head1 DEPENDENCIES
|
|
|
|
L<YAML::Any> from CPAN.
|
|
|
|
=head1 INCOMPATIBILITIES
|
|
|
|
None reported.
|
|
|
|
=head1 BUGS
|
|
|
|
The entire cache is read into a Perl hash when loading the file,
|
|
so this is not very scalable.
|