[Catalyst-commits] r14374 - in CatalystX-CRUD/CatalystX-CRUD/trunk:
. lib/CatalystX lib/CatalystX/CRUD
lib/CatalystX/CRUD/Iterator lib/CatalystX/CRUD/Model
lib/CatalystX/CRUD/ModelAdapter lib/CatalystX/CRUD/Object
lib/CatalystX/CRUD/Test
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Fri Nov 2 04:05:43 GMT 2012
Author: karpet
Date: 2012-11-02 04:05:43 +0000 (Fri, 02 Nov 2012)
New Revision: 14374
Modified:
CatalystX-CRUD/CatalystX-CRUD/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm
Log:
add Results->serialize()
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/Changes 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/Changes 2012-11-02 04:05:43 UTC (rev 14374)
@@ -254,3 +254,5 @@
0.53 31 Oct 2012
* add list_related and view_related primarily for REST support
+0.54 xxx
+ * add Results->serialize() method
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -37,7 +37,7 @@
naked_results => 0,
);
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -3,7 +3,7 @@
use warnings;
use Carp;
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -4,7 +4,7 @@
use Carp;
use base qw( CatalystX::CRUD );
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -10,7 +10,7 @@
__PACKAGE__->mk_accessors(qw( inc_path ));
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
# test whether symlink() works at compile time
my $SYMLINK_SUPPORTED = eval { symlink( "", "" ); 1 };
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -9,7 +9,7 @@
__PACKAGE__->mk_accessors(qw( use_ilike ne_sign ));
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -9,7 +9,7 @@
Catalyst::Model
);
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
__PACKAGE__->mk_accessors(qw( object_class page_size ));
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -3,7 +3,7 @@
use warnings;
use base qw( CatalystX::CRUD::ModelAdapter );
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -13,7 +13,7 @@
__PACKAGE__->mk_accessors(qw( content file ));
__PACKAGE__->delegate_class('Path::Class::File');
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -12,7 +12,7 @@
__PACKAGE__->mk_ro_accessors(qw( delegate ));
__PACKAGE__->mk_classdata('delegate_class');
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -10,7 +10,7 @@
__PACKAGE__->mk_accessors(qw( enable_rpc_compat ));
__PACKAGE__->config( enable_rpc_compat => 0 );
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
#warn "REST VERSION = $VERSION";
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -3,12 +3,18 @@
use warnings;
use base qw( Class::Accessor::Fast );
use Carp;
+use Scalar::Util qw( blessed );
+use Data::Dump qw( dump );
use MRO::Compat;
use mro 'c3';
+use overload
+ '""' => sub { return dump( $_[0]->serialize ) . ""; },
+ 'bool' => sub {1},
+ fallback => 1;
__PACKAGE__->mk_ro_accessors(qw( count pager query results ));
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
@@ -72,6 +78,70 @@
}
}
+=head2 TO_JSON
+
+Hook for the L<JSON> module so that you can pass a Results object
+directly to encode_json(). Calls serialize() internally.
+
+=cut
+
+sub TO_JSON {
+ my $self = shift;
+ return $self->serialize();
+}
+
+=head2 serialize
+
+Returns object as a hash ref. Objects are overloaded to call
+Data::Dump::dump( $results->serialize ) in string context.
+
+=cut
+
+sub serialize {
+ my $self = shift;
+
+ #dump $self;
+ my $r = { count => $self->count };
+
+ # what might query be?
+ my $q = $self->query;
+ if ( blessed($q) ) {
+ $r->{query} = "$q";
+ }
+ elsif ( ref $q eq 'CODE' ) {
+ $r->{query} = $q->();
+ }
+ else {
+ $r->{query} = $q;
+ }
+
+ my @results;
+ if ( ref( $self->results ) eq 'ARRAY' ) {
+ @results = @{ $self->{results} };
+ }
+ else {
+ while ( my $i = $self->results->next ) {
+ push @results, $i;
+ }
+ }
+
+ # serialize results
+ my @serialized;
+ for my $i (@results) {
+ my $s;
+ if ( blessed($i) and $i->can('serialize') ) {
+ $s = $i->serialize;
+ }
+ else {
+ $s = "$i";
+ }
+ push @serialized, $s;
+ }
+ $r->{results} = \@serialized;
+
+ return $r;
+}
+
1;
__END__
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -8,7 +8,7 @@
__PACKAGE__->mk_accessors( qw( form_fields ) );
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -7,7 +7,7 @@
__PACKAGE__->mk_accessors(qw( params fields ));
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm 2012-10-31 20:22:10 UTC (rev 14373)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm 2012-11-02 04:05:43 UTC (rev 14374)
@@ -4,7 +4,7 @@
use strict;
use Carp;
-our $VERSION = '0.53';
+our $VERSION = '0.53_01';
=head1 NAME
More information about the Catalyst-commits
mailing list