Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Path-Class-Rule CPAN distribution.

Report information
The Basics
Id: 80426
Status: resolved
Priority: 0/
Queue: Path-Class-Rule

People
Owner: Nobody in particular
Requestors: cjm [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.011
Fixed in: (no value)



Subject: clone doesn't go deep enough
The clone method doesn't actually work, because it does a shallow copy of the object, and the list of rules is stored as an arrayref value. So the original object and the clone share the same list of rules, and adding a rule to one also adds it to the other. Here's a test demonstrating the issue:
Subject: clone.t
use 5.006; use strict; use warnings; use autodie; use Test::More 0.92; use Path::Class; use File::Temp; use Test::Deep qw/cmp_deeply/; use File::pushd qw/pushd/; use lib 't/lib'; use PCNTest; use Path::Class::Rule; #--------------------------------------------------------------------------# my @tree = qw( aaaa.txt bbbb.txt aaaabbbb.txt ); my $td = make_tree(@tree); sub test { my ($name, $rule, $expected) = @_; my @got = sort map { $_->relative($td)->as_foreign("Unix")->stringify } $rule->all($td); local $Test::Builder::Level = $Test::Builder::Level + 1; cmp_deeply( \@got, $expected, $name) or diag explain { got => \@got, expected => $expected }; } # end test { my $ruleA = Path::Class::Rule->new->file; my $ruleB = $ruleA->new->name("*bb*"); $ruleA->name("*aa*"); test('new *aa*', $ruleA => [qw/aaaa.txt aaaabbbb.txt/]); test('new *bb*', $ruleB => [qw/aaaabbbb.txt bbbb.txt/]); } { my $ruleA = Path::Class::Rule->new->file; my $ruleB = $ruleA->clone->name("*bb*"); $ruleA->name("*aa*"); test('cloned *aa*', $ruleA => [qw/aaaa.txt aaaabbbb.txt/]); test('cloned *bb*', $ruleB => [qw/aaaabbbb.txt bbbb.txt/]); } done_testing;
Thank you for the report and especially for the test file. I've fixed it with Data::Clone and released the fix to CPAN. David