1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
package Catmandu::Path;
use Catmandu::Sane;
our $VERSION = '1.2024';
use Catmandu::Util qw(is_array_ref is_code_ref);
use Moo::Role;
has path => (is => 'ro', required => 1);
requires 'getter';
requires 'setter';
requires 'creator';
requires 'updater';
requires 'deleter';
around creator => sub {
my $orig = shift;
my $self = shift;
my %opts = @_ == 1 ? (value => $_[0]) : @_;
$orig->($self, %opts);
};
around updater => sub {
my $orig = shift;
my $self = shift;
my %opts = @_ == 1 ? (value => $_[0]) : @_;
for my $key (keys %opts) {
my $val = $opts{$key};
next unless $key =~ s/^if_//;
push @{$opts{if} ||= []}, $key, $val;
}
if (my $tests = $opts{if}) {
for (my $i = 0; $i < @$tests; $i += 2) {
my $test = $tests->[$i];
$test = [$test] unless is_array_ref($test);
$tests->[$i]
= [map {is_code_ref($_) ? $_ : Catmandu::Util->can("is_$_")}
@$test];
}
}
$orig->($self, %opts);
};
1;
__END__
=pod
=head1 NAME
Catmandu::Path - Base role for Catmandu path implementations
=head1 SEE ALSO
L<Catmandu::Path::simple>.
=cut
|