Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
nics committed Mar 23, 2017
1 parent 6e035cf commit ffd3f97
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 94 deletions.
3 changes: 2 additions & 1 deletion lib/Catmandu/Cmd/copy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ sub command {
};

if ($opts->transaction) {
$self->usage_error("Bag isn't transactional") if !$into->does('Catmandu::Transactional');
$self->usage_error("Bag isn't transactional")
if !$into->does('Catmandu::Transactional');
$into->transaction($tx);
}
else {
Expand Down
3 changes: 2 additions & 1 deletion lib/Catmandu/Cmd/import.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ sub command {
};

if ($opts->transaction) {
$self->usage_error("Bag isn't transactional") if !$into->does('Catmandu::Transactional');
$self->usage_error("Bag isn't transactional")
if !$into->does('Catmandu::Transactional');
$into->transaction($tx);
}
else {
Expand Down
8 changes: 4 additions & 4 deletions lib/Catmandu/Fix/Condition/valid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use Catmandu::Util qw(require_package);
use namespace::clean;
use Catmandu::Fix::Has;

has path => (fix_arg => 1);
has name => (fix_arg => 1);
has opts => (fix_opt => 'collect');
has validator => (is => 'lazy', init_arg => undef);
has path => (fix_arg => 1);
has name => (fix_arg => 1);
has opts => (fix_opt => 'collect');
has validator => (is => 'lazy', init_arg => undef);

with 'Catmandu::Fix::Condition::SimpleAllTest';

Expand Down
1 change: 1 addition & 0 deletions lib/Catmandu/Fix/Inlineable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sub import {
my $key = join('--', @_);
$fixer = $cache->{$key} ||= do {
my $f = $pkg->new(@_);

# memoize instance of Fix.pm if it's an emitting fix
$f = $f->fixer if $f->can('fixer');
$f;
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/rename.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ with 'Catmandu::Fix::SimpleGetValue';

sub emit_value {
my ($self, $var, $fixer) = @_;
my $search = $self->search;
my $search = $self->search;
my $replace = $self->replace;
my $renamer;

Expand Down
47 changes: 27 additions & 20 deletions lib/Catmandu/Fix/search_in_store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ use Catmandu::Fix::Has;
with 'Catmandu::Fix::Base';

#options/arguments
has path => ( fix_arg => 1 );
has store_name => ( fix_opt => 1, init_arg => 'store');
has bag_name => ( fix_opt => 1, init_arg => 'bag' );
has limit => ( fix_opt => 1, init_arg => undef, default => sub { 20 } );
has start => ( fix_opt => 1, init_arg => undef, default => sub { 0 } );
has sort => ( fix_opt => 1, init_arg => undef );
has store_args => ( fix_opt => 'collect' );
has path => (fix_arg => 1);
has store_name => (fix_opt => 1, init_arg => 'store');
has bag_name => (fix_opt => 1, init_arg => 'bag');
has limit => (fix_opt => 1, init_arg => undef, default => sub {20});
has start => (fix_opt => 1, init_arg => undef, default => sub {0});
has sort => (fix_opt => 1, init_arg => undef);
has store_args => (fix_opt => 'collect');

#internal
has store => ( is => 'lazy', init_arg => undef, builder => '_build_store' );
has bag => ( is => 'lazy', init_arg => undef, builder => '_build_bag' );
has store => (is => 'lazy', init_arg => undef, builder => '_build_store');
has bag => (is => 'lazy', init_arg => undef, builder => '_build_bag');

sub _build_store {
my $self = $_[0];
Catmandu->store( $self->store_name, %{ $self->store_args } );
Catmandu->store($self->store_name, %{$self->store_args});
}

sub _build_bag {
my ( $self ) = @_;
my ($self) = @_;
defined $self->bag_name
? $self->store->bag($self->bag_name)
: $self->store->bag;
}

sub emit {
my ( $self, $fixer ) = @_;
my ($self, $fixer) = @_;

my $path = $fixer->split_path($self->path);
my $key = pop @$path;
Expand All @@ -42,25 +42,32 @@ sub emit {
my $start = $self->start;
my $sort = $self->sort || "";

$fixer->emit_walk_path ( $fixer->var, $path, sub {
$fixer->emit_walk_path(
$fixer->var,
$path,
sub {

my $var = shift;
my $var = shift;

$fixer->emit_get_key ( $var, $key, sub {
$fixer->emit_get_key(
$var, $key,
sub {

my $val_var = shift;
my $val_var = shift;

my $perl = <<EOF;
my $perl = <<EOF;
${val_var} = ${bag_var}->search( query => $val_var, start => ${start}, limit => ${limit}, sort => '${sort}' );
${val_var} = { start => ${start}, limit => ${limit}, total => ${val_var}->total(), hits => ${val_var}->to_array() };
EOF

$perl;
$perl;

});
});
}
);
}
);
}

=head1 NAME
Expand Down
6 changes: 5 additions & 1 deletion lib/Catmandu/Importer/Modules.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ sub generator {
}
elsif (open(my $fh, '<:encoding(UTF-8)', $file)) {
while (my $line = <$fh>) {
if (my ($version) = $line =~ /^\s*our\s+\$VERSION\s*=\s*['"]([^'"]+)['"]\s*;/) {
if (my ($version)
= $line
=~ /^\s*our\s+\$VERSION\s*=\s*['"]([^'"]+)['"]\s*;/
)
{
$data->{version} = $version;
last;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Catmandu/Iterable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ sub stop_if {

sub run {
my ($self) = @_;
my $next = $self->generator;
my $run = 0;
my $next = $self->generator;
my $run = 0;
while (defined($next->())) {
$run ||= 1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Searchable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ my $AROUND_SEARCH = sub {
}

$args{query} = $self->normalize_query($args{query});
$args{sort} = $self->normalize_sort($args{sort});
$args{sort} = $self->normalize_sort($args{sort});

defined $args{$_} || delete $args{$_} for keys %args;

Expand Down
2 changes: 1 addition & 1 deletion t/Catmandu-Fix-Condition-valid.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ my $cond;
my $pass = [Catmandu::Fix::set_field->new('test', 'pass')];
my $fail = [Catmandu::Fix::set_field->new('test', 'fail')];

$cond = $pkg->new('', 'Simple', handler => sub {});
$cond = $pkg->new('', 'Simple', handler => sub { });
$cond->pass_fixes($pass);
$cond->fail_fixes($fail);

Expand Down
3 changes: 2 additions & 1 deletion t/Catmandu-Fix-rename.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ BEGIN {
use_ok $pkg;
}

is_deeply $pkg->new('dots', '\.', '-')->fix({dots => {'a.b' => [{'c.d' => ""}]}}),
is_deeply $pkg->new('dots', '\.', '-')
->fix({dots => {'a.b' => [{'c.d' => ""}]}}),
{dots => {'a-b' => [{'c-d' => ""}]}};

done_testing;
Loading

0 comments on commit ffd3f97

Please sign in to comment.