Skip to content

Commit

Permalink
Merge branch 'dev' into fix_importer
Browse files Browse the repository at this point in the history
  • Loading branch information
phochste committed Sep 2, 2015
2 parents 05a5a1e + ba6d2a4 commit 0310b47
Show file tree
Hide file tree
Showing 31 changed files with 202 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ my %module_build_args = (
"Log::Any::Test" => "1.03",
"Test::Deep" => "0.112",
"Test::Exception" => "0.32",
"Test::More" => "1.001003",
"Test::More" => "0.99",
"Test::Pod" => 0
}
);
Expand All @@ -75,7 +75,7 @@ my %fallback_build_requires = (
"Module::Build" => "0.28",
"Test::Deep" => "0.112",
"Test::Exception" => "0.32",
"Test::More" => "1.001003",
"Test::More" => "0.99",
"Test::Pod" => 0
);

Expand Down
2 changes: 1 addition & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires 'perl', 'v5.10.1';
on 'test', sub {
requires 'Test::Deep', '0.112';
requires 'Test::Exception', '0.32';
requires 'Test::More', '1.001003';
requires 'Test::More', '0.99';
requires 'Test::Pod', 0;
requires 'Log::Any::Test', '1.03';
};
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Addable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ L<Catmandu::Fixable>, L<Catmandu::Exporter> , L<Catmandu::Store>
=cut

use namespace::clean;
use Catmandu::Sane;
use Catmandu::Util qw(:is :check);
use Moo::Role;
use namespace::clean;

with 'Catmandu::Fixable';

Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/ArrayIterator.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package Catmandu::ArrayIterator;

use namespace::clean;
use Catmandu::Sane;
use Catmandu::Util qw(check_array_ref);
use Role::Tiny::With;
use namespace::clean;

with 'Catmandu::Iterable';

Expand Down
22 changes: 18 additions & 4 deletions lib/Catmandu/Bag.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package Catmandu::Bag;

use namespace::clean;
use Catmandu::Sane;
use Catmandu::Util qw(:check);
use Catmandu::Util qw(:check is_string require_package);
use Catmandu::IdGenerator::UUID;
use Moo::Role;
use Data::UUID;
use namespace::clean;

with 'Catmandu::Logger';
with 'Catmandu::Pluggable'; # TODO
Expand All @@ -17,6 +17,20 @@ requires 'delete_all';

has store => (is => 'ro'); # TODO
has name => (is => 'ro'); # TODO
has id_generator => (
is => 'lazy',
coerce => sub {
if (is_string($_[0])) {
require_package($_[0], 'Catmandu::IdGenerator')->new;
} else {
$_[0];
}
},
);

sub _build_id_generator {
state $uuid = Catmandu::IdGenerator::UUID->new;
}

before get => sub {
check_value($_[1]);
Expand All @@ -33,7 +47,7 @@ before delete => sub {
};

sub generate_id {
Data::UUID->new->create_str;
$_[0]->id_generator->generate;
}

sub get_or_add {
Expand Down
36 changes: 27 additions & 9 deletions lib/Catmandu/Error.pm
Original file line number Diff line number Diff line change
@@ -1,66 +1,84 @@
package Catmandu::Error;
use namespace::clean;

use Catmandu::Sane;
use Moo;
use namespace::clean;

extends 'Throwable::Error';

package Catmandu::BadVal;
use namespace::clean;

use Catmandu::Sane;
use Moo;
use namespace::clean;

extends 'Catmandu::Error';

package Catmandu::BadArg;
use namespace::clean;

use Catmandu::Sane;
use Moo;
use namespace::clean;

extends 'Catmandu::BadVal';

package Catmandu::NotImplemented;
use namespace::clean;

use Catmandu::Sane;
use Moo;
use namespace::clean;

extends 'Catmandu::Error';

package Catmandu::NoSuchPackage;
use namespace::clean;

use Catmandu::Sane;
use Moo;
use namespace::clean;

extends 'Catmandu::Error';

has package_name => (is => 'ro');

package Catmandu::FixParseError;
use namespace::clean;

use Catmandu::Sane;
use Moo;
use namespace::clean;

extends 'Catmandu::Error';

has source => (is => 'ro');

package Catmandu::NoSuchFixPackage;
use namespace::clean;

use Catmandu::Sane;
use Moo;
use namespace::clean;

extends 'Catmandu::NoSuchPackage';

has fix_name => (is => 'ro');
has source => (is => 'rw', writer => 'set_source');

package Catmandu::BadFixArg;
use namespace::clean;

use Catmandu::Sane;
use Moo;
use namespace::clean;

extends 'Catmandu::BadArg';

has package_name => (is => 'ro');
has fix_name => (is => 'ro');
has source => (is => 'rw', writer => 'set_source');

package Catmandu::FixError;
use namespace::clean;

use Catmandu::Sane;
use Moo;
use namespace::clean;

extends 'Catmandu::Error';

has data => (is => 'ro');
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Exporter/CSV.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package Catmandu::Exporter::CSV;

use namespace::clean;
use Catmandu::Sane;
use Text::CSV;
use Moo;
use namespace::clean;

with 'Catmandu::Exporter';

Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Exporter/JSON.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package Catmandu::Exporter::JSON;

use namespace::clean;
use Catmandu::Sane;
use JSON::XS ();
use Moo;
use MooX::Aliases;
use namespace::clean;

with 'Catmandu::Exporter';

Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Exporter/Null.pm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package Catmandu::Exporter::Null;

use namespace::clean;
use Catmandu::Sane;
use Moo;
use namespace::clean;

with 'Catmandu::Exporter';

Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Exporter/Text.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package Catmandu::Exporter::Text;

use namespace::clean;
use Catmandu::Sane;
use Moo;
use Catmandu::Util;
use namespace::clean;

with 'Catmandu::Exporter';

Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Exporter/YAML.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package Catmandu::Exporter::YAML;

use namespace::clean;
use Catmandu::Sane;
use YAML::XS ();
use Moo;
use namespace::clean;

with 'Catmandu::Exporter';

Expand Down
5 changes: 1 addition & 4 deletions lib/Catmandu/Fix/from_json.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ use Moo;
use Catmandu::Fix::Has;

has path => (fix_arg => 1);
has _json_var => (is => 'rwp', writer => '_set_json_var', init_arg => undef);

with 'Catmandu::Fix::SimpleGetValue';

sub emit_value {
my ($self, $var, $fixer) = @_;
# memoize in case called multiple times
my $json_var = $self->_json_var ||
$self->_set_json_var($fixer->capture(JSON::XS->new->utf8(0)->pretty(0)->allow_nonref(1)));
my $json_var = $fixer->capture(JSON::XS->new->utf8(0)->pretty(0)->allow_nonref(1));

"if (is_string(${var})) {" .
"${var} = ${json_var}->decode(${var});" .
Expand Down
4 changes: 2 additions & 2 deletions lib/Catmandu/Fix/retain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Catmandu::Fix::retain - delete everything except the paths given
=head1 SYNOPSIS
# Delete everything except foo.bar and baz.bar
retain(foo.bar, baz.bar)
retain(foo.bar, bar.baz)
{bar => 3, foo => {bar => 1, baz => 2}}
{bar => { x => 1} , foo => {bar => 1, y => 2}}
# becomes
{foo => {bar => 1}}
Expand Down
4 changes: 1 addition & 3 deletions lib/Catmandu/Fix/to_json.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ use Moo;
use Catmandu::Fix::Has;

has path => (fix_arg => 1);
has _json_var => (is => 'rwp', writer => '_set_json_var', init_arg => undef);

with 'Catmandu::Fix::SimpleGetValue';

sub emit_value {
my ($self, $var, $fixer) = @_;
# memoize in case called multiple times
my $json_var = $self->_json_var ||
$self->_set_json_var($fixer->capture(JSON::XS->new->utf8(0)->pretty(0)->allow_nonref(1)));
my $json_var = $fixer->capture(JSON::XS->new->utf8(0)->pretty(0)->allow_nonref(1));

"if (is_maybe_value(${var}) || is_array_ref(${var}) || is_hash_ref(${var})) {" .
"${var} = ${json_var}->encode(${var});" .
Expand Down
9 changes: 9 additions & 0 deletions lib/Catmandu/IdGenerator.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package Catmandu::IdGenerator;

use Catmandu::Sane;
use Moo::Role;
use namespace::clean;

requires 'generate';

1;
30 changes: 30 additions & 0 deletions lib/Catmandu/IdGenerator/Mock.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package Catmandu::IdGenerator::Mock;

use Catmandu::Sane;
use Moo;
use Catmandu::Util qw(check_natural);
use namespace::clean;

with 'Catmandu::IdGenerator';

has first_id => (
is => 'ro',
isa => sub { check_natural($_[0]) },
default => sub { 0 },
);

has next_id => (
is => 'rwp',
init_arg => undef,
lazy => 1,
builder => 'first_id',
);

sub generate {
my ($self) = @_;
my $id = $self->next_id;
$self->_set_next_id($id + 1);
$id;
}

1;
18 changes: 18 additions & 0 deletions lib/Catmandu/IdGenerator/UUID.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Catmandu::IdGenerator::UUID;

use Catmandu::Sane;
use Data::UUID;
use Moo;
use namespace::clean;

with 'Catmandu::IdGenerator';

has _uuid => (is => 'lazy', builder => '_build_uuid');

sub _build_uuid { Data::UUID->new }

sub generate {
$_[0]->_uuid->create_str;
}

1;
2 changes: 1 addition & 1 deletion lib/Catmandu/Importer/CSV.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package Catmandu::Importer::CSV;

use namespace::clean;
use Catmandu::Sane;
use Text::CSV;
use Moo;
use namespace::clean;

with 'Catmandu::Importer';

Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Importer/JSON.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package Catmandu::Importer::JSON;

use namespace::clean;
use Catmandu::Sane;
use JSON::XS ();
use Moo;
use namespace::clean;

with 'Catmandu::Importer';

Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Importer/Mock.pm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package Catmandu::Importer::Mock;

use namespace::clean;
use Catmandu::Sane;
use Moo;
use namespace::clean;

with 'Catmandu::Importer';

Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Importer/Modules.pm
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package Catmandu::Importer::Modules;

use namespace::clean;
use Catmandu::Sane;
use Module::Info;
use File::Spec;
use File::Find::Rule;
use Moo;
use Catmandu::Util qw(array_split pod_section);
use namespace::clean;

with 'Catmandu::Importer';

Expand Down

0 comments on commit 0310b47

Please sign in to comment.