Skip to content

Commit

Permalink
0.41 spath_delta(): don't return full second path if it's a subset of…
Browse files Browse the repository at this point in the history
… first one
  • Loading branch information
mr-mixas committed Aug 19, 2016
1 parent d618e9e commit 8cde50a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for Struct-Path

0.41 2016-08-19
spath_delta(): don't return full second path if it's a subset of first one

0.40 2016-08-18
spath_delta() appeared

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Struct::Path - Path for nested structures where path is also a structure

# VERSION

Version 0.40
Version 0.41

# SYNOPSIS

Expand Down Expand Up @@ -102,7 +102,7 @@ See [Struct::Path::PerlStyle](https://metacpan.org/pod/Struct::Path::PerlStyle)

## spath\_delta

Returns delta for two passed paths.
Returns delta for two passed paths. By delta means steps from the second path without beginning common steps for both.

@delta = spath_delta($path1, $path2)

Expand Down
14 changes: 5 additions & 9 deletions lib/Struct/Path.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Struct::Path - Path for nested structures where path is also a structure
=head1 VERSION
Version 0.40
Version 0.41
=cut

our $VERSION = '0.40';
our $VERSION = '0.41';

=head1 SYNOPSIS
Expand Down Expand Up @@ -231,7 +231,7 @@ sub spath($$;@) {

=head2 spath_delta
Returns delta for two passed paths.
Returns delta for two passed paths. By delta means steps from the second path without beginning common steps for both.
@delta = spath_delta($path1, $path2)
Expand All @@ -241,12 +241,8 @@ sub spath_delta($$) {
my ($frst, $scnd) = @_;

croak "Second path must be an arrayref" unless (ref $scnd eq 'ARRAY');
if (defined $frst) {
croak "First path may be undef or an arrayref" unless (ref $frst eq 'ARRAY');
return @{$scnd} if (@{$scnd} < @{$frst});
} else {
return @{$scnd};
}
return @{$scnd} unless (defined $frst);
croak "First path may be undef or an arrayref" unless (ref $frst eq 'ARRAY');

my $i = 0;
MAIN: while ($i < @{$frst}) {
Expand Down
4 changes: 2 additions & 2 deletions t/30-spath_delta.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ cmp_deeply(
);
cmp_deeply(
\@delta,
[ {keys => ['a']},[0,3],{keys => ['ana', 'anb']} ],
"One step removed"
[],
"One step removed -- no delta"
);

@delta = spath_delta(
Expand Down

0 comments on commit 8cde50a

Please sign in to comment.