Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit e4d3fef7b047b9b67121d04c7f737b6c68041c26 Stevan Little committed Apr 20, 2010
@@ -0,0 +1,2 @@
+.DS_Store
+t/apps/Test-App/root/db
@@ -0,0 +1,60 @@
+package Catalyst::Plugin::Bread::Board;
+use Moose;
+
+our $VERSION = '0.01';
+our $AUTHORITY = 'cpan:STEVAN';
+
+sub setup {
+ my $c = shift;
+
+
+ $c->next::method( @_ )
+}
+
+
+__PACKAGE__->meta->make_immutable;
+
+no Moose; 1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Catalyst::Plugin::Bread::Board - A Moosey solution to this problem
+
+=head1 SYNOPSIS
+
+ use Catalyst::Plugin::Bread::Board;
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=over 4
+
+=item B<>
+
+=back
+
+=head1 BUGS
+
+All complex software has bugs lurking in it, and this module is no
+exception. If you find a bug please either email me, or add the bug
+to cpan-RT.
+
+=head1 AUTHOR
+
+Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2010 Infinity Interactive, Inc.
+
+L<http://www.iinteractive.com>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
@@ -0,0 +1,108 @@
+package Catalyst::Plugin::Bread::Board::Container;
+use Moose;
+use Bread::Board;
+use MooseX::Types::Path::Class;
+
+our $VERSION = '0.01';
+our $AUTHORITY = 'cpan:STEVAN';
+
+extends 'Bread::Board::Container';
+
+has 'app_root' => (
+ is => 'ro',
+ isa => 'Path::Class::Dir',
+ coerce => 1,
+ required => 1,
+);
+
+sub BUILD {
+ my $self = shift;
+
+ container $self => as {
+ service 'app_root' => $self->app_root;
+ };
+}
+
+sub as_catalyst_config {
+ my $self = shift;
+
+ my $config = {};
+
+ # process any top level stuff
+ foreach my $service_name ( $self->get_service_list ) {
+ $config->{ $service_name } = $self->get_service( $service_name )->get;
+ }
+
+ foreach my $container_name ( $self->get_sub_container_list ) {
+ # FIXME
+ # this is no doubt wrong, but
+ # it will suffice for now
+ # - SL
+ next unless $container_name =~ /^Model|View|Plugin$/;
+
+ my $container = $self->get_sub_container( $container_name );
+
+ foreach my $sub_container_name ( $container->get_sub_container_list ) {
+
+ my $sub_container = $container->get_sub_container( $sub_container_name );
+
+ $config->{ join '::' => $container_name, $sub_container_name } = {
+ map {
+ $_ => $sub_container->get_service( $_ )->get
+ } $sub_container->get_service_list
+ };
+ }
+
+ }
+
+
+ $config;
+}
+
+
+__PACKAGE__->meta->make_immutable;
+
+no Bread::Board; no Moose; 1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Catalyst::Plugin::Bread::Board::Container - A Moosey solution to this problem
+
+=head1 SYNOPSIS
+
+ use Catalyst::Plugin::Bread::Board::Container;
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=over 4
+
+=item B<>
+
+=back
+
+=head1 BUGS
+
+All complex software has bugs lurking in it, and this module is no
+exception. If you find a bug please either email me, or add the bug
+to cpan-RT.
+
+=head1 AUTHOR
+
+Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2010 Infinity Interactive, Inc.
+
+L<http://www.iinteractive.com>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use Test::Moose;
+
+BEGIN {
+ use_ok('Catalyst::Plugin::Bread::Board');
+}
+
+
+
+done_testing;
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FindBin;
+use Path::Class;
+
+use Test::More;
+use Test::Exception;
+use Test::Moose;
+
+BEGIN {
+ use_ok('Catalyst::Plugin::Bread::Board::Container');
+}
+
+my $c = Catalyst::Plugin::Bread::Board::Container->new(
+ name => 'Test010',
+ app_root => [ $FindBin::Bin ],
+);
+isa_ok($c, 'Catalyst::Plugin::Bread::Board::Container');
+
+is($c->name, 'Test010', '... got the right name');
+isa_ok($c->app_root, 'Path::Class::Dir');
+
+is($c->app_root->stringify, dir( $FindBin::Bin )->stringify, '... got the right dir');
+
+my $app_root = $c->fetch('app_root')->get;
+is($c->app_root, $app_root, '... the service is the same as what we passed in');
+
+done_testing;
@@ -0,0 +1,98 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FindBin;
+use Path::Class;
+
+use Test::More;
+use Test::Exception;
+use Test::Moose;
+
+BEGIN {
+ use_ok('Catalyst::Plugin::Bread::Board::Container');
+}
+
+{
+ package Test::App::Container;
+ use Moose;
+ use Bread::Board;
+
+ extends 'Catalyst::Plugin::Bread::Board::Container';
+
+ sub BUILD {
+ my $self = shift;
+
+ container $self => as {
+
+ container 'Model' => as {
+ container 'DBIC' => as {
+ service 'schema_class' => 'Test::App::Schema::DB';
+ service 'connect_info' => (
+ block => sub {
+ my $root = (shift)->param('app_root');
+ 'dbi:SQLite:dbname=' . $root->file(qw[ root db ])
+ },
+ dependencies => [ depends_on('/app_root') ]
+ );
+ };
+ };
+
+ container 'View' => as {
+ container 'TT' => as {
+ service 'TEMPLATE_EXTENSION' => '.tt';
+ service 'INCLUDE_PATH' => (
+ block => sub {
+ my $root = (shift)->param('app_root');
+ [ $root->subdir('root/templates')->stringify ]
+ },
+ dependencies => [ depends_on('/app_root') ]
+ );
+ };
+ };
+
+ container 'Plugin' => as {
+ container 'Session' => as {
+ service 'cookie_name' => 'test_session';
+ service 'expires' => 1920;
+ service 'namespace' => 'test';
+ };
+ };
+
+ };
+ }
+}
+
+my $app_root = dir( $FindBin::Bin );
+
+my $c = Test::App::Container->new(
+ name => 'Test010',
+ app_root => $app_root,
+);
+isa_ok($c, 'Test::App::Container');
+isa_ok($c, 'Catalyst::Plugin::Bread::Board::Container');
+
+is_deeply(
+ $c->as_catalyst_config,
+ {
+ 'app_root' => $app_root,
+ 'Model::DBIC' => {
+ 'schema_class' => 'Test::App::Schema::DB',
+ 'connect_info' => 'dbi:SQLite:dbname=' . $app_root->file(qw[ root db ])
+ },
+ 'View::TT' => {
+ 'TEMPLATE_EXTENSION' => '.tt',
+ 'INCLUDE_PATH' => [
+ $app_root->file(qw[ root templates ])->stringify
+ ]
+ },
+ 'Plugin::Session' => {
+ 'namespace' => 'test',
+ 'cookie_name' => 'test_session',
+ 'expires' => 1920
+ }
+ },
+ '... got the config we expected for Catalyst'
+);
+
+done_testing;
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FindBin;
+use Path::Class;
+
+use Test::More;
+use Test::Exception;
+use Test::Moose;
+
+use lib "$FindBin::Bin/apps/Test-App/lib";
+
+use Test::App::Schema::DB;
+
+my $app_root = dir("$FindBin::Bin/apps/Test-App/");
+my $db_file = $app_root->file(qw[ root db ]);
+
+$db_file->remove if -e $db_file;
+
+my $s = Test::App::Schema::DB->connect(
+ 'dbi:SQLite:dbname=' . $db_file
+);
+$s->deploy;
+
+my $artists = $s->resultset('Artist');
+
+my @artist = (
+ $artists->create( { id => 1, name => 'Willem de Kooning' } ),
+ $artists->create( { id => 2, name => 'Mark Rothko' } ),
+ $artists->create( { id => 3, name => 'Jackson Pollock' } ),
+ $artists->create( { id => 4, name => 'Franz Kline' } ),
+);
+
+## ---------------------- Catalyst Test -----------------------------
+
+use Catalyst::Test 'Test::App';
+
+ok( request('/')->is_success, '... request succeeded' );
+
+my $content = get('/');
+
+like( $content, qr/<h1>Artist Listing<\/h1>/, '... got value we expected' );
+like( $content, qr/<li>Willem de Kooning<\/li>/, '... got value we expected' );
+like( $content, qr/<li>Mark Rothko<\/li>/, '... got value we expected' );
+like( $content, qr/<li>Jackson Pollock<\/li>/, '... got value we expected' );
+like( $content, qr/<li>Franz Kline<\/li>/, '... got value we expected' );
+
+done_testing;
Oops, something went wrong.

0 comments on commit e4d3fef

Please sign in to comment.