[Catalyst-commits] r7488 - in CatalystX-CRUD:
CatalystX-CRUD-Model-DBIC CatalystX-CRUD-Model-DBIC/trunk
CatalystX-CRUD-Model-DBIC/trunk/lib
CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX
CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD
CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Model
CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Object
CatalystX-CRUD-Model-DBIC/trunk/t
CatalystX-CRUD-Model-DBIC/trunk/t/MyDB
CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main
CatalystX-CRUD-Model-DBIC/trunk/t/lib
CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp
CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp/Model
CatalystX-CRUD-View-Excel CatalystX-CRUD-View-Excel/trunk
CatalystX-CRUD-View-Excel/trunk/lib
CatalystX-CRUD-View-Excel/trunk/lib/CatalystX
CatalystX-CRUD-View-Excel/trunk/lib/CatalystX/CRUD
CatalystX-CRUD-View-Excel/trunk/lib/CatalystX/CRUD/View
CatalystX-CRUD-View-Excel/trunk/t
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Tue Mar 11 17:22:55 GMT 2008
Author: karpet
Date: 2008-03-11 17:22:53 +0000 (Tue, 11 Mar 2008)
New Revision: 7488
Added:
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/branches/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/MANIFEST
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/Makefile.PL
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/README
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Model/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Model/DBIC.pm
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Object/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Object/DBIC.pm
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/00-load.t
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/01-dbic.t
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main.pm
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Artist.pm
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Cd.pm
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Track.pm
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/boilerplate.t
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/example.sql
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/insertdb.pl
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp.pm
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp/Model/
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp/Model/Main.pm
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/pod-coverage.t
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/pod.t
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/test.pl
CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/testdb.pl
CatalystX-CRUD/CatalystX-CRUD-View-Excel/branches/
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/MANIFEST
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/Makefile.PL
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/README
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/lib/
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/lib/CatalystX/
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/lib/CatalystX/CRUD/
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/lib/CatalystX/CRUD/View/
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/lib/CatalystX/CRUD/View/Excel.pm
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/00-load.t
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/boilerplate.t
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/pod-coverage.t
CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/pod.t
Log:
import from peknet and msi
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/Changes (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/Changes 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,10 @@
+Revision history for CatalystX-CRUD-Model-DBIC
+
+0.01 20 Dec 2007
+ First version, released on an unsuspecting world.
+
+0.02 16 Jan 2008
+ * bump CXCRUD req version to include Sort::SQL and satisfy testers
+
+
+
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/MANIFEST
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/MANIFEST (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/MANIFEST 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,20 @@
+Changes
+MANIFEST
+Makefile.PL
+README
+lib/CatalystX/CRUD/Model/DBIC.pm
+t/00-load.t
+t/boilerplate.t
+t/pod-coverage.t
+t/pod.t
+lib/CatalystX/CRUD/Object/DBIC.pm
+t/01-dbic.t
+t/example.sql
+t/insertdb.pl
+t/lib/MyApp.pm
+t/lib/MyApp/Model/Main.pm
+t/MyDB/Main.pm
+t/MyDB/Main/Artist.pm
+t/MyDB/Main/Cd.pm
+t/MyDB/Main/Track.pm
+
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/Makefile.PL
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/Makefile.PL (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/Makefile.PL 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'CatalystX::CRUD::Model::DBIC',
+ AUTHOR => 'Peter Karman <karman at cpan.org>',
+ VERSION_FROM => 'lib/CatalystX/CRUD/Model/DBIC.pm',
+ ABSTRACT_FROM => 'lib/CatalystX/CRUD/Model/DBIC.pm',
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Test::More' => 0,
+ 'CatalystX::CRUD' => '0.22',
+ 'DBIx::Class' => 0,
+ 'Catalyst::Model::DBIC::Schema' => 0,
+
+
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'CatalystX-CRUD-Model-DBIC-*' },
+);
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/README
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/README (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/README 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,38 @@
+CatalystX-CRUD-Model-DBIC
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the perldoc command.
+
+ perldoc CatalystX::CRUD::Model::DBIC
+
+You can also look for information at:
+
+ Search CPAN
+ http://search.cpan.org/dist/CatalystX-CRUD-Model-DBIC
+
+ CPAN Request Tracker:
+ http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD-Model-DBIC
+
+ AnnoCPAN, annotated CPAN documentation:
+ http://annocpan.org/dist/CatalystX-CRUD-Model-DBIC
+
+ CPAN Ratings:
+ http://cpanratings.perl.org/d/CatalystX-CRUD-Model-DBIC
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2007 Peter Karman
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Model/DBIC.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Model/DBIC.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Model/DBIC.pm 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,240 @@
+package CatalystX::CRUD::Model::DBIC;
+use strict;
+use warnings;
+
+use CatalystX::CRUD::Iterator;
+
+# @INC order important!
+use base qw(
+ Catalyst::Model::DBIC::Schema
+ CatalystX::CRUD::Model
+ CatalystX::CRUD::Model::Utils
+);
+
+our $VERSION = '0.02';
+
+__PACKAGE__->mk_ro_accessors(qw( resultset_opts moniker ));
+__PACKAGE__->config->{object_class} = 'CatalystX::CRUD::Object::DBIC';
+
+=head1 NAME
+
+CatalystX::CRUD::Model::DBIC - DBIx::Class CRUD
+
+=head1 SYNOPSIS
+
+ package MyApp::Model::Foo;
+ use base qw( CatalystX::CRUD::Model::DBIC );
+ __PACKAGE__->config(
+ resultset_opts => {
+ join => [ 'bar' ],
+ prefetch => [ 'bar' ]
+ },
+ moniker => 'Foo',
+ schema_class => 'MyDB::Main',
+ connect_info =>
+ [ 'dbi:SQLite:' . MyApp->path_to('my_foo.db') ],
+ );
+
+ 1;
+
+=head1 DESCRIPTION
+
+CatalystX::CRUD::Model::DBIC is a CatalystX::CRUD implementation for DBIx::Class.
+See the CatalystX::CRUD documentation.
+
+=head1 METHODS
+
+Only new or overridden methods are documented here.
+
+=cut
+
+=head2 new
+
+Initialize the class at application start-up.
+
+We implement new() instead of Xsetup() because of idiosyncracies of NEXT.
+
+=cut
+
+sub new {
+ my ( $class, $c, $arg ) = @_;
+
+ my $self = $class->NEXT::new( $c, $arg );
+ $self->Xsetup( $c, $arg );
+
+ # SQL for not equal
+ $self->ne_sign('!=');
+
+ $self->{moniker} = $self->config->{moniker};
+ if ( !$self->moniker ) {
+ return if $self->throw_error("need to configure a moniker value");
+ }
+ return $self;
+}
+
+sub _get_field_names {
+ my $self = shift;
+ return $self->{_field_names} if $self->{_field_names};
+
+ my $obj = $self->composed_schema->source( $self->moniker );
+ my @cols = $obj->columns;
+ my @rels = $obj->relationships;
+
+ my @fields;
+ for my $rel (@rels) {
+ my $info = $obj->relationship_info($rel);
+ my $rel_class = $info->{source};
+ my @rel_cols = $rel_class->columns;
+ push( @fields, map { $rel . '.' . $_ } @rel_cols );
+ }
+ for my $col (@cols) {
+ push( @fields, 'me.' . $col );
+ }
+
+ $self->{_field_names} = \@fields;
+
+ return \@fields;
+}
+
+=head2 new_object( @params )
+
+Returns a new moniker() class object. @params are passed directly
+to the schema()'s new() method.
+
+=cut
+
+sub new_object {
+ my $self = shift;
+ return $self->schema->resultset( $self->moniker )->new(@_);
+}
+
+=head2 fetch( @params )
+
+ at params are passed directly to the find() method of schema().
+
+=cut
+
+sub fetch {
+ my $self = shift;
+ return $self->schema->resultset( $self->moniker )->find(@_);
+}
+
+=head2 make_query( I<\@field_names> )
+
+Create a query from the current request suitable for search(),
+count() or iterator().
+
+=cut
+
+sub make_query {
+ my $self = shift;
+ my $c = $self->context;
+ my $field_names = shift || $self->_get_field_names;
+
+ # TODO sort order and limit/offset support
+ # it's already in $q but need DBIC syntax
+
+ my @query;
+ my $q = $self->make_sql_query($field_names);
+
+ push( @query, { @{ $q->{query} } }, $self->resultset_opts )
+ if $self->resultset_opts;
+
+ return \@query;
+}
+
+=head2 search( I<query> )
+
+If not present, I<query> will default to the return value of make_query().
+
+Returns an array or arrayref of CatalystX::CRUD::Object::DBIC objects depending
+on context.
+
+=cut
+
+sub search {
+ my $self = shift;
+ my $query = shift || $self->make_query;
+ my $class = $self->object_class;
+ my @results = map { $class->new( delegate => $_ ) }
+ $self->schema->resultset( $self->moniker )->search(@$query);
+ return wantarray ? @results : \@results;
+}
+
+=head2 iterator( I<query> )
+
+If not present, I<query> will default to the return value of make_query().
+
+=cut
+
+sub iterator {
+ my $self = shift;
+ my $query = shift || $self->make_query;
+ my $rs = $self->schema->resultset( $self->moniker )->search(@$query);
+ return CatalystX::CRUD::Iterator->new( $rs, $self->object_class );
+}
+
+=head2 count( I<query> )
+
+If not present, I<query> will default to the return value of make_query().
+
+=cut
+
+sub count {
+ my $self = shift;
+ my $query = shift || $self->make_query;
+ return $self->schema->resultset( $self->moniker )->count(@$query);
+}
+
+=head1 AUTHOR
+
+Peter Karman, C<< <karman at cpan.org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-catalystx-crud-model-dbic at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD-Model-DBIC>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc CatalystX::CRUD::Model::DBIC
+
+You can also look for information at:
+
+=over 4
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/CatalystX-CRUD-Model-DBIC>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/CatalystX-CRUD-Model-DBIC>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD-Model-DBIC>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/CatalystX-CRUD-Model-DBIC>
+
+=back
+
+=head1 ACKNOWLEDGEMENTS
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 Peter Karman, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of CatalystX::CRUD::Model::DBIC
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Object/DBIC.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Object/DBIC.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/lib/CatalystX/CRUD/Object/DBIC.pm 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,123 @@
+package CatalystX::CRUD::Object::DBIC;
+use strict;
+use warnings;
+use base qw( CatalystX::CRUD::Object );
+
+our $VERSION = '0.02';
+
+=head1 NAME
+
+CatalystX::CRUD::Object::DBIC - DBIx::Class implementation of CatalystX::CRUD::Object
+
+=head1 SYNOPSIS
+
+ # fetch a row from MyApp::Model::Foo (which isa CatalystX::CRUD::Model)
+ my $foo = $c->model('Foo')->fetch( id => 1234 );
+ $foo->create;
+ $foo->read;
+ $foo->update;
+ $foo->delete;
+
+=head1 DESCRIPTION
+
+CatalystX::CRUD::Object::DBIC implements the required CRUD methods
+of a CatalystX::CRUD::Object subclass. It is intended for use
+with CatalystX::CRUD::Model::DBIC.
+
+=head1 METHODS
+
+Only new or overridden methods are documented here.
+
+=head2 create
+
+Calls delegate->create().
+
+=cut
+
+# required methods
+sub create {
+ shift->delegate->create(@_);
+}
+
+=head2 read
+
+Calls delegate->find(@_).
+
+=cut
+
+sub read {
+ shift->delegate->find(@_);
+}
+
+=head2 update
+
+Calls delegate->update().
+
+=cut
+
+sub update {
+ shift->delegate->update(@_);
+}
+
+=head2 delete
+
+Calls delegate->delete(@_).
+
+=cut
+
+sub delete {
+ shift->delegate->delete(@_);
+}
+
+=head1 AUTHOR
+
+Peter Karman, C<< <karman at cpan.org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-catalystx-crud-model-dbic at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD-Model-DBIC>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc CatalystX::CRUD::Model::DBIC
+
+You can also look for information at:
+
+=over 4
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/CatalystX-CRUD-Model-DBIC>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/CatalystX-CRUD-Model-DBIC>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD-Model-DBIC>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/CatalystX-CRUD-Model-DBIC>
+
+=back
+
+=head1 ACKNOWLEDGEMENTS
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 Peter Karman, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of CatalystX::CRUD::Object::DBIC
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/00-load.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/00-load.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/00-load.t 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,10 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib qw( ../CatalystX-CRUD/lib t );
+
+BEGIN {
+ use_ok( 'CatalystX::CRUD::Model::DBIC' );
+}
+
+diag( "Testing CatalystX::CRUD::Model::DBIC $CatalystX::CRUD::Model::DBIC::VERSION, Perl $], $^X" );
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/01-dbic.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/01-dbic.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/01-dbic.t 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,26 @@
+use Test::More tests => 10;
+
+BEGIN {
+ use lib qw( ../CatalystX-CRUD/lib t );
+ use_ok('CatalystX::CRUD::Model::DBIC');
+ use_ok('CatalystX::CRUD::Object::DBIC');
+
+ system("cd t/ && $^X insertdb.pl") and die "can't create db: $!";
+}
+
+END { unlink('t/example.db'); }
+
+use lib qw( t/lib );
+use Catalyst::Test 'MyApp';
+use Data::Dump qw( dump );
+
+ok( my $res = request('/test1'), "get /test1" );
+is( $res->content, 13, "right number of results" );
+ok( $res = request('/test2?cd.title=Bad'), "get /test2" );
+is( $res->content, 3, "iterator for cd.title=Bad" );
+ok( $res = request('/test3?cd.title=Bad'), "get /test3" );
+is( $res->content, 3, "search for cd.title=Bad" );
+ok( $res = request('/test4?cd.title=Bad'), "get /test4" );
+is( $res->content, 3, "count for cd.title=Bad" );
+
+# TODO need some actual CRUD. so far all we've done is search/retrieve.
\ No newline at end of file
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Artist.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Artist.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Artist.pm 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,9 @@
+package MyDB::Main::Artist;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/PK::Auto Core/);
+__PACKAGE__->table('artist');
+__PACKAGE__->add_columns(qw/ artistid name /);
+__PACKAGE__->set_primary_key('artistid');
+__PACKAGE__->has_many( 'cds' => 'MyDB::Main::Cd' );
+
+1;
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Cd.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Cd.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Cd.pm 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,10 @@
+package MyDB::Main::Cd;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/PK::Auto Core/);
+__PACKAGE__->table('cd');
+__PACKAGE__->add_columns(qw/ cdid artist title/);
+__PACKAGE__->set_primary_key('cdid');
+__PACKAGE__->belongs_to( 'artist' => 'MyDB::Main::Artist' );
+__PACKAGE__->has_many( 'tracks' => 'MyDB::Main::Track' );
+
+1;
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Track.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Track.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main/Track.pm 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,9 @@
+package MyDB::Main::Track;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/PK::Auto Core/);
+__PACKAGE__->table('track');
+__PACKAGE__->add_columns(qw/ trackid cd title/);
+__PACKAGE__->set_primary_key('trackid');
+__PACKAGE__->belongs_to( 'cd' => 'MyDB::Main::Cd' );
+
+1;
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/MyDB/Main.pm 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,5 @@
+package MyDB::Main;
+use base qw/DBIx::Class::Schema/;
+__PACKAGE__->load_classes(qw/Artist Cd Track/);
+
+1;
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/boilerplate.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/boilerplate.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/boilerplate.t 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,48 @@
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+sub not_in_file_ok {
+ my ($filename, %regex) = @_;
+ open my $fh, "<", $filename
+ or die "couldn't open $filename for reading: $!";
+
+ my %violated;
+
+ while (my $line = <$fh>) {
+ while (my ($desc, $regex) = each %regex) {
+ if ($line =~ $regex) {
+ push @{$violated{$desc}||=[]}, $.;
+ }
+ }
+ }
+
+ if (%violated) {
+ fail("$filename contains boilerplate text");
+ diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
+ } else {
+ pass("$filename contains no boilerplate text");
+ }
+}
+
+not_in_file_ok(README =>
+ "The README is used..." => qr/The README is used/,
+ "'version information here'" => qr/to provide version information/,
+);
+
+not_in_file_ok(Changes =>
+ "placeholder date/time" => qr(Date/time)
+);
+
+sub module_boilerplate_ok {
+ my ($module) = @_;
+ not_in_file_ok($module =>
+ 'the great new $MODULENAME' => qr/ - The great new /,
+ 'boilerplate description' => qr/Quick summary of what the module/,
+ 'stub function definition' => qr/function[12]/,
+ );
+}
+
+module_boilerplate_ok('lib/CatalystX/CRUD/Model/DBIC.pm');
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/example.sql
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/example.sql (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/example.sql 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,16 @@
+CREATE TABLE artist (
+ artistid INTEGER PRIMARY KEY,
+ name TEXT NOT NULL
+ );
+
+CREATE TABLE cd (
+ cdid INTEGER PRIMARY KEY,
+ artist INTEGER NOT NULL REFERENCES artist(artistid),
+ title TEXT NOT NULL
+ );
+
+CREATE TABLE track (
+ trackid INTEGER PRIMARY KEY,
+ cd INTEGER NOT NULL REFERENCES cd(cdid),
+ title TEXT NOT NULL
+ );
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/insertdb.pl
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/insertdb.pl (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/insertdb.pl 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,76 @@
+#!/usr/bin/perl -w
+
+use MyDB::Main;
+use strict;
+
+my $schema = MyDB::Main->connect('dbi:SQLite:example.db');
+my $dbh = $schema->storage->dbh;
+
+$dbh->do(
+ qq{
+CREATE TABLE artist (
+ artistid INTEGER PRIMARY KEY,
+ name TEXT NOT NULL
+ );}
+) or die;
+
+$dbh->do(
+ qq{
+CREATE TABLE cd (
+ cdid INTEGER PRIMARY KEY,
+ artist INTEGER NOT NULL REFERENCES artist(artistid),
+ title TEXT NOT NULL
+ );
+}
+) or die;
+
+$dbh->do(
+ qq{
+CREATE TABLE track (
+ trackid INTEGER PRIMARY KEY,
+ cd INTEGER NOT NULL REFERENCES cd(cdid),
+ title TEXT NOT NULL
+ );
+}
+) or die;
+
+# here's some of the sql that is going to be generated by the schema
+# INSERT INTO artist VALUES (NULL,'Michael Jackson');
+# INSERT INTO artist VALUES (NULL,'Eminem');
+
+my @artists = ( ['Michael Jackson'], ['Eminem'] );
+$schema->populate( 'Artist', [ [qw/name/], @artists, ] );
+
+my %albums = (
+ 'Thriller' => 'Michael Jackson',
+ 'Bad' => 'Michael Jackson',
+ 'The Marshall Mathers LP' => 'Eminem',
+);
+
+my @cds;
+foreach my $lp ( keys %albums ) {
+ my $artist
+ = $schema->resultset('Artist')->search( { name => $albums{$lp} } );
+ push @cds, [ $lp, $artist->first ];
+}
+
+$schema->populate( 'Cd', [ [qw/title artist/], @cds, ] );
+
+my %tracks = (
+ 'Beat It' => 'Thriller',
+ 'Billie Jean' => 'Thriller',
+ 'Dirty Diana' => 'Bad',
+ 'Smooth Criminal' => 'Bad',
+ 'Leave Me Alone' => 'Bad',
+ 'Stan' => 'The Marshall Mathers LP',
+ 'The Way I Am' => 'The Marshall Mathers LP',
+);
+
+my @tracks;
+foreach my $track ( keys %tracks ) {
+ my $cdname
+ = $schema->resultset('Cd')->search( { title => $tracks{$track}, } );
+ push @tracks, [ $cdname->first, $track ];
+}
+
+$schema->populate( 'Track', [ [qw/cd title/], @tracks, ] );
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp/Model/Main.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp/Model/Main.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp/Model/Main.pm 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,16 @@
+package MyApp::Model::Main;
+use base qw/CatalystX::CRUD::Model::DBIC/;
+
+__PACKAGE__->config(
+ schema_class => 'MyDB::Main',
+ connect_info =>
+ [ 'dbi:SQLite:' . MyApp->path_to() . '/../../example.db' ],
+ moniker => 'Track',
+ resultset_opts => {
+ join => [qw/ cd /],
+ prefetch => [qw/ cd /]
+ }
+
+);
+
+1;
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/lib/MyApp.pm 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,151 @@
+package MyApp;
+use strict;
+use warnings;
+use Catalyst;
+use Catalyst::Runtime;
+
+__PACKAGE__->setup();
+
+sub primary_key { 'id' }
+
+# mimic testdb.pl from the cookbook
+sub test1 : Local {
+ my ( $self, $c ) = @_;
+
+ my $schema = $c->model('Main')->schema;
+ my $count = 0;
+
+ get_tracks_by_cd( $schema, \$count, 'Bad' );
+ get_tracks_by_artist( $schema, \$count, 'Michael Jackson' );
+
+ get_cd_by_track( $schema, \$count, 'Stan' );
+ get_cds_by_artist( $schema, \$count, 'Michael Jackson' );
+
+ get_artist_by_track( $schema, \$count, 'Dirty Diana' );
+ get_artist_by_cd( $schema, \$count, 'The Marshall Mathers LP' );
+
+ $c->res->body($count);
+}
+
+# iterator
+sub test2 : Local {
+ my ( $self, $c ) = @_;
+
+ my $count = 0;
+
+ my $rs = $c->model('Main')->iterator;
+ while ( my $track = $rs->next ) {
+ $count++;
+ }
+
+ $c->res->body($count);
+}
+
+# search
+sub test3 : Local {
+ my ( $self, $c ) = @_;
+
+ my $count = 0;
+ my @results = $c->model('Main')->search;
+ for my $r (@results) {
+ $count++;
+ }
+
+ $c->res->body($count);
+}
+
+# count
+sub test4 : Local {
+ my ( $self, $c ) = @_;
+ my $count = $c->model('Main')->count;
+ $c->res->body($count);
+}
+
+#################################################################
+## private functions
+
+sub get_tracks_by_cd {
+ my $schema = shift;
+ my $count = shift;
+ my $cdtitle = shift;
+ my $rs = $schema->resultset('Track')->search(
+ { 'cd.title' => $cdtitle },
+ { join => [qw/ cd /],
+ prefetch => [qw/ cd /]
+ }
+ );
+ while ( my $track = $rs->next ) {
+ $$count++;
+ }
+
+}
+
+sub get_tracks_by_artist {
+ my $schema = shift;
+ my $count = shift;
+ my $artistname = shift;
+ my $rs = $schema->resultset('Track')->search(
+ { 'artist.name' => $artistname },
+ { join => { 'cd' => 'artist' }, }
+ );
+ while ( my $track = $rs->next ) {
+ $$count++;
+ }
+
+}
+
+sub get_cd_by_track {
+ my $schema = shift;
+ my $count = shift;
+ my $tracktitle = shift;
+
+ my $rs
+ = $schema->resultset('Cd')->search( { 'tracks.title' => $tracktitle },
+ { join => [qw/ tracks /], } );
+ my $cd = $rs->first;
+ $$count++;
+}
+
+sub get_cds_by_artist {
+ my $schema = shift;
+ my $count = shift;
+ my $artistname = shift;
+
+ my $rs = $schema->resultset('Cd')->search(
+ { 'artist.name' => $artistname },
+ { join => [qw/ artist /],
+ prefetch => [qw/ artist /]
+ }
+ );
+ while ( my $cd = $rs->next ) {
+ $$count++;
+ }
+
+}
+
+sub get_artist_by_track {
+ my $schema = shift;
+ my $count = shift;
+ my $tracktitle = shift;
+
+ my $rs = $schema->resultset('Artist')->search(
+ { 'tracks.title' => $tracktitle },
+ { join => { 'cds' => 'tracks' } }
+ );
+ my $artist = $rs->first;
+ $$count++;
+}
+
+sub get_artist_by_cd {
+ my $schema = shift;
+ my $count = shift;
+ my $cdtitle = shift;
+
+ my $rs = $schema->resultset('Artist')
+ ->search( { 'cds.title' => $cdtitle }, { join => [qw/ cds /], } );
+ my $artist = $rs->first;
+ $$count++;
+}
+
+1;
+
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/pod-coverage.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/pod-coverage.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/pod-coverage.t 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+all_pod_coverage_ok();
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/pod.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/pod.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/pod.t 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok();
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/test.pl
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/test.pl (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/test.pl 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,6 @@
+use DBIx::Class::Schema::Loader qw/ make_schema_at /;
+make_schema_at(
+ 'MyDB',
+ { debug => 1, dump_directory => './lib' },
+ [ 'dbi:Pg:dbname="al"', 'aluser', 'alpass' ],
+);
Added: CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/testdb.pl
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/testdb.pl (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-DBIC/trunk/t/testdb.pl 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,94 @@
+#!/usr/bin/perl -w
+
+use MyDB::Main;
+use strict;
+
+use Data::Dump qw( dump );
+use Carp;
+use Class::ISA;
+
+my $schema = MyDB::Main->connect('dbi:SQLite:example.db');
+
+get_tracks_by_cd('Bad');
+get_tracks_by_artist('Michael Jackson');
+
+get_cd_by_track('Stan');
+get_cds_by_artist('Michael Jackson');
+
+get_artist_by_track('Dirty Diana');
+get_artist_by_cd('The Marshall Mathers LP');
+
+sub get_tracks_by_cd {
+ my $cdtitle = shift;
+ print "get_tracks_by_cd($cdtitle):\n";
+ my $rs = $schema->resultset('Track')->search(
+ { 'cd.title' => $cdtitle },
+ { join => [qw/ cd /],
+ prefetch => [qw/ cd /]
+ }
+ );
+ while ( my $track = $rs->next ) {
+ my $class = ref($track);
+ dump [ Class::ISA::super_path($class) ];
+ print $track->title . "\n";
+ }
+ print "\n";
+}
+
+sub get_tracks_by_artist {
+ my $artistname = shift;
+ print "get_tracks_by_artist($artistname):\n";
+ my $rs = $schema->resultset('Track')->search(
+ { 'artist.name' => $artistname },
+ { join => { 'cd' => 'artist' }, }
+ );
+ while ( my $track = $rs->next ) {
+ print $track->title . "\n";
+ }
+ print "\n";
+}
+
+sub get_cd_by_track {
+ my $tracktitle = shift;
+ print "get_cd_by_track($tracktitle):\n";
+ my $rs
+ = $schema->resultset('Cd')->search( { 'tracks.title' => $tracktitle },
+ { join => [qw/ tracks /], } );
+ my $cd = $rs->first;
+ print $cd->title . "\n\n";
+}
+
+sub get_cds_by_artist {
+ my $artistname = shift;
+ print "get_cds_by_artist($artistname):\n";
+ my $rs = $schema->resultset('Cd')->search(
+ { 'artist.name' => $artistname },
+ { join => [qw/ artist /],
+ prefetch => [qw/ artist /]
+ }
+ );
+ while ( my $cd = $rs->next ) {
+ print $cd->title . "\n";
+ }
+ print "\n";
+}
+
+sub get_artist_by_track {
+ my $tracktitle = shift;
+ print "get_artist_by_track($tracktitle):\n";
+ my $rs = $schema->resultset('Artist')->search(
+ { 'tracks.title' => $tracktitle },
+ { join => { 'cds' => 'tracks' } }
+ );
+ my $artist = $rs->first;
+ print $artist->name . "\n\n";
+}
+
+sub get_artist_by_cd {
+ my $cdtitle = shift;
+ print "get_artist_by_cd($cdtitle):\n";
+ my $rs = $schema->resultset('Artist')
+ ->search( { 'cds.title' => $cdtitle }, { join => [qw/ cds /], } );
+ my $artist = $rs->first;
+ print $artist->name . "\n\n";
+}
Added: CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/Changes (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/Changes 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,14 @@
+Revision history for CatalystX-CRUD-View-Excel
+
+0.01 19 Dec 2007
+ First version, released on an unsuspecting world.
+
+0.02 20 Dec 2007
+ * Added SYNOPSIS and DESCRIPTION to docs.
+ * Updated Makefile.PL for correct dependencies.
+
+0.03 21 Dec 2007
+ * fix INCLUDE -> INCLUDE_PATH bug (it was wrong in ETP docs)
+
+
+
Added: CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/MANIFEST
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/MANIFEST (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/MANIFEST 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,9 @@
+Changes
+MANIFEST
+Makefile.PL
+README
+lib/CatalystX/CRUD/View/Excel.pm
+t/00-load.t
+t/boilerplate.t
+t/pod-coverage.t
+t/pod.t
Added: CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/Makefile.PL
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/Makefile.PL (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/Makefile.PL 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'CatalystX::CRUD::View::Excel',
+ AUTHOR => 'Peter Karman <karman at cpan dot org>',
+ VERSION_FROM => 'lib/CatalystX/CRUD/View/Excel.pm',
+ ABSTRACT_FROM => 'lib/CatalystX/CRUD/View/Excel.pm',
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Test::More' => 0,
+ 'CatalystX::CRUD' => 0.17,
+ 'Catalyst::View::Excel::Template::Plus' => 0,
+ 'Path::Class' => 0,
+
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'CatalystX-CRUD-View-Excel-*' },
+);
Added: CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/README
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/README (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/README 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,38 @@
+CatalystX-CRUD-View-Excel
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the perldoc command.
+
+ perldoc CatalystX::CRUD::View::Excel
+
+You can also look for information at:
+
+ Search CPAN
+ http://search.cpan.org/dist/CatalystX-CRUD-View-Excel
+
+ CPAN Request Tracker:
+ http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD-View-Excel
+
+ AnnoCPAN, annotated CPAN documentation:
+ http://annocpan.org/dist/CatalystX-CRUD-View-Excel
+
+ CPAN Ratings:
+ http://cpanratings.perl.org/d/CatalystX-CRUD-View-Excel
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2007 Regents of the University of Minnesota
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
Added: CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/lib/CatalystX/CRUD/View/Excel.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/lib/CatalystX/CRUD/View/Excel.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/lib/CatalystX/CRUD/View/Excel.pm 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,252 @@
+package CatalystX::CRUD::View::Excel;
+
+use warnings;
+use strict;
+use base qw( Catalyst::View::Excel::Template::Plus CatalystX::CRUD );
+use Path::Class;
+
+our $VERSION = '0.03';
+
+=head1 NAME
+
+CatalystX::CRUD::View::Excel - view CRUD search/list results in Excel format
+
+=head1 SYNOPSIS
+
+ package MyApp::View::Excel;
+ use base qw( CatalystX::CRUD::View::Excel );
+
+ __PACKAGE__->config(
+ TEMPLATE_EXTENSION => 'tt',
+ etp_config => {
+ INCLUDE => [ 'my/tt/path', __PACKAGE__->path_to('root') ],
+ }
+ );
+
+ 1;
+
+=cut
+
+=head1 DESCRIPTION
+
+CatalystX::CRUD::View::Excel makes it easy to export your search results
+as an Excel document. If you are using the other CatalystX::CRUD Controller
+and Model classes, your default end() method might look something like this:
+
+ sub end : ActionClass('RenderView') {
+ my ( $self, $c ) = @_;
+ if ( $c->req->param('as_xls') ) {
+ $c->stash->{current_view} = 'Excel';
+ }
+ }
+
+and get a .xls document for any search or list by simply adding a C<as_xls=1>
+param pair to your url query.
+
+B<NOTE:> If you are paging results, then you will need to turn off paging
+in order to get all your results in a single .xls file. You can do this
+with the standard C<_no_page> param as defined in the CatalystX::CRUD::Model
+API.
+
+=head1 METHODS
+
+=head2 new
+
+Overrides base new() method to set default INCLUDE and TEMPLATE_EXTENSION
+config values.
+
+=cut
+
+sub new {
+ my ( $class, $c, $args ) = @_;
+ my $self = $class->NEXT::new( $c, $args );
+ $self->etp_config->{INCLUDE_PATH} ||= [ $c->config->{root} ];
+ $self->config->{TEMPLATE_EXTENSION} ||= 'tt';
+ return $self;
+}
+
+=head2 process
+
+Overrides base process() method to call get_filename()
+and create template from results_template if a template file
+does not exist.
+
+=cut
+
+sub process {
+ my $self = shift;
+ my $c = shift;
+ my @args = @_;
+
+ my $template = $self->get_template_filename($c);
+
+ ( defined $template )
+ || die 'No template specified for rendering';
+
+ # does $template exist? otherwise create one ad-hoc
+ unless ( $self->template_exists($template) ) {
+ $template = \( $self->results_template($c) );
+ }
+
+ my $etp_engine = $c->stash->{etp_engine} || $self->etp_engine;
+ my $etp_config = $c->stash->{etp_config} || $self->etp_config;
+ my $etp_params = $c->stash->{etp_params} || $self->etp_params;
+
+ my $excel = $self->create_template_object(
+ $c => (
+ engine => $etp_engine,
+ template => $template,
+ config => $etp_config,
+ params => $etp_params,
+ )
+ );
+
+ $excel->param( $self->get_template_params($c) );
+
+ $c->response->content_type('application/x-msexcel');
+ my $filename = $self->get_filename($c);
+ $c->response->header( 'Content-Disposition',
+ qq{attachment; filename="$filename"} );
+ $c->response->body( $excel->output );
+}
+
+=head2 template_exists( I<path> )
+
+Search the TT include path to see if I<path> really exists.
+
+=cut
+
+sub template_exists {
+ my ( $self, $template ) = @_;
+ for my $path ( @{ $self->etp_config->{INCLUDE_PATH} } ) {
+ return 1 if -s file( $path, $template );
+ }
+ return 0;
+}
+
+=head2 get_template_filename( I<context> )
+
+Overrides base method to change the default naming convention.
+If C<template> is not set in stash(), then the default template
+path is:
+
+ $c->action . '.xls.' . $self->config->{TEMPLATE_EXTENSION}
+
+C<TEMPLATE_EXTENSION> by default is C<tt>. You can alter that with the config()
+method.
+
+=cut
+
+sub get_template_filename {
+ my ( $self, $c ) = @_;
+ $c->stash->{template}
+ || ( $c->action . '.xls.' . $self->config->{TEMPLATE_EXTENSION} );
+}
+
+=head2 get_filename( I<context> )
+
+Returns the name of the file to return in the response header
+Content-Disposition.
+
+=cut
+
+sub get_filename {
+ my ( $self, $c ) = @_;
+ my $f = $c->action . '.xls';
+ $f =~ s,/,_,g;
+ return $f;
+}
+
+=head2 results_template( I<context> )
+
+Returns results-specific template.
+
+=cut
+
+sub results_template {
+ my ( $self, $c ) = @_;
+
+ my $tmpl = <<TT;
+<workbook>
+ <worksheet name="[% c.controller.model_name.replace('\\W+','_') %]">
+ [% myfields = c.controller.field_names %]
+ <row>
+ [% FOR fn = myfields %]
+ <bold><cell>[% fn %]</cell></bold>
+ [% END %]
+ </row>
+ [% FOR r = results.results %]
+ <row>
+ [% FOR fn = myfields %]
+ <cell>[% r.\$fn %]</cell>
+ [% END %]
+ </row>
+ [% END %]
+ </worksheet>
+</workbook>
+TT
+
+ return $tmpl;
+
+}
+
+=head1 AUTHOR
+
+Peter Karman, C<< <karman at cpan dot org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-catalystx-crud-view-excel at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD-View-Excel>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc CatalystX::CRUD::View::Excel
+
+You can also look for information at:
+
+=over 4
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/CatalystX-CRUD-View-Excel>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/CatalystX-CRUD-View-Excel>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD-View-Excel>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/CatalystX-CRUD-View-Excel>
+
+=back
+
+=head1 ACKNOWLEDGEMENTS
+
+The Minnesota Supercomputing Institute C<< http://www.msi.umn.edu/ >>
+sponsored the development of this software.
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 by the Regents of the University of Minnesota.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+Catalyst::View::Excel::Template::Plus,
+CatalystX::CRUD
+
+=cut
+
+1;
Added: CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/00-load.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/00-load.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/00-load.t 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,9 @@
+#!perl -T
+
+use Test::More tests => 1;
+
+BEGIN {
+ use_ok( 'CatalystX::CRUD::View::Excel' );
+}
+
+diag( "Testing CatalystX::CRUD::View::Excel $CatalystX::CRUD::View::Excel::VERSION, Perl $], $^X" );
Added: CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/boilerplate.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/boilerplate.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/boilerplate.t 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,48 @@
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+sub not_in_file_ok {
+ my ($filename, %regex) = @_;
+ open my $fh, "<", $filename
+ or die "couldn't open $filename for reading: $!";
+
+ my %violated;
+
+ while (my $line = <$fh>) {
+ while (my ($desc, $regex) = each %regex) {
+ if ($line =~ $regex) {
+ push @{$violated{$desc}||=[]}, $.;
+ }
+ }
+ }
+
+ if (%violated) {
+ fail("$filename contains boilerplate text");
+ diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
+ } else {
+ pass("$filename contains no boilerplate text");
+ }
+}
+
+not_in_file_ok(README =>
+ "The README is used..." => qr/The README is used/,
+ "'version information here'" => qr/to provide version information/,
+);
+
+not_in_file_ok(Changes =>
+ "placeholder date/time" => qr(Date/time)
+);
+
+sub module_boilerplate_ok {
+ my ($module) = @_;
+ not_in_file_ok($module =>
+ 'the great new $MODULENAME' => qr/ - The great new /,
+ 'boilerplate description' => qr/Quick summary of what the module/,
+ 'stub function definition' => qr/function[12]/,
+ );
+}
+
+module_boilerplate_ok('lib/CatalystX/CRUD/View/Excel.pm');
Added: CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/pod-coverage.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/pod-coverage.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/pod-coverage.t 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+all_pod_coverage_ok();
Added: CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/pod.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/pod.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-View-Excel/trunk/t/pod.t 2008-03-11 17:22:53 UTC (rev 7488)
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok();
More information about the Catalyst-commits
mailing list