Skip to content

Commit

Permalink
added a few JSONPointer examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 18, 2012
1 parent b91e550 commit 556c3e0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.46 2012-01-19 00:00:00
- Improved documentation.

2.45 2012-01-18 00:00:00
- Removed T-Shirt link.
- Fixed small caching bug in Mojolicious::Plugin::EPRenderer.
Expand Down
17 changes: 17 additions & 0 deletions lib/Mojo/JSON/Pointer.pm
Expand Up @@ -63,12 +63,29 @@ this module is EXPERIMENTAL and might change without warning!
Check if data structure contains a value that can be identified with the
given JSON Pointer.
# True
$p->contains({foo => 'bar', baz => [4, 5, 6]}, '/foo');
$p->contains({foo => 'bar', baz => [4, 5, 6]}, '/baz/2');
# False
$p->contains({foo => 'bar', baz => [4, 5, 6]}, '/bar');
$p->contains({foo => 'bar', baz => [4, 5, 6]}, '/baz/9');
=head2 C<get>
my $value = $p->get($data, '/foo/bar');
Extract value identified by the given JSON Pointer.
# "bar"
$p->get({foo => 'bar', baz => [4, 5, 6]}, '/foo');
# "4"
$p->get({foo => 'bar', baz => [4, 5, 6]}, '/baz/0');
# "6"
$p->get({foo => 'bar', baz => [4, 5, 6]}, '/baz/2');
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Path.pm
Expand Up @@ -168,7 +168,7 @@ Construct a new L<Mojo::Path> object.
Canonicalize path.
# "/foo/baz"
say Mojo::Path->new('/foo/bar/../baz')->canonicalize;
Mojo::Path->new('/foo/bar/../baz')->canonicalize;
=head2 C<clone>
Expand Down
16 changes: 8 additions & 8 deletions lib/Mojo/URL.pm
Expand Up @@ -403,7 +403,7 @@ Clone this URL.
Host part of this URL in punycode format.
# "xn--da5b0n.net"
say Mojo::URL->new('http://☃.net')->ihost;
Mojo::URL->new('http://☃.net')->ihost;
=head2 C<is_abs>
Expand All @@ -428,10 +428,10 @@ Path part of this URL, relative paths will be appended to the existing path,
defaults to a L<Mojo::Path> object.
# "http://mojolicio.us/Mojo/DOM"
say Mojo::URL->new('http://mojolicio.us/perldoc')->path('/Mojo/DOM');
Mojo::URL->new('http://mojolicio.us/perldoc')->path('/Mojo/DOM');
# "http://mojolicio.us/perldoc/Mojo/DOM"
say Mojo::URL->new('http://mojolicio.us/perldoc')->path('Mojo/DOM');
Mojo::URL->new('http://mojolicio.us/perldoc')->path('Mojo/DOM');
=head2 C<query>
Expand All @@ -444,19 +444,19 @@ defaults to a L<Mojo::Path> object.
Query part of this URL, defaults to a L<Mojo::Parameters> object.
# "2"
say Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query->param('b');
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query->param('b');
# "http://mojolicio.us?a=2&c=3"
say Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query(a => 2, c => 3);
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query(a => 2, c => 3);
# "http://mojolicio.us?a=2&b=2&c=3"
say Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query([a => 2, c => 3]);
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query([a => 2, c => 3]);
# "http://mojolicio.us?b=2"
say Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query([a => undef]);
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query([a => undef]);
# "http://mojolicio.us?a=1&b=2&a=2&c=3"
say Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query({a => 2, c => 3});
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query({a => 2, c => 3});
=head2 C<to_abs>
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -32,7 +32,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.45';
our $VERSION = '2.46';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down

0 comments on commit 556c3e0

Please sign in to comment.