pax_global_header00006660000000000000000000000064122272556310014517gustar00rootroot0000000000000052 comment=06b822b0fb3f753295b15a520f71f52e776499f3 libdata-hal-perl-1.000/000077500000000000000000000000001222725563100146215ustar00rootroot00000000000000libdata-hal-perl-1.000/Build.PL000066400000000000000000000030351222725563100161160ustar00rootroot00000000000000use Module::Build qw(); Module::Build->new( add_to_cleanup => [ 'Data-HAL-*' ], build_requires => { 'Data::Visitor::Callback' => 0, 'File::Slurp' => 0, 'JSON' => 0, 'Log::Any::Adapter' => 0, 'Log::Any::Adapter::FileHandle' => 0, 'strictures' => 0, 'Test::Fatal' => 0, 'Test::More' => 0, }, configure_requires => { 'Module::Build' => 0.40, }, dist_version_from => 'lib/Data/HAL.pm', dynamic_config => 0, license => 'perl', meta-spec => { url => 'http://module-build.sourceforge.net/META-spec-v1.4.html', version => '1.4', }, module_name => 'Data::HAL', no_index => { file => [ 'lib/Data/HAL/URI/NamespaceMap.pm', ], }, requires => { 'boolean' => 0, 'Clone' => 0, 'Data::Visitor::Callback' => 0, 'failures' => 0, 'HTTP::Headers::Util' => 0, 'JSON' => 0, 'Log::Any' => 0, 'MIME::Type' => 0, 'Moo' => 0, 'perl' => '5.008', 'Safe::Isa' => 0, 'Scalar::Util' => 0, 'strictures' => 0, 'Types::Standard' => 0, 'URI' => 0, 'URI::IRI' => 0, 'URI::NamespaceMap' => 0, 'URI::Template' => 0, 'XML::RegExp' => 0, }, resources => { license => 'http://dev.perl.org/licenses/', bugtracker => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-HAL', repository => 'https://github.com/daxim/Data-HAL', }, )->create_build_script; libdata-hal-perl-1.000/Changes000066400000000000000000000001611222725563100161120ustar00rootroot00000000000000=encoding UTF-8 =head1 NAME Changes - Revision history for Data-HAL =head2 1.000 2013-10-15 Initial release. libdata-hal-perl-1.000/MANIFEST000066400000000000000000000013271222725563100157550ustar00rootroot00000000000000Build.PL Changes lib/Data/HAL.pm lib/Data/HAL/Link.pm lib/Data/HAL/URI.pm lib/Data/HAL/URI/NamespaceMap.pm MANIFEST This list of files META.json META.yml README t/00.load.t t/curies.t t/deprecation.t t/double.t t/example.json t/example1.json t/example2.json t/example3.json t/example4.json t/exampleWithArray.json t/exampleWithLiteralNullProperty.json t/exampleWithMultipleNestedSubresources.json t/exampleWithMultipleSubresources.json t/exampleWithNullProperty.json t/exampleWithoutHref.json t/exampleWithSubresource.json t/exampleWithSubresourceLinkingToItself.json t/exampleWithTemplate.json t/exampleWithUnderscoredProperty.json t/headers.t t/invalid.t t/profile.t t/round-trip.t SIGNATURE Added here by Module::Build libdata-hal-perl-1.000/META.json000066400000000000000000000044041222725563100162440ustar00rootroot00000000000000{ "abstract" : "Hypertext Application Language resource", "author" : [ "Lars Dɪᴇᴄᴋᴏᴡ C<< >>" ], "dynamic_config" : 0, "generated_by" : "Module::Build version 0.4007, CPAN::Meta::Converter version 2.132830", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Data-HAL", "no_index" : { "file" : [ "lib/Data/HAL/URI/NamespaceMap.pm" ] }, "prereqs" : { "build" : { "requires" : { "Data::Visitor::Callback" : "0", "File::Slurp" : "0", "JSON" : "0", "Log::Any::Adapter" : "0", "Log::Any::Adapter::FileHandle" : "0", "Test::Fatal" : "0", "Test::More" : "0", "strictures" : "0" } }, "configure" : { "requires" : { "Module::Build" : "0.4" } }, "runtime" : { "requires" : { "Clone" : "0", "Data::Visitor::Callback" : "0", "HTTP::Headers::Util" : "0", "JSON" : "0", "Log::Any" : "0", "MIME::Type" : "0", "Moo" : "0", "Safe::Isa" : "0", "Scalar::Util" : "0", "Types::Standard" : "0", "URI" : "0", "URI::IRI" : "0", "URI::NamespaceMap" : "0", "URI::Template" : "0", "XML::RegExp" : "0", "boolean" : "0", "failures" : "0", "perl" : "5.008", "strictures" : "0" } } }, "provides" : { "Data::HAL" : { "file" : "lib/Data/HAL.pm", "version" : "1.000" }, "Data::HAL::Link" : { "file" : "lib/Data/HAL/Link.pm", "version" : "1.000" }, "Data::HAL::URI" : { "file" : "lib/Data/HAL/URI.pm", "version" : "1.000" }, "Data::HAL::URI::NamespaceMap" : { "file" : "lib/Data/HAL/URI/NamespaceMap.pm", "version" : "1.000" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "1.000" } libdata-hal-perl-1.000/META.yml000066400000000000000000000024431222725563100160750ustar00rootroot00000000000000--- abstract: 'Hypertext Application Language resource' author: - 'Lars Dɪᴇᴄᴋᴏᴡ C<< >>' build_requires: Data::Visitor::Callback: 0 File::Slurp: 0 JSON: 0 Log::Any::Adapter: 0 Log::Any::Adapter::FileHandle: 0 Test::Fatal: 0 Test::More: 0 strictures: 0 configure_requires: Module::Build: 0.4 dynamic_config: 0 generated_by: 'Module::Build version 0.4007, CPAN::Meta::Converter version 2.132830' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Data-HAL no_index: file: - lib/Data/HAL/URI/NamespaceMap.pm provides: Data::HAL: file: lib/Data/HAL.pm version: 1.000 Data::HAL::Link: file: lib/Data/HAL/Link.pm version: 1.000 Data::HAL::URI: file: lib/Data/HAL/URI.pm version: 1.000 Data::HAL::URI::NamespaceMap: file: lib/Data/HAL/URI/NamespaceMap.pm version: 1.000 requires: Clone: 0 Data::Visitor::Callback: 0 HTTP::Headers::Util: 0 JSON: 0 Log::Any: 0 MIME::Type: 0 Moo: 0 Safe::Isa: 0 Scalar::Util: 0 Types::Standard: 0 URI: 0 URI::IRI: 0 URI::NamespaceMap: 0 URI::Template: 0 XML::RegExp: 0 boolean: 0 failures: 0 perl: 5.008 strictures: 0 resources: license: http://dev.perl.org/licenses/ version: 1.000 libdata-hal-perl-1.000/README000066400000000000000000000013741222725563100155060ustar00rootroot00000000000000=encoding UTF-8 Data-HAL version 1.000 is Copyright © 2013, Lars Dɪᴇᴄᴋᴏᴡ =head1 NAME README - basic information for users prior to downloading =head1 INSTALLATION See L, L, L. =head1 LICENCE AND COPYRIGHT Copyright © 2013 Lars Dɪᴇᴄᴋᴏᴡ C<< >> This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5.18.0. =head2 Disclaimer of warranty This library is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness libdata-hal-perl-1.000/SIGNATURE000066400000000000000000000067431222725563100161170ustar00rootroot00000000000000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.73. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 SHA1 6716f26200ebb14dc8a8fd59f6c1c965f8ad4b75 Build.PL SHA1 a76b9d8a0f1e4d79220acfb833819d6d8bc5e6b7 Changes SHA1 6c79a8c2deb18d6f4b702bd8495731f86ddd0fb0 MANIFEST SHA1 483d207fdfee85541b3813a96fd299f4a866d68c META.json SHA1 1a839a648279a21c1daa0c723c6a0f96baccbdfc META.yml SHA1 b8c8df5a3e0b2214e8b848ae1e8301020a93d9cd README SHA1 95bf82cc9dd9268d72c11644eb09de2f9faee5cd lib/Data/HAL.pm SHA1 d923daeb277126265e7b49d5e738c225ade0ee93 lib/Data/HAL/Link.pm SHA1 0d6e407c7c52fc6ea8274494401aee32b88333c7 lib/Data/HAL/URI.pm SHA1 ac5108b667d94b94b1ee580a0d33fc12db98c5df lib/Data/HAL/URI/NamespaceMap.pm SHA1 00e96bace07bf698d7751a3c187c7eabdf01d018 t/00.load.t SHA1 49cd2b3e81db4b3daca75b2263076fdda9f2dde8 t/curies.t SHA1 92c86c92a4e6a827b38b595b3636ca088451ea56 t/deprecation.t SHA1 7298689f99e7fd75b8106ce89fbb3c39e2aad73a t/double.t SHA1 38a4b359fccf0203e4c3b02cd095b93cded14121 t/example.json SHA1 b8dd154a00af9a2aee799ee6ff13bc30d5c8fecf t/example1.json SHA1 72b9e9a45fbbafa78f5e5bbc02bff7eb77faed0d t/example2.json SHA1 8f0d0fdec24bae09e2bc08da8e0ee56d969b633f t/example3.json SHA1 f0449ba681a10499d03dfa78b6f22515ba453d26 t/example4.json SHA1 794d4f1c7798b01dfe238852a86b7464954223c9 t/exampleWithArray.json SHA1 ddab26e6c23b941073cd825073270b723fa43abc t/exampleWithLiteralNullProperty.json SHA1 69337af80b63145dd80023e9b317e8c3ab0fb5a8 t/exampleWithMultipleNestedSubresources.json SHA1 abb4ef6b596e0bd16d764c7a5e4a61d71ab5a4c7 t/exampleWithMultipleSubresources.json SHA1 c337677f8142ac73ac8911e97527609dd0144b5a t/exampleWithNullProperty.json SHA1 f0eac9579aeffe3e2f37cdb5f38d00ca73a89d91 t/exampleWithSubresource.json SHA1 5e32f0492adfcad2dd7fd1207e737d2b306de7a8 t/exampleWithSubresourceLinkingToItself.json SHA1 020cdb4111df3d4cfafba112296f30e76d09549b t/exampleWithTemplate.json SHA1 30794dfb518ff4008b544f6b20aa1a0f4a7a118f t/exampleWithUnderscoredProperty.json SHA1 26258edc80b74473f58b6ebda41448bb3cc96fdc t/exampleWithoutHref.json SHA1 8f3b8ef4ee1eea63b21fc271e780022885f9cf60 t/headers.t SHA1 4fcca67f2960f002c8b0ca7a98e766132adca6e5 t/invalid.t SHA1 1f687ec41f30d65cb99c855e9a01101c04a58dc6 t/profile.t SHA1 f758b35a5052db598fc723d2791800979e0dacee t/round-trip.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBCgAGBQJSXSK5AAoJEO5ZBCSkxNcgLkEQALXiv40U9ZPjcUgMc6NoKjg8 jhNude1viqoT0OAYzkA0Xu4UD1a3dGbSqEolYVkXUgAsMPosy0PSG6Eo6mqtUqXd lFnpys9UhU5iseet1WUt7g8KDa7E+MSx1mH79+4sbmvNJm8mnryyID1wnOj1oQzq 5EWflhjAsup4SDAQHONh7QdopO+li7iYlyNzKPLsPebRM1YtGH2S+3YJcPEKhPmu ylTvsdaLltLcB+jjkIaI9TuxCL33tl0DU3iszc6X6jnYZXI/lcBabKvu+vSxV2dc azW3nqv+dFpqTKS2/n7WW6eP7OJrbxDS3zoNyIX4Aq9FbIg5Lg9I6OVf9jkETpdQ zXv9C7Y/y2aBxrNpBEHK/YPuwgTYjdbq+87dfrIycJtYGR356Yd95SLi5HlF9iLK ptCUrrARShmJUuTbXwP81z1B2LByGrCeKyh3Pei12XLBOmrCMfJUn66o9i2DEtJ3 ULk7ogAKDnN0CLbRXWmUklT0PAtkKf+5GMQynyW4N595iIm+JmFapRDRnNN7Dbgo JxY0PhPufSW++q79vgrHEEPt4mgjdqQIt5rovimWLr3Sz5tK1fTUrB615B9/wIuW mnrABZzfbczf4fCRY5GbZxYDomTR3EBN57PtpJEazBf3WEKVepzusSAuWYGN7Knz I+muOiXjZxtE39COWWp6 =t6Sb -----END PGP SIGNATURE----- libdata-hal-perl-1.000/lib/000077500000000000000000000000001222725563100153675ustar00rootroot00000000000000libdata-hal-perl-1.000/lib/Data/000077500000000000000000000000001222725563100162405ustar00rootroot00000000000000libdata-hal-perl-1.000/lib/Data/HAL.pm000066400000000000000000000277771222725563100172260ustar00rootroot00000000000000package Data::HAL; use strictures; use boolean qw(false true); use Clone qw(clone); use Data::HAL::Link qw(); use Data::HAL::URI qw(); use Data::HAL::URI::NamespaceMap qw(); use Data::Visitor::Callback qw(); use failures qw(Data::HAL::InvalidJSON); use HTTP::Headers::Util qw(join_header_words); use JSON qw(); use Moo; # has use Safe::Isa qw($_isa); use Scalar::Util qw(reftype); use Types::Standard qw(ArrayRef Bool HashRef InstanceOf Str); our $VERSION = '1.000'; my $uri_from_str = sub { my ($val) = @_; return $val->$_isa('Data::HAL::URI') ? $val : Data::HAL::URI->new($val); }; has('embedded', is => 'rw', isa => ArrayRef[InstanceOf['Data::HAL']]); has('links', is => 'rw', isa => ArrayRef[InstanceOf['Data::HAL::Link']]); has('resource', is => 'rw', isa => HashRef, default => sub {return {};}); has('relation', is => 'rw', isa => InstanceOf['Data::HAL::URI'], coerce => $uri_from_str); has('_nsmap', is => 'rw', isa => InstanceOf['Data::HAL::URI::NamespaceMap']); has('_recursing', is => 'ro', isa => Bool); sub BUILD { my ($self) = @_; $self->_expand_curies unless $self->_recursing; return; } sub from_json { my ($self, $json, $relation) = @_; my $nested = clone JSON::from_json($json); failure::Data::HAL::InvalidJSON->throw('not a JSON object') unless reftype $nested eq reftype {}; return $self->_from_nested($self->_boolify($nested), $relation)->_expand_curies; } sub _boolify { my ($self, $nested) = @_; my $visited = Data::Visitor::Callback->new( object => sub { my (undef, $val) = @_; if (JSON::is_bool($val)) { $val = false if $val == JSON::false; $val = true if $val == JSON::true; } return $val; } )->visit($nested); return $visited; } sub _from_nested { my ($class, $nested, $relation, $_recursing) = @_; my $embedded = delete $nested->{_embedded}; my $links = delete $nested->{_links}; my $self = $class->new( $relation ? (relation => $relation) : (), resource => $nested, $_recursing ? (_recursing => $_recursing) : (), ); if ($embedded) { $self->embedded([]); for my $k (keys %{ $embedded }) { push @{ $self->embedded }, (reftype $embedded->{$k} eq reftype []) ? map { $self->_from_nested($_, $k, 1) } @{ $embedded->{$k} } : $self->_from_nested($embedded->{$k}, $k, 1); } } if ($links) { $self->links([]); for my $k (keys %{ $links }) { push @{ $self->links }, (reftype $links->{$k} eq reftype []) ? map { Data::HAL::Link->new(%{ $_ }, relation => $k) } @{ $links->{$k} } : Data::HAL::Link->new(%{ $links->{$k} }, relation => $k); } } return $self; } sub _expand_curies { my ($self) = @_; my $nsmap = Data::HAL::URI::NamespaceMap->new; if ($self->links) { for my $l (@{ $self->links }) { if ('curies' eq $l->relation->as_string) { $nsmap->add_mapping($l->name, $l->href); } } } $self->_nsmap($nsmap); $self->_recurse_curies($self); return $self; } sub _recurse_curies { my ($self, $root) = @_; if ($self->relation) { my $uri = $root->_nsmap->uri($self->relation->as_string); if ($uri) { $self->relation(Data::HAL::URI->new( uri => $uri->uri, _original => $self->relation->_original, )); } } if ($self->links) { for my $l (@{ $self->links }) { my $uri = $root->_nsmap->uri($l->relation->as_string($root)); next unless $uri; $l->relation(Data::HAL::URI->new( uri => $uri->uri, _original => $l->relation->_original, )); } } if ($self->embedded) { for my $e (@{ $self->embedded }) { $e->_recurse_curies($root); } } return $self; } sub _to_nested { my ($self, $root) = @_; if ($self->relation) { $self->relation(Data::HAL::URI->new( uri => URI->new($self->relation->_original), _original => $self->relation->_original, )); } my $hal = clone $self->resource; for my $prop (qw(links embedded)) { if ($self->$prop) { for my $p (@{ $self->$prop }) { my ($nested, $r) = $p->_to_nested($root); if (exists $hal->{"_$prop"}{$r}) { if (reftype $hal->{"_$prop"}{$r} eq reftype []) { push @{ $hal->{"_$prop"}{$r} }, $nested; } else { my $attr = delete $hal->{"_$prop"}{$r}; push @{ $hal->{"_$prop"}{$r} }, $attr, $nested; } } else { $hal->{"_$prop"}{$r} = $nested; } } } } return($hal, $self->relation ? $self->relation->as_string : ()); } sub TO_JSON { my ($self) = @_; my ($nested) = $self->_to_nested($self); my $visited = Data::Visitor::Callback->new( boolean => sub { my (undef, $val) = @_; return $val ? JSON::true : JSON::false; } )->visit($nested); return $visited; } sub as_json { my ($self) = @_; return JSON::to_json($self->TO_JSON, { canonical => 1, pretty => 1, utf8 => 1 }); } sub http_headers { my ($self) = @_; my @headers; if ($self->links) { if (my ($profile_link) = grep { 'profile' eq $_->relation->as_string } @{ $self->links }) { push @headers, 'Content-Type' => join_header_words( 'application/hal+json' => undef, profile => $profile_link->href->as_string ); } else { push @headers, 'Content-Type' => 'application/hal+json'; } push @headers, map { (Link => $_->as_http_link_value) } grep { 'curies' ne $_->relation->as_string } @{ $self->links }; } return @headers; } 1; __END__ =encoding UTF-8 =head1 NAME Data::HAL - Hypertext Application Language resource =head1 VERSION This document describes Data::HAL version 1.000 =head1 SYNOPSIS use Data::HAL qw(); use Data::HAL::Link qw(); { my $hal = Data::HAL->from_json($json_str); my $resource_member_data_href = $hal->resource; my $links_aref = $hal->links; my $embedded_resources_aref = $hal->embedded; } { my $hal = Data::HAL->new( resource => {foo => 23, bar => 42}, links => [Data::HAL::Link->new(relation => 'self', href => '/')], ); my $json_str = $hal->as_json; # { # "_links" : { # "self" : { # "href" : "/" # } # }, # "bar" : 42, # "foo" : 23 # } my @headers = $hal->http_headers; # ( # 'Content-Type' => 'application/hal+json', # 'Link' => ';rel="self"' # ) } =head1 DESCRIPTION HAL is a format you can use in your hypermedia API. =head2 Introduction This section is completely quoted from the specification: There is an emergence of non-HTML HTTP applications ("Web APIs") which use hyperlinks to direct clients around their resources. The JSON Hypertext Application Language (HAL) is a standard which establishes conventions for expressing hypermedia controls, such as links, with JSON. HAL is a generic media type with which Web APIs can be developed and exposed as series of links. Clients of these APIs can select links by their link relation type and traverse them in order to progress through the application. HAL's conventions result in a uniform interface for serving and consuming hypermedia, enabling the creation of general-purpose libraries that can be re-used on any API utilising HAL. The primary design goals of HAL are generality and simplicity. HAL can be applied to many different domains, and imposes the minimal amount of structure necessary to cover the key requirements of a hypermedia Web API. =head2 Conformance The author claims to conform with L, published 2013-10-03. =head1 INTERFACE =head2 Composition None. =head2 Constructors =head3 C Data::HAL->from_json($json_str) Takes a HAL+JSON document as string and returns a C object. =head3 C Data::HAL->new( resource => {foo => 23, bar => 42}, links => [Data::HAL::Link->new(relation => 'self', href => '/')] ) Default L constructor, returns a C object. =head2 Attributes =head3 C Type C, L<< embedded resource objects|http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1.2 >> =head3 C Type C, L<< link objects|http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1.1 >> =head3 C Type C, member data L<< representing the current state of the resource|http://tools.ietf.org/html/draft-kelly-json-hal#section-4 >> =head3 C Type L, L<< identifier of the semantics of a link|http://tools.ietf.org/html/rfc5988#section-4 >> Perl strings are coerced to the L type. A stand-alone HAL+JSON document, when deserialised, will not have this attribute set in the root resource since nothing is linking to the document. =head2 Methods =head3 C Serialisation hook for the L (or compatible) module. This method is not intended to be called directly from your code. Instead call L or C<< JSON::to_json $hal, { convert_blessed => 1 } >> or similar. =head3 C Returns the resource object serialised as a HAL+JSON document string. =head3 C Returns a list of pairs of HTTP message headers. The keys are field name strings and the values are field content strings. B: since field names can repeat, assigning this list to a hash loses information. The list is suitable as input for e.g. the L<< C accessor in HTTP::Headers|HTTP::Headers/$h->header( $f1 => $v1, $f2 => $v2, ... ) >> or the L<< C attribute in Plack::Response|Plack::Response/headers >>. =head4 C The value is C, perhaps with a C parameter. =head4 C See L. =head2 Exports None. =head1 DIAGNOSTICS =head2 C The L constructor throws this exception of type C when the JSON input is a malformed HAL+JSON document. =head1 CONFIGURATION AND ENVIRONMENT Requires no configuration files or environment variables. =head1 DEPENDENCIES See meta file in the source distribution. =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS Please report any bugs or feature requests to C, or through the web interface at L. =head2 tight coupling to JSON It is currently difficult to exert control over the specifics of (de)serialisation, perhaps put the (de)serialisers into attributes? =head2 error type is an attribute, not a class name It is not worth it to design an error class hierarchy for a single error. =head2 Data::HAL::URI::NamespaceMap is undocumented It is used only internally. =head1 TO DO =over =item make everything cache-friendly =item non-standard accessors for link objects =item support §8.3. cache pattern =item support HAL XML =back =head1 SEE ALSO L, the more mature, featureful hypermedia protocol =head1 AUTHOR Lars Dɪᴇᴄᴋᴏᴡ C<< >> =head1 LICENCE AND COPYRIGHT Copyright © 2013 Lars Dɪᴇᴄᴋᴏᴡ C<< >> This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5.18.0. =head2 Disclaimer of warranty This library is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. libdata-hal-perl-1.000/lib/Data/HAL/000077500000000000000000000000001222725563100166445ustar00rootroot00000000000000libdata-hal-perl-1.000/lib/Data/HAL/Link.pm000066400000000000000000000122271222725563100201030ustar00rootroot00000000000000package Data::HAL::Link; use strictures; use boolean qw(false true); use Data::HAL::URI qw(); use HTTP::Headers::Util qw(join_header_words); use JSON qw(); use Log::Any qw($log); use MIME::Type qw(); use Moo; # has use Safe::Isa qw($_can $_isa); use Types::Standard qw(InstanceOf Str); our $VERSION = '1.000'; my $uri_from_str = sub { my ($val) = @_; return $val->$_isa('Data::HAL::URI') ? $val : Data::HAL::URI->new($val); }; my $boolean_from_perlbool = sub { my ($val) = @_; return $val ? true : false; }; has('relation', is => 'rw', isa => InstanceOf['Data::HAL::URI'], coerce => $uri_from_str, required => 1); has('href', is => 'rw', isa => InstanceOf['Data::HAL::URI'], coerce => $uri_from_str, required => 1); has('templated', is => 'rw', isa => InstanceOf['boolean'], coerce => $boolean_from_perlbool); has('type', is => 'rw', isa => InstanceOf['MIME::Type']); has('deprecation', is => 'rw', isa => InstanceOf['Data::HAL::URI'], coerce => $uri_from_str); has('name', is => 'rw', isa => Str); has('profile', is => 'rw', isa => InstanceOf['Data::HAL::URI'], coerce => $uri_from_str); has('title', is => 'rw', isa => Str); has('hreflang', is => 'rw', isa => Str); sub BUILD { my ($self) = @_; if ($self->deprecation) { $log->warn(sprintf 'The link (relation: "%s", href: "%s") is deprecated, see <%s>', $self->relation->as_string, $self->href->as_string, $self->deprecation->as_string); } return; } sub _to_nested { my ($self, $root) = @_; my $hal; for my $attr (map { $_->accessor } $self->meta->get_all_attributes) { my $val = $self->$attr; if (defined $val) { $hal->{$attr} = $val->$_can('as_string') ? $val->as_string($root) : $val; } } my $r = delete $hal->{relation}; return($hal, $r); } sub as_http_link_value { my ($self) = @_; return if 'curies' eq $self->relation->as_string; return join_header_words( '<'.$self->href->as_string.'>' => undef, rel => $self->relation->as_string, $self->hreflang ? (hreflang => $self->hreflang) : (), $self->title ? (title => $self->title) : (), $self->type ? (type => $self->type) : (), $self->name ? (name => $self->name) : (), $self->profile ? (profile => $self->profile->as_string) : (), ); } 1; __END__ =encoding UTF-8 =head1 NAME Data::HAL::Link - Hypertext Application Language link =head1 VERSION This document describes Data::HAL::Link version 1.000 =head1 SYNOPSIS map { +{ href => $_->href->uri->as_string, rel => $_->relation->uri->as_string } } @{ $resource->links } =head1 DESCRIPTION This section is completely quoted from the specification: A Link Object represents a hyperlink from the containing resource to a URI. =head1 INTERFACE =head2 Composition None. =head2 Constructors =head3 C When the L attribute is set, the constructor logs a L warning: C<< The link (relation: "%s", href: "%s") is deprecated, see <%s> >> You can consume it with a L of your choice, e.g. use Log::Any::Adapter 'Stderr'; Otherwise the constructor behaves like the default L constructor. Returns a C object. =head2 Attributes Perl strings are coerced to the L type in the attributes L, L, L, L. =head3 C Type L, B, L =head3 C Type L, B, L =head3 C Type L, L<< whether C is a URI template|http://tools.ietf.org/html/draft-kelly-json-hal#section-5.2 >> Perl boolean values are coerced to the L type. =head3 C Type L, L<< media type of the C resource|http://tools.ietf.org/html/draft-kelly-json-hal#section-5.3 >> =head3 C Type L, if existing L<< indicates the link is deprecated|http://tools.ietf.org/html/draft-kelly-json-hal#section-5.4 >> Setting the attribute triggers a log message in the constructor L. =head3 C Type C, L<< secondary key for selecting link objects which share the same relation type|http://tools.ietf.org/html/draft-kelly-json-hal#section-5.5 >> =head3 C Type L, L<< RFC 6906 profile of the target resource|http://tools.ietf.org/html/draft-kelly-json-hal#section-5.6 >> =head3 C Type C<Str>, L<< labels the link with a human-readable identifier|http://tools.ietf.org/html/draft-kelly-json-hal#section-5.7 >> =head3 C<hreflang> Type C<Str>, L<< indicates the language of the target resource|http://tools.ietf.org/html/draft-kelly-json-hal#section-5.8 >> =head2 Methods =head3 C<as_http_link_value> Returns the link as a L<< RFC 5988 C<link-value>|http://tools.ietf.org/html/rfc5988#section-5 >> string, e.g. C<< </orders?page=2>;rel="next" >>. =head2 Exports None. =head1 DIAGNOSTICS See L</new> constructor. =head1 CONFIGURATION AND ENVIRONMENT Requires no configuration files or environment variables. �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/lib/Data/HAL/URI.pm����������������������������������������������������������0000664�0000000�0000000�00000004332�12227255631�0017643�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������package Data::HAL::URI; use strictures; use Moo; # has use Types::Standard qw(InstanceOf Str); use URI qw(); our $VERSION = '1.000'; has('_original', is => 'rw', isa => Str); # just records what was passed to the constructor, this is a work-around for # URI->new being a lossy operation has( 'uri', is => 'ro', isa => InstanceOf['URI'], default => sub { my ($self) = @_; return URI->new($self->_original); }, handles => [qw(abs as_iri canonical clone eq fragment implementor new_abs opaque path rel scheme secure STORABLE_freeze STORABLE_thaw)], lazy => 1, required => 1, ); sub BUILDARGS { my (undef, @arg) = @_; return 1 == @arg ? {_original => $arg[0]} : {@arg}; } sub as_string { my ($self, $root) = @_; if ( $self->eq($self->_original) || $root && $root->_nsmap && $self->uri->eq($root->_nsmap->uri($self->_original)->as_string) ) { return $self->_original; } else { return $self->uri->as_string; } } 1; __END__ =encoding UTF-8 =head1 NAME Data::HAL::URI - URI wrapper =head1 VERSION This document describes Data::HAL::URI version 1.000 =head1 SYNOPSIS my $relation = $resource->relation->as_string; =head1 DESCRIPTION This is a wrapper for L<URI> objects. =head1 INTERFACE =head2 Composition None, but L<URI> methods are delegated through the L</uri> attribute. =head2 Constructors =head3 C<new> my $u = Data::HAL::URI->new('http://example.com/something'); Takes a string argument, returns a C<Data::HAL::URI> object. =head2 Attributes =head3 C<uri> Type C<URI>, B<required>, B<readonly>, can only be set from the L</new> constructor. This attribute delegates all methods to L<URI> except L</as_string>. =head2 Methods =head3 C<as_string> Returns the original argument to the constructor if still equal to the L</uri>, where equality also takes CURIE expansion into account, or otherwise the L</uri> as string. The unaltered behaviour is still available through the L</uri> accessor, e.g.: $resource->relation->uri->as_string =head2 Exports None. =head1 DIAGNOSTICS None. =head1 CONFIGURATION AND ENVIRONMENT Requires no configuration files or environment variables. ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/lib/Data/HAL/URI/������������������������������������������������������������0000775�0000000�0000000�00000000000�12227255631�0017303�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/lib/Data/HAL/URI/NamespaceMap.pm���������������������������������������������0000664�0000000�0000000�00000001303�12227255631�0022170�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������package Data::HAL::URI::NamespaceMap; use strictures; use Data::HAL::URI qw(); use Moo; # extends use URI::IRI qw(); use URI::Template qw(); use XML::RegExp qw(); extends 'URI::NamespaceMap'; our $VERSION = '1.000'; sub uri { my ($self, $abbr) = @_; if (my ($prefix, $reference) = $abbr =~ m/\A ($XML::RegExp::NCName) : (.*) \z/msx) { if ($self->namespace_uri($prefix)) { return Data::HAL::URI->new( _original => $abbr, uri => URI::Template ->new($self->namespace_uri($prefix)->as_string) ->process(rel => URI::IRI->new($reference)->canonical->as_string), ); } } return; } 1; �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/���������������������������������������������������������������������������0000775�0000000�0000000�00000000000�12227255631�0015064�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/00.load.t������������������������������������������������������������������0000664�0000000�0000000�00000000427�12227255631�0016411�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������use strictures; use Test::More import => [qw(diag done_testing use_ok)]; BEGIN { use_ok('Data::HAL'); use_ok('Data::HAL::Link'); use_ok('Data::HAL::URI'); use_ok('Data::HAL::URI::NamespaceMap'); } diag('Testing Data::HAL ' . Data::HAL->VERSION); done_testing; �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/curies.t�������������������������������������������������������������������0000664�0000000�0000000�00000001351�12227255631�0016543�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������use strictures; use Test::More import => [qw(done_testing is ok)]; use Data::HAL qw(); use File::Slurp qw(read_file); my $hal = Data::HAL->from_json(scalar read_file 't/exampleWithMultipleNestedSubresources.json'); my @expanded_curies = map { $_->relation->uri->as_string } @{ $hal->links }; ok grep { 'https://example.com/apidocs/ns/parent' eq $_ } @expanded_curies; ok grep { 'https://example.com/apidocs/ns/users' eq $_ } @expanded_curies; is $hal->embedded->[0]->relation->uri->as_string, 'https://example.com/apidocs/ns/user'; is $hal->embedded->[1]->relation->uri->as_string, 'https://example.com/apidocs/ns/user'; is $hal->embedded->[0]->embedded->[0]->relation->uri->as_string, 'https://example.com/apidocs/phone/cell'; done_testing; ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/deprecation.t��������������������������������������������������������������0000664�0000000�0000000�00000000752�12227255631�0017552�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������use strictures; use Data::HAL qw(); use File::Slurp qw(read_file); use Log::Any::Adapter qw(); use Log::Any::Adapter::FileHandle qw(); use Test::More import => [qw(done_testing is)]; my $log; open my $fh, '>', \$log; Log::Any::Adapter->set('FileHandle', fh => $fh); Data::HAL->from_json(scalar read_file 't/example3.json'); is $log, qq{[warning] The link (relation: "widgets", href: "/widgets") } . "is deprecated, see <http://example.com/blog/2013/09/no-more-widgets>\n"; done_testing; ����������������������libdata-hal-perl-1.000/t/double.t�������������������������������������������������������������������0000664�0000000�0000000�00000000417�12227255631�0016525�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������use strictures; use Test::More import => [qw(done_testing is)]; use Data::HAL qw(); use File::Slurp qw(read_file); my $hal = Data::HAL->from_json(scalar read_file 't/example.json'); my $json1 = $hal->as_json; my $json2 = $hal->as_json; is $json2, $json1; done_testing; �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/example.json���������������������������������������������������������������0000664�0000000�0000000�00000001270�12227255631�0017412�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links" : { "curies" : [ { "href" : "https://example.com/apidocs/ns/{rel}", "name" : "ns", "templated" : true }, { "href" : "https://example.com/apidocs/role/{rel}", "name" : "role", "templated" : true } ], "self" : { "href" : "https://example.com/api/customer/123456" }, "ns:parent" : { "href" : "https://example.com/api/customer/1234", "name" : "bob", "title" : "The Parent", "hreflang" : "en" }, "ns:users" : { "href" : "https://example.com/api/customer/123456?users" } }, "age" : 33, "expired" : false, "id" : 123456, "name" : "Example Resource", "optional" : true } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/example1.json��������������������������������������������������������������0000664�0000000�0000000�00000002103�12227255631�0017467�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links": { "self": { "href": "/orders" }, "next": { "href": "/orders?page=2" }, "find": { "href": "/orders{?id}", "templated": true }, "admin": [{ "href": "/admins/2", "title": "Fred" }, { "href": "/admins/5", "title": "Kate" }] }, "currentlyProcessing": 14, "shippedToday": 20, "_embedded": { "order": [{ "_links": { "self": { "href": "/orders/123" }, "basket": { "href": "/baskets/98712" }, "customer": { "href": "/customers/7809" } }, "total": 30.00, "currency": "USD", "status": "shipped" }, { "_links": { "self": { "href": "/orders/124" }, "basket": { "href": "/baskets/97213" }, "customer": { "href": "/customers/12369" } }, "total": 20.00, "currency": "USD", "status": "processing" }] } } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/example2.json��������������������������������������������������������������0000664�0000000�0000000�00000000407�12227255631�0017475�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links": { "self": { "href": "/orders" }, "curies": [{ "name": "acme", "href": "http://docs.acme.com/relations/{rel}", "templated": true }], "acme:widgets": { "href": "/widgets" } } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/example3.json��������������������������������������������������������������0000664�0000000�0000000�00000000255�12227255631�0017477�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links": { "self": { "href": "/orders" }, "widgets": { "href": "/widgets", "deprecation": "http://example.com/blog/2013/09/no-more-widgets" } } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/example4.json��������������������������������������������������������������0000664�0000000�0000000�00000000210�12227255631�0017467�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links": { "self": { "href": "/orders" }, "profile": { "href": "http://example.com/shop/documentation" } } } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithArray.json������������������������������������������������������0000664�0000000�0000000�00000000111�12227255631�0021236�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "array" : [ "one", "two", "three" ], "name" : "Example Resource" } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithLiteralNullProperty.json����������������������������������������0000664�0000000�0000000�00000001316�12227255631�0024164�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links" : { "curies" : [ { "href" : "https://example.com/apidocs/ns/{rel}", "name" : "ns", "templated" : true }, { "href" : "https://example.com/apidocs/role/{rel}", "name" : "role", "templated" : true } ], "self" : { "href" : "https://example.com/api/customer/123456" }, "ns:parent" : { "href" : "https://example.com/api/customer/1234", "name" : "bob", "title" : "The Parent", "hreflang" : "en" }, "ns:users" : { "href" : "https://example.com/api/customer/123456?users" } }, "age" : 33, "expired" : false, "id" : 123456, "name" : "Example Resource", "nullval" : "null", "optional" : true } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithMultipleNestedSubresources.json���������������������������������0000664�0000000�0000000�00000002662�12227255631�0025540�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links" : { "curies" : [ { "href" : "https://example.com/apidocs/ns/{rel}", "name" : "ns", "templated" : true }, { "href" : "https://example.com/apidocs/phone/{rel}", "name" : "phone", "templated" : true }, { "href" : "https://example.com/apidocs/role/{rel}", "name" : "role", "templated" : true } ], "self" : { "href" : "https://example.com/api/customer/123456" }, "ns:parent" : { "href" : "https://example.com/api/customer/1234", "name" : "bob", "title" : "The Parent", "hreflang" : "en" }, "ns:users" : { "href" : "https://example.com/api/customer/123456?users" } }, "_embedded" : { "ns:user" : [ { "_links" : { "self" : { "href" : "https://example.com/user/11" } }, "age" : 32, "expired" : false, "id" : 11, "name" : "Example User", "optional" : true, "_embedded" : { "phone:cell" : { "_links" : { "self" : { "href" : "https://example.com/phone/1" } }, "id" : 1, "number" : "555-666-7890" } } }, { "_links" : { "self" : { "href" : "https://example.com/user/12" } }, "age" : 32, "expired" : false, "id" : 12, "name" : "Example User", "optional" : true } ] } } ������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithMultipleSubresources.json���������������������������������������0000664�0000000�0000000�00000002106�12227255631�0024366�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links" : { "curies" : [ { "href" : "https://example.com/apidocs/ns/{rel}", "name" : "ns", "templated" : true }, { "href" : "https://example.com/apidocs/role/{rel}", "name" : "role", "templated" : true } ], "self" : { "href" : "https://example.com/api/customer/123456" }, "ns:parent" : { "href" : "https://example.com/api/customer/1234", "name" : "bob", "title" : "The Parent", "hreflang" : "en" }, "ns:users" : { "href" : "https://example.com/api/customer/123456?users" } }, "_embedded" : { "ns:user" : [ { "_links" : { "self" : { "href" : "https://example.com/user/11" } }, "age" : 32, "expired" : false, "id" : 11, "name" : "Example User", "optional" : true }, { "_links" : { "self" : { "href" : "https://example.com/user/12" } }, "age" : 32, "expired" : false, "id" : 12, "name" : "Example User", "optional" : true } ] } } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithNullProperty.json�����������������������������������������������0000664�0000000�0000000�00000001315�12227255631�0022646�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links" : { "curies" : [ { "href" : "https://example.com/apidocs/ns/{rel}", "name" : "ns", "templated" : true }, { "href" : "https://example.com/apidocs/role/{rel}", "name" : "role", "templated" : true } ], "self" : { "href" : "https://example.com/api/customer/123456" }, "ns:parent" : { "href" : "https://example.com/api/customer/1234", "name" : "bob", "title" : "The Parent", "hreflang" : "en" }, "ns:users" : { "href" : "https://example.com/api/customer/123456?users" } }, "age" : 33, "expired" : false, "id" : 123456, "name" : "Example Resource", "nullprop" : null, "optional" : true } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithSubresource.json������������������������������������������������0000664�0000000�0000000�00000001534�12227255631�0022473�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links" : { "curies" : [ { "href" : "https://example.com/apidocs/ns/{rel}", "name" : "ns", "templated" : true }, { "href" : "https://example.com/apidocs/role/{rel}", "name" : "role", "templated" : true } ], "self" : { "href" : "https://example.com/api/customer/123456" }, "ns:parent" : { "href" : "https://example.com/api/customer/1234", "name" : "bob", "title" : "The Parent", "hreflang" : "en" }, "ns:users" : { "href" : "https://example.com/api/customer/123456?users" } }, "_embedded" : { "ns:user" : { "_links" : { "self" : { "href" : "https://example.com/user/11" } }, "age" : 32, "expired" : false, "id" : 11, "name" : "Example User", "optional" : true } } } ��������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithSubresourceLinkingToItself.json���������������������������������0000664�0000000�0000000�00000001661�12227255631�0025462�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links" : { "curies" : [ { "href" : "https://example.com/apidocs/ns/{rel}", "name" : "ns", "templated" : true }, { "href" : "https://example.com/apidocs/role/{rel}", "name" : "role", "templated" : true } ], "self" : { "href" : "https://example.com/api/customer/123456" }, "ns:parent" : { "href" : "https://example.com/api/customer/1234", "name" : "bob", "title" : "The Parent", "hreflang" : "en" }, "ns:users" : { "href" : "https://example.com/api/customer/123456?users" } }, "_embedded" : { "ns:user" : { "_links" : { "self" : { "href" : "https://example.com/user/11" }, "role:admin" : { "href" : "https://example.com/user/11" } }, "age" : 32, "expired" : false, "id" : 11, "name" : "Example User", "optional" : true } } } �������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithTemplate.json���������������������������������������������������0000664�0000000�0000000�00000001152�12227255631�0021741�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links" : { "curies" : [ { "href" : "https://example.com/apidocs/ns/{rel}", "name" : "ns", "templated" : true }, { "href" : "https://example.com/apidocs/role/{rel}", "name" : "role", "templated" : true } ], "self" : { "href" : "https://example.com/api/customer" }, "ns:parent" : { "href" : "https://example.com/api/customer/1234", "name" : "bob", "title" : "The Parent", "hreflang" : "en" }, "ns:query" : { "href" : "https://example.com/api/customer/search{?queryParam}", "templated" : true } } } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithUnderscoredProperty.json����������������������������������������0000664�0000000�0000000�00000000205�12227255631�0024206�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "_links" : { "self" : { "href" : "https://example.com/api/customer/123456" } }, "_name" : "Example Resource" } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/exampleWithoutHref.json����������������������������������������������������0000664�0000000�0000000�00000000042�12227255631�0021577�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "name" : "Example Resource" } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/headers.t������������������������������������������������������������������0000664�0000000�0000000�00000001732�12227255631�0016667�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������use strictures; use Test::More import => [qw(done_testing is_deeply)]; use Data::HAL qw(); my $hal = Data::HAL->new( links => [ Data::HAL::Link->new(relation => 'self', href => 'http://example.com/a-resource'), Data::HAL::Link->new(relation => 'profile', href => 'http://example.com/docs'), Data::HAL::Link->new(relation => 'curies', name => 'example', href => 'http://example.com/rel#{rel}', templated => 1), Data::HAL::Link->new(relation => 'example:foo', href => '/a-foo-thing'), Data::HAL::Link->new(relation => 'example:bar', href => '/some-bar'), ], ); is_deeply [$hal->http_headers], [ 'Content-Type' => 'application/hal+json; profile="http://example.com/docs"', 'Link' => '<http://example.com/a-resource>; rel=self', 'Link' => '<http://example.com/docs>; rel=profile', 'Link' => '</a-foo-thing>; rel="http://example.com/rel#foo"', 'Link' => '</some-bar>; rel="http://example.com/rel#bar"', ]; done_testing; ��������������������������������������libdata-hal-perl-1.000/t/invalid.t������������������������������������������������������������������0000664�0000000�0000000�00000000332�12227255631�0016675�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������use strictures; use Data::HAL qw(); use Test::Fatal qw(exception); use Test::More import => [qw(done_testing isa_ok)]; isa_ok exception { Data::HAL->from_json('[]') }, 'failure::Data::HAL::InvalidJSON'; done_testing; ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/profile.t������������������������������������������������������������������0000664�0000000�0000000�00000000454�12227255631�0016714�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������use strictures; use Data::HAL qw(); use File::Slurp qw(read_file); use Test::More import => [qw(done_testing is)]; is {Data::HAL->from_json(scalar read_file 't/example4.json')->http_headers}->{'Content-Type'}, 'application/hal+json; profile="http://example.com/shop/documentation"'; done_testing; ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������libdata-hal-perl-1.000/t/round-trip.t���������������������������������������������������������������0000664�0000000�0000000�00000001344�12227255631�0017356�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������use strictures; use Test::More import => [qw(done_testing is_deeply)]; use Data::HAL qw(); use Data::Visitor::Callback qw(); use File::Slurp qw(read_file); use JSON qw(); sub round_trip { my ($file_name, $json_in) = @_; my $json_out = Data::HAL->from_json($json_in)->as_json; my $in_unwrapped = Data::Visitor::Callback->new( array => sub { if (1 == @{ $_ }) { my ($inner) = @{ $_ }; return $inner; } return $_; } )->visit(JSON::from_json($json_in)); is_deeply JSON::from_json($json_out), $in_unwrapped, $file_name; } for my $file_name (sort glob 't/*.json') { round_trip($file_name, scalar read_file $file_name); } done_testing; ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������