App-CriticDB

 view release on metacpan or  search on metacpan

lib/App/CriticDB/DB/Stor.pm  view on Meta::CPAN

Version 0.0.6

=head1 SYNOPSIS

  my $db=App::CriticDB::DB->new(mode=>'file',file=>'path.stor',type=>'storable');
  $db->store($filename,@violations);
  $db->write();

=head1 DESCRIPTION

Provides reading and writing of L<Storable> databases of L<Perl::Critic> violations for L<App::CriticDB>.  File locking prevents other processes from reading during writes.  Timestamps are checked to ensure other processes haven't updated the datafil...

=head1 AUTHORS

Brian Blackmore (brian@mediaalpha.com).

=head1 COPYRIGHT

  Copyright (c) 2025--2035, MediaAlpha.com.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License Version 3 as published by the Free Software Foundation.

t/app/criticdb/db/stor.t  view on Meta::CPAN

	$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.331 second using v1.01-cache-2.11-cpan-bbe5e583499 )