App-CriticDB
view release on metacpan or search on metacpan
lib/App/CriticDB/DB.pm view on Meta::CPAN
sub _init {
my ($self)=@_;
%{$$self{store}}=$self->_initStore();
return $self->write();
}
sub _filemtime {
my ($fn)=@_;
if(!-e $fn) { return }
return (stat($fn))[9];
}
sub _fileNewer {
my ($self,$fn,$ts)=@_;
if(!$ts) { return }
my $tm=_filemtime($fn);
if(!$tm) { return }
return ($tm>$ts);
}
t/app/criticdb/db/stor.t view on Meta::CPAN
use File::Temp qw/tempfile/;
use Test::More tests=>3;
subtest 'end to end'=>sub{
plan tests=>8;
my ($db,$mtime);
my ($fh,$fn)=tempfile(UNLINK=>1); close($fh); unlink($fn);
#
$db=App::CriticDB::DB::Stor->new(mode=>'file',file=>$fn,type=>'storable');
ok(-e $fn,"created: stor ($fn)");
$mtime=(stat($fn))[9];
is(ref($db),'App::CriticDB::DB::Stor','class: Stor');
is($$db{store}{version},1001,'Store version');
#
$db->store(file=>'/fake/path.pm',violations=>[{policy=>'TestPolicy',sev=>3,line=>1,col=>1,desc=>'d',expl=>'e',code=>'c'}]);
ok((stat($fn))[9]<=$mtime,'store: not auto-write');
if(time()<=$mtime) { sleep(1) }
$db->write();
ok((stat($fn))[9]>=$mtime,'write: file updated');
$db=undef;
#
$db=App::CriticDB::DB->new(mode=>'file',file=>$fn,type=>'storable');
ok(defined($$db{store}{file}{'/fake/path.pm'}),'read: file entry');
is(scalar(@{$$db{store}{file}{'/fake/path.pm'}{violations}}),1,'read: violation count');
ok(defined($$db{store}{index}{policy}),'read: policy index');
};
subtest 'mtime guard'=>sub{
plan tests=>2;
( run in 0.717 second using v1.01-cache-2.11-cpan-14f38c9f855 )