diff --git a/Taskfile.yaml b/Taskfile.yaml index 522a945..83f77eb 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -9,7 +9,7 @@ vars: tasks: format: cmds: - - git diff-ls {{.TARGET_BRANCH}} | grep -e '\.pm$\|\.t$' | xargs -IX perltidy -b X + - git diff-ls --diff-filter=ACMR {{.TARGET_BRANCH}} | grep -e '\.pm$\|\.t$' | xargs -IX perltidy -b X default: cmds: diff --git a/lib/Dancer2/Plugin/JsonApi/Registry.pm b/lib/Dancer2/Plugin/JsonApi/Registry.pm index 4d6f2c2..b1a1c6a 100644 --- a/lib/Dancer2/Plugin/JsonApi/Registry.pm +++ b/lib/Dancer2/Plugin/JsonApi/Registry.pm @@ -1,7 +1,7 @@ package Dancer2::Plugin::JsonApi::Registry; use 5.32.0; -use Dancer2::Plugin::JsonApi::Registry::Schema; +use Dancer2::Plugin::JsonApi::Schema; use Carp; @@ -39,7 +39,7 @@ Adds a data type to the registry. =cut sub add_type ( $self, $type, $definition = {} ) { - $self->{types}{$type} = Dancer2::Plugin::JsonApi::Registry::Schema->new( + $self->{types}{$type} = Dancer2::Plugin::JsonApi::Schema->new( registry => $self, type => $type, %$definition @@ -48,14 +48,14 @@ sub add_type ( $self, $type, $definition = {} ) { =head2 type($type) -Returns the type's C. Throws an +Returns the type's C. Throws an error if the type does not exist. =cut sub type ( $self, $type ) { return $self->types->{$type} //= - Dancer2::Plugin::JsonApi::Registry::Schema->new( type => $type ); + Dancer2::Plugin::JsonApi::Schema->new( type => $type ); } 1; diff --git a/lib/Dancer2/Plugin/JsonApi/Registry/Schema.pm b/lib/Dancer2/Plugin/JsonApi/Schema.pm similarity index 98% rename from lib/Dancer2/Plugin/JsonApi/Registry/Schema.pm rename to lib/Dancer2/Plugin/JsonApi/Schema.pm index f8d1e6a..adf9fc6 100644 --- a/lib/Dancer2/Plugin/JsonApi/Registry/Schema.pm +++ b/lib/Dancer2/Plugin/JsonApi/Schema.pm @@ -1,6 +1,6 @@ use 5.32.0; -package Dancer2::Plugin::JsonApi::Registry::Schema; +package Dancer2::Plugin::JsonApi::Schema; use Moo; diff --git a/t/registry.t b/t/registry.t index e5277c9..9626740 100644 --- a/t/registry.t +++ b/t/registry.t @@ -14,13 +14,15 @@ $registry->add_type( no warnings qw/ uninitialized /; return "/peoples/$data->{id}"; } - } } ); + } + } +); -isa_ok $registry->type('people') => - 'Dancer2::Plugin::JsonApi::Registry::Schema'; +isa_ok $registry->type('people') => 'Dancer2::Plugin::JsonApi::Schema'; like( $registry->serialize( people => {} ), - { jsonapi => { version => '1.0' } } ); + { jsonapi => { version => '1.0' } } +); done_testing(); diff --git a/t/registry-schema.t b/t/schema.t similarity index 79% rename from t/registry-schema.t rename to t/schema.t index ffe3a94..5a2495c 100644 --- a/t/registry-schema.t +++ b/t/schema.t @@ -1,19 +1,19 @@ use Test2::V0; -use Dancer2::Plugin::JsonApi::Registry::Schema; +use Dancer2::Plugin::JsonApi::Schema; use Dancer2::Plugin::JsonApi::Registry; use experimental qw/ signatures /; my $type = - Dancer2::Plugin::JsonApi::Registry::Schema->new( 'type' => 'thing' ); + Dancer2::Plugin::JsonApi::Schema->new( 'type' => 'thing' ); like $type->serialize( { attr1 => 'a', id => '123' }, { foo => 1 } ) => { jsonapi => { version => '1.0' }, data => { type => 'thing', id => '123' } }; -is( Dancer2::Plugin::JsonApi::Registry::Schema->new( +is( Dancer2::Plugin::JsonApi::Schema->new( 'type' => 'thing', id => 'foo' )->serialize( { foo => '123' } )->{data}{id} => '123', @@ -35,12 +35,12 @@ is( $serialized->{data}{id} => '12', like $serialized->{data}, { links => { self => '/some/url' } }, "links"; sub schema_serialize ( $schema, $data ) { - return Dancer2::Plugin::JsonApi::Registry::Schema->new(%$schema) + return Dancer2::Plugin::JsonApi::Schema->new(%$schema) ->serialize($data); } like( - Dancer2::Plugin::JsonApi::Registry::Schema->new( + Dancer2::Plugin::JsonApi::Schema->new( type => 'thing', top_level_meta => { foo => 1, @@ -54,7 +54,7 @@ like( subtest 'attributes' => sub { my $serialized = - Dancer2::Plugin::JsonApi::Registry::Schema->new( type => 'thing', ) + Dancer2::Plugin::JsonApi::Schema->new( type => 'thing', ) ->serialize( { id => 1, foo => 'bar' } ); is $serialized->{data} => { @@ -67,7 +67,7 @@ subtest 'attributes' => sub { subtest 'a single scalar == id', sub { my $serialized = - Dancer2::Plugin::JsonApi::Registry::Schema->new( type => 'thing' ) + Dancer2::Plugin::JsonApi::Schema->new( type => 'thing' ) ->serialize('blah'); is $serialized->{data} => { @@ -77,7 +77,7 @@ subtest 'a single scalar == id', sub { }; subtest 'allowed_attributes', sub { - my $serialized = Dancer2::Plugin::JsonApi::Registry::Schema->new( + my $serialized = Dancer2::Plugin::JsonApi::Schema->new( type => 'thing', allowed_attributes => ['foo'], )->serialize( { id => 1, foo => 2, bar => 3 } ); @@ -91,7 +91,7 @@ subtest 'allowed_attributes', sub { subtest 'empty data', sub { my $serialized = - Dancer2::Plugin::JsonApi::Registry::Schema->new( type => 'thing' ) + Dancer2::Plugin::JsonApi::Schema->new( type => 'thing' ) ->serialize(undef); ok( !$serialized->{data}, "there is no data" ); @@ -113,7 +113,7 @@ package FakeApp { } subtest "add the self link if tied to the app" => sub { - my $serialized = Dancer2::Plugin::JsonApi::Registry::Schema->new( + my $serialized = Dancer2::Plugin::JsonApi::Schema->new( type => 'thing', registry => Dancer2::Plugin::JsonApi::Registry->new( app => FakeApp->new ) @@ -123,7 +123,7 @@ subtest "add the self link if tied to the app" => sub { }; subtest 'attributes function' => sub { - my $serialized = Dancer2::Plugin::JsonApi::Registry::Schema->new( + my $serialized = Dancer2::Plugin::JsonApi::Schema->new( type => 'thing', attributes => sub ( $data, @ ) { return +{ reverse %$data },;