[libcatalyst-view-json-perl] 01/06: Imported Upstream version 0.36

Lucas Kanashiro kanashiro.duarte at gmail.com
Fri Nov 27 01:50:39 UTC 2015


This is an automated email from the git hooks/post-receive script.

kanashiro-guest pushed a commit to branch master
in repository libcatalyst-view-json-perl.

commit a32801b7b4773bb4fe4480a421b573fab7fef343
Author: Lucas Kanashiro <kanashiro.duarte at gmail.com>
Date:   Thu Nov 26 23:03:22 2015 -0200

    Imported Upstream version 0.36
---
 Changes                          |  9 ++++
 META.yml                         |  4 +-
 MYMETA.json                      |  5 ++-
 MYMETA.yml                       |  5 ++-
 inc/Module/Install.pm            |  2 +-
 inc/Module/Install/Base.pm       |  2 +-
 inc/Module/Install/Can.pm        |  2 +-
 inc/Module/Install/Fetch.pm      |  2 +-
 inc/Module/Install/Makefile.pm   |  2 +-
 inc/Module/Install/Metadata.pm   |  2 +-
 inc/Module/Install/Win32.pm      |  2 +-
 inc/Module/Install/WriteAll.pm   |  2 +-
 lib/Catalyst/Helper/View/JSON.pm |  1 +
 lib/Catalyst/View/JSON.pm        | 89 ++++++++++++++++++++++++++++++----------
 t/01_server.t                    | 14 ++++++-
 t/lib/TestApp.pm                 |  1 +
 t/lib/TestApp/Controller/Root.pm | 15 +++++++
 17 files changed, 123 insertions(+), 36 deletions(-)

diff --git a/Changes b/Changes
index 76790b5..67a4dee 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,14 @@
 Revision history for Perl extension Catalyst::View::JSON
 
+0.36  Wed Nov 25  12:00:00 CT 2015
+        - POD updates, improved warning messages, strictness (andyjack++)
+        - Make the default BOM added for safari optional. Possible breaking
+          change, please file issues if this causes trouble.
+        - New render method to let you just get a JSON encoded version of
+          some data (Added to make compatible with the unofficial Catalyst
+          View API that has a render method).
+        -
+
 0.35  Wed Jan 07  12:00:00 CT 2014
         - Specify a version of JSON::MaybXS in the Makefile to close a test
           failure (test case requires version '1.003000' so we made that the
diff --git a/META.yml b/META.yml
index f36365a..0d87420 100644
--- a/META.yml
+++ b/META.yml
@@ -10,7 +10,7 @@ configure_requires:
   ExtUtils::MakeMaker: 6.59
 distribution_type: module
 dynamic_config: 1
-generated_by: 'Module::Install version 1.14'
+generated_by: 'Module::Install version 1.16'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -28,4 +28,4 @@ requires:
 resources:
   license: http://dev.perl.org/licenses/
   repository: git://github.com/perl-catalyst/Catalyst-View-JSON.git
-version: '0.35'
+version: '0.36'
diff --git a/MYMETA.json b/MYMETA.json
index 26c83a9..eac3b03 100644
--- a/MYMETA.json
+++ b/MYMETA.json
@@ -4,7 +4,7 @@
       "Tatsuhiko Miyagawa <miyagawa at bulknews.net>"
    ],
    "dynamic_config" : 0,
-   "generated_by" : "ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.143240",
+   "generated_by" : "ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005",
    "license" : [
       "perl_5"
    ],
@@ -42,5 +42,6 @@
       }
    },
    "release_status" : "stable",
-   "version" : "0.35"
+   "version" : "0.36",
+   "x_serialization_backend" : "JSON::PP version 2.27203"
 }
diff --git a/MYMETA.yml b/MYMETA.yml
index f56abdd..b3eafb3 100644
--- a/MYMETA.yml
+++ b/MYMETA.yml
@@ -9,7 +9,7 @@ build_requires:
 configure_requires:
   ExtUtils::MakeMaker: '0'
 dynamic_config: 0
-generated_by: 'ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.143240'
+generated_by: 'ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -24,4 +24,5 @@ requires:
   JSON::MaybeXS: '1.003000'
   MRO::Compat: '0'
   perl: '5.008001'
-version: '0.35'
+version: '0.36'
+x_serialization_backend: 'CPAN::Meta::YAML version 0.012'
diff --git a/inc/Module/Install.pm b/inc/Module/Install.pm
index ff767fa..f44ab4d 100644
--- a/inc/Module/Install.pm
+++ b/inc/Module/Install.pm
@@ -31,7 +31,7 @@ BEGIN {
 	# This is not enforced yet, but will be some time in the next few
 	# releases once we can make sure it won't clash with custom
 	# Module::Install extensions.
-	$VERSION = '1.14';
+	$VERSION = '1.16';
 
 	# Storage for the pseudo-singleton
 	$MAIN    = undef;
diff --git a/inc/Module/Install/Base.pm b/inc/Module/Install/Base.pm
index 4206347..5762a74 100644
--- a/inc/Module/Install/Base.pm
+++ b/inc/Module/Install/Base.pm
@@ -4,7 +4,7 @@ package Module::Install::Base;
 use strict 'vars';
 use vars qw{$VERSION};
 BEGIN {
-	$VERSION = '1.14';
+	$VERSION = '1.16';
 }
 
 # Suspend handler for "redefined" warnings
diff --git a/inc/Module/Install/Can.pm b/inc/Module/Install/Can.pm
index 9929b1b..d859276 100644
--- a/inc/Module/Install/Can.pm
+++ b/inc/Module/Install/Can.pm
@@ -8,7 +8,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.14';
+	$VERSION = '1.16';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Fetch.pm b/inc/Module/Install/Fetch.pm
index 3d8de76..41d3517 100644
--- a/inc/Module/Install/Fetch.pm
+++ b/inc/Module/Install/Fetch.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.14';
+	$VERSION = '1.16';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Makefile.pm b/inc/Module/Install/Makefile.pm
index 66993af..e9918d2 100644
--- a/inc/Module/Install/Makefile.pm
+++ b/inc/Module/Install/Makefile.pm
@@ -8,7 +8,7 @@ use Fcntl qw/:flock :seek/;
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.14';
+	$VERSION = '1.16';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Metadata.pm b/inc/Module/Install/Metadata.pm
index e547fa0..9792685 100644
--- a/inc/Module/Install/Metadata.pm
+++ b/inc/Module/Install/Metadata.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.14';
+	$VERSION = '1.16';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Win32.pm b/inc/Module/Install/Win32.pm
index 9706e5f..218a66b 100644
--- a/inc/Module/Install/Win32.pm
+++ b/inc/Module/Install/Win32.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.14';
+	$VERSION = '1.16';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/WriteAll.pm b/inc/Module/Install/WriteAll.pm
index dbedc00..530749b 100644
--- a/inc/Module/Install/WriteAll.pm
+++ b/inc/Module/Install/WriteAll.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.14';
+	$VERSION = '1.16';
 	@ISA     = qw{Module::Install::Base};
 	$ISCORE  = 1;
 }
diff --git a/lib/Catalyst/Helper/View/JSON.pm b/lib/Catalyst/Helper/View/JSON.pm
index 68b82ea..ae01df9 100644
--- a/lib/Catalyst/Helper/View/JSON.pm
+++ b/lib/Catalyst/Helper/View/JSON.pm
@@ -1,6 +1,7 @@
 package Catalyst::Helper::View::JSON;
 
 use strict;
+use warnings;
 
 =head1 NAME
 
diff --git a/lib/Catalyst/View/JSON.pm b/lib/Catalyst/View/JSON.pm
index 9ec286c..1e47fd4 100644
--- a/lib/Catalyst/View/JSON.pm
+++ b/lib/Catalyst/View/JSON.pm
@@ -1,7 +1,8 @@
 package Catalyst::View::JSON;
 
 use strict;
-our $VERSION = '0.35';
+use warnings;
+our $VERSION = '0.36';
 use 5.008_001;
 
 use base qw( Catalyst::View );
@@ -9,7 +10,10 @@ use Encode ();
 use MRO::Compat;
 use Catalyst::Exception;
 
-__PACKAGE__->mk_accessors(qw( allow_callback callback_param expose_stash encoding json_dumper no_x_json_header json_encoder_args ));
+__PACKAGE__->mk_accessors(qw(
+  allow_callback callback_param expose_stash
+  encoding json_dumper no_x_json_header json_encoder_args
+  use_force_bom));
 
 sub new {
     my($class, $c, $arguments) = @_;
@@ -30,12 +34,6 @@ sub new {
         }
     }
 
-    my $method = $self->can('encode_json');
-    $self->json_dumper( sub {
-                            my($data, $self, $c) = @_;
-                            $method->($self, $c, $data);
-                        } );
-
     if (my $method = $self->can('encode_json')) {
         $self->json_dumper( sub {
                                 my($data, $self, $c) = @_;
@@ -67,7 +65,8 @@ sub process {
         } elsif (!ref($expose)) {
             $single_key = $expose;
         } else {
-            $c->log->warn("expose_stash should be an array referernce or Regexp object.");
+            $c->log->warn("expose_stash should be an array reference, Regexp object, or key for a single stash entry.");
+            $c->log->warn("Returning all stash entries");
         }
     }
 
@@ -84,8 +83,6 @@ sub process {
     my $cb = $cb_param ? $c->req->param($cb_param) : undef;
     $self->validate_callback_param($cb) if $cb;
 
-    my $json = $self->json_dumper->($data, $self, $c); # weird order to be backward compat
-
     # When you set encoding option in View::JSON, this plugin DWIMs
     my $encoding = $self->encoding || 'utf-8';
 
@@ -95,12 +92,13 @@ sub process {
         $c->res->header('X-JSON' => 'eval("("+this.transport.responseText+")")');
     }
 
+    my $json = $self->render($c, $data);
     my $output;
 
-    ## add UTF-8 BOM if the client is Safari
-    if ($encoding eq 'utf-8') {
+    ## add UTF-8 BOM if the client meets a test and the application wants it.
+    if ($self->use_force_bom && $encoding eq 'utf-8') {
         my $user_agent = $c->req->user_agent || '';
-        if ($user_agent =~ m/\bSafari\b/ and $user_agent !~ m/\bChrome\b/) {
+        if ($self->user_agent_bom_test($user_agent)) {
             $output = "\xEF\xBB\xBF";
         }
     }
@@ -112,6 +110,23 @@ sub process {
     $c->res->output($output);
 }
 
+# allow for called as $c, $template, $data || $c, $data so that we are compatible
+# with the semi standard render method that a lot of views use.
+
+sub render {
+    my $self = shift;
+    my $c = shift;
+    my $data = pop;
+
+    return $self->json_dumper->($data, $self, $c); # weird order to be backward compat
+}
+
+sub user_agent_bom_test {
+    my ($self, $user_agent) = @_;
+    return(($user_agent =~ m/\bSafari\b/) and ($user_agent !~ m/\bChrome\b/));
+}
+
+
 sub validate_callback_param {
     my($self, $param) = @_;
     $param =~ /^[a-zA-Z0-9\.\_\[\]]+$/
@@ -184,7 +199,7 @@ exposed as a JSON response. Defaults to everything. Examples configuration:
 Suppose you have data structure of the following.
 
   $c->stash->{foo} = [ 1, 2 ];
-  $c->stash->{bar} = [ 3, 4 ];
+  $c->stash->{bar} = 2;
 
 By default, this view will return:
 
@@ -215,8 +230,37 @@ behavior so that you can do eval() by your own. Defaults to 0.
 An optional hashref that supplies arguments to L<JSON::MaybeXS> used when creating
 a new object.
 
+=item use_force_bom
+
+If versions of this view older than 0.36, there was some code that added a UTF-8 BOM
+marker to the end of the JSON string when the user agent was Safari.  After looking
+at a lot of existing code I don't think this is needed anymore so we removed it by
+default.  However if this turns out to be a problem you can re enable it by setting
+this attribute to true.  Possible a breaking change so we offer this workaround.
+
+You may also override the method 'user_agent_bom_test' which received the current
+request user agent string to try and better determine if this is needed.  Patches
+for this welcomed.
+
 =back
 
+=head1 METHODS
+
+=head2 process
+
+Standard target of $c->forward used to prepare a response
+
+=head2 render
+
+The methods accepts either of the following argument signatures in order to promote
+compatibility with the semi standard render method as define in numerous L<Catalyst>
+views on CPAN:
+
+    my $json_string = $c->view('JSON')->render($c, undef, $data);
+    my $json_string = $c->view('JSON')->render($c, $data);
+
+Given '$data' returns the JSON serialized version, or throws and error.
+
 =head1 OVERRIDING JSON ENCODER
 
 By default it uses L<JSON::MaybeXS::encode_json> to serialize perl data structure into
@@ -261,7 +305,7 @@ this default via the C<json_encoder_args>:
     MyApp::View::JSON->config(
       json_encoder_args => +{utf8=>0} );
 
-B<NOTE>In 2015 the use of UTF8 as encoding is widely standard so it
+B<NOTE> In 2015 the use of UTF8 as encoding is widely standard so it
 is very likely you should need to do nothing to get the correct
 encoding.  The following documention will remain for historical
 value and backcompat needs.
@@ -331,6 +375,9 @@ See L<http://developer.yahoo.net/common/json.html> and
 L<http://ajaxian.com/archives/jsonp-json-with-padding> for more about
 JSONP.
 
+B<NOTE> For another way to enable JSONP in your application take a look
+at L<Plack::Middleware::JSONP>
+
 =head1 INTEROPERABILITY
 
 JSON use is still developing and has not been standardized. This
@@ -436,11 +483,11 @@ it under the same terms as Perl itself.
 Following people has been contributing patches, bug reports and
 suggestions for the improvement of Catalyst::View::JSON.
 
-John Wang
-kazeburo
-Daisuke Murase
-Jun Kuriyama
-Tomas Doran
+  John Wang
+  kazeburo
+  Daisuke Murase
+  Jun Kuriyama
+  Tomas Doran
 
 =head1 SEE ALSO
 
diff --git a/t/01_server.t b/t/01_server.t
index 5e92c08..8ab6772 100644
--- a/t/01_server.t
+++ b/t/01_server.t
@@ -9,7 +9,7 @@ use Test::More;
 use Catalyst::Test 'TestApp';
 use JSON::MaybeXS 1.003000 ':legacy';
 
-plan tests => 40;
+plan tests => 47;
 
 BEGIN {
     no warnings 'redefine';
@@ -154,4 +154,16 @@ my $entrypoint = "http://localhost/foo";
     is $data->{foo}, "fake";
 }
 
+{
+    my $request = HTTP::Request->new( GET => "http://localhost/warnmsg" );
+
+    ok( my $response = request($request), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->code, 200, 'Response Code' );
+    is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] );
 
+    my $data = from_json($response->content);
+    is $data->{json_foo}, "bar";
+    is_deeply $data->{json_baz}, [ 1, 2, 3 ];
+    is $data->{'foo'}, 'barbarbar';
+}
diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm
index ff412ff..5d7949c 100644
--- a/t/lib/TestApp.pm
+++ b/t/lib/TestApp.pm
@@ -11,6 +11,7 @@ __PACKAGE__->config({
     name => 'TestApp',
     disable_component_resolution_regex_fallback => 1,
     'View::JSON' => {
+        use_force_bom => 1,
         expose_stash => qr/^json_/,
         allow_callback => 1,
         callback_param => 'cb',
diff --git a/t/lib/TestApp/Controller/Root.pm b/t/lib/TestApp/Controller/Root.pm
index 8920fb3..8a9ae6f 100644
--- a/t/lib/TestApp/Controller/Root.pm
+++ b/t/lib/TestApp/Controller/Root.pm
@@ -18,6 +18,21 @@ sub foo : Global {
     $c->forward('View::JSON');
 }
 
+sub warnmsg : Global {
+    my ( $self, $c ) = @_;
+
+    # case where setting expose_stash returns everything in
+    # the stash.  Set a true value to enter to code path
+    # that shows the warning message.
+    $c->component('View::JSON')->expose_stash(\1);
+    $c->stash->{json_foo} = "bar";
+    $c->stash->{json_baz} = [ 1, 2, 3 ];
+    $c->stash->{foo}      = "barbarbar";
+
+    $c->forward('View::JSON');
+}
+
+
 sub foo2 : Global {
     my( $self, $c ) = @_;
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatalyst-view-json-perl.git



More information about the Pkg-perl-cvs-commits mailing list