Skip to content

Commit

Permalink
Try to avoid weird problems with linecache consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
kentfredric committed Mar 3, 2017
1 parent 4442d1a commit d8b618b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
4 changes: 3 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ Release history for Dist-Zilla-Plugin-Author-KENTNL-RecommendFixes

{{$NEXT}}
[Bugfix]
- Avoid test failures on 5.26 w/ -Ddefault_inc_excludes_dot
- 1. Avoid test failures on 5.26 w/ -Ddefault_inc_excludes_dot
- Closes https://github.com/kentnl/Dist-Zilla-Plugin-Author-KENTNL-RecommendFixes/issues/2
- 2. Avoid weird problems with linecache consistency by reducing code complexity

[Dependencies::Stats]
- Dependencies changed since 0.005002, see misc/*.deps* for details
- develop: +1 ↑2
- runtime: -1
- test: ↓1

0.005002 2016-09-10T06:01:15Z fa37013
Expand Down
2 changes: 0 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ my %WriteMakefileArgs = (
"Path::Tiny" => 0,
"Term::ANSIColor" => 0,
"YAML::Tiny" => 0,
"constant" => 0,
"strict" => 0,
"warnings" => 0
},
Expand Down Expand Up @@ -57,7 +56,6 @@ my %FallbackPrereqs = (
"Test::DZil" => 0,
"Test::More" => 0,
"YAML::Tiny" => 0,
"constant" => 0,
"strict" => 0,
"warnings" => 0
);
Expand Down
37 changes: 13 additions & 24 deletions lib/Dist/Zilla/Plugin/Author/KENTNL/RecommendFixes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use MooX::Lsub qw( lsub );
use Path::Tiny qw( path );
use YAML::Tiny;
use Data::DPath qw( dpath );
use constant _CAN_VARIABLE_MAGIC => eval 'require Variable::Magic; require Tie::RefHash::Weak; 1';
use Generic::Assertions;

with 'Dist::Zilla::Role::InstallTool';
Expand Down Expand Up @@ -92,26 +91,14 @@ sub _mk_assertions {

has _pc => ( is => ro =>, lazy => 1, builder => '_build__pc' );

sub _mk_cache {
my %cache;
if (_CAN_VARIABLE_MAGIC) {
## no critic (Miscellanea::ProhibitTies)
tie %cache, 'Tie::RefHash::Weak';
}
return sub {
return $cache{ \$_[0] } if exists $cache{ \$_[0] };
return ( $cache{ \$_[0] } = $_[1]->() );
};
}

sub _build__pc {
my ($self) = @_;

my $line_cache = _mk_cache;
my %cache;

my $get_lines = sub {
my ($path) = @_;
return $line_cache->( $path => sub { [ $path->lines_raw( { chomp => 1 } ) ] } );
exists $cache{ $_[0] } or ( $cache{ $_[0] } = [ $_[0]->lines_raw( { chomp => 1 } ) ] );
return $cache{ $_[0] };
};

return $self->_mk_assertions(
Expand All @@ -128,7 +115,9 @@ sub _build__pc {
},
have_line => sub {
my ( $path, $regex ) = @_;
for my $line ( @{ $get_lines->($path) } ) {
my (@lines) = @{ $get_lines->($path) };
return ( 0, "$path has no lines ( none to match $regex )" ) unless @lines;
for my $line (@lines) {
return ( 1, "$path Has line matching $regex" ) if $line =~ $regex;
}
return ( 0, "$path Does not have line matching $regex" );
Expand Down Expand Up @@ -159,21 +148,21 @@ has _dc => ( is => ro =>, lazy => 1, builder => '_build__dc' );
sub _build__dc {
my ($self) = @_;

my $yaml_cache = _mk_cache;
my %yaml_cache;

my $get_yaml = sub {
my ($path) = @_;
return $yaml_cache->(
$path => sub {
exists $yaml_cache{ $_[0] } or (
$yaml_cache{ $_[0] } = do {
my ( $r, $ok );
## no critic (ErrorHandling::RequireCheckingReturnValueOfEval)
eval {
$r = YAML::Tiny->read( path($path)->stringify )->[0];
$r = YAML::Tiny->read( path( $_[0] )->stringify )->[0];
$ok = 1;
};
return $r;
},
$r;
}
);
return $yaml_cache{ $_[0] };
};

return $self->_mk_assertions(
Expand Down
3 changes: 3 additions & 0 deletions misc/Changes.deps
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This file contains changes in REQUIRED dependencies for standard CPAN phases (co
[Changed / test requires]
- Test::More 0.89 → 0

[Removed / runtime requires]
- constant

0.005002 2016-09-10T06:01:15Z

0.005001 2015-07-11T14:36:47Z
Expand Down
3 changes: 3 additions & 0 deletions misc/Changes.deps.all
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ This file contains ALL changes in dependencies in both REQUIRED / OPTIONAL depen
[Changed / test requires]
- Test::More 0.89 → 0

[Removed / runtime requires]
- constant

0.005002 2016-09-10T06:01:15Z
[Added / develop requires]
- English
Expand Down

0 comments on commit d8b618b

Please sign in to comment.