[Catalyst-commits] r8236 - / Catalyst-Helper-AuthDBIC
Catalyst-Helper-AuthDBIC/inc Catalyst-Helper-AuthDBIC/inc/Module
Catalyst-Helper-AuthDBIC/lib Catalyst-Helper-AuthDBIC/lib/Catalyst
Catalyst-Helper-AuthDBIC/lib/Catalyst/Helper
Catalyst-Helper-AuthDBIC/script Catalyst-Helper-AuthDBIC/t
Catalyst-Helper-AuthDBIC/t/author Catalyst-Helper-AuthDBIC/t/lib
Catalyst-Helper-AuthDBIC/t/lib/TestApp
Catalyst-Helper-AuthDBIC/t/lib/TestApp/Controller
Catalyst-Helper-AuthDBIC/t/lib/TestApp/Model
Catalyst-Helper-AuthDBIC/t/lib/db
Catalyst-Helper-AuthDBIC/t/lib/script
zarquon at dev.catalyst.perl.org
zarquon at dev.catalyst.perl.org
Wed Aug 20 22:50:36 BST 2008
Author: zarquon
Date: 2008-08-20 22:50:36 +0100 (Wed, 20 Aug 2008)
New Revision: 8236
Added:
Catalyst-Helper-AuthDBIC/
Catalyst-Helper-AuthDBIC/Changes
Catalyst-Helper-AuthDBIC/MANIFEST.SKIP
Catalyst-Helper-AuthDBIC/Makefile.PL
Catalyst-Helper-AuthDBIC/README
Catalyst-Helper-AuthDBIC/inc/
Catalyst-Helper-AuthDBIC/inc/.author/
Catalyst-Helper-AuthDBIC/inc/Module/
Catalyst-Helper-AuthDBIC/inc/Module/Install.pm
Catalyst-Helper-AuthDBIC/lib/
Catalyst-Helper-AuthDBIC/lib/Catalyst/
Catalyst-Helper-AuthDBIC/lib/Catalyst/Helper/
Catalyst-Helper-AuthDBIC/lib/Catalyst/Helper/AuthDBIC.pm
Catalyst-Helper-AuthDBIC/script/
Catalyst-Helper-AuthDBIC/script/auth_bootstrap.pl
Catalyst-Helper-AuthDBIC/t/
Catalyst-Helper-AuthDBIC/t/00-load.t
Catalyst-Helper-AuthDBIC/t/01-functions.t
Catalyst-Helper-AuthDBIC/t/author/
Catalyst-Helper-AuthDBIC/t/author/pod-coverage.t
Catalyst-Helper-AuthDBIC/t/author/pod.t
Catalyst-Helper-AuthDBIC/t/lib/
Catalyst-Helper-AuthDBIC/t/lib/Makefile.PL
Catalyst-Helper-AuthDBIC/t/lib/TestApp.pm
Catalyst-Helper-AuthDBIC/t/lib/TestApp/
Catalyst-Helper-AuthDBIC/t/lib/TestApp/Controller/
Catalyst-Helper-AuthDBIC/t/lib/TestApp/Controller/Root.pm
Catalyst-Helper-AuthDBIC/t/lib/TestApp/Model/
Catalyst-Helper-AuthDBIC/t/lib/TestApp/Model/.gitignore
Catalyst-Helper-AuthDBIC/t/lib/db/
Catalyst-Helper-AuthDBIC/t/lib/db/auth.db,"",""
Catalyst-Helper-AuthDBIC/t/lib/db/auth.db,,
Catalyst-Helper-AuthDBIC/t/lib/script/
Catalyst-Helper-AuthDBIC/t/lib/script/testapp_create.pl
Catalyst-Helper-AuthDBIC/t/lib/script/testapp_server.pl
Catalyst-Helper-AuthDBIC/t/lib/script/testapp_test.pl
Catalyst-Helper-AuthDBIC/t/live-test.t
Modified:
/
Log:
r13748 at harold: kd | 2008-08-20 22:49:54 +0100
rough auth helper
Property changes on:
___________________________________________________________________
Name: svk:merge
- 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:13745
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909
+ 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:13748
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909
Added: Catalyst-Helper-AuthDBIC/Changes
===================================================================
Added: Catalyst-Helper-AuthDBIC/MANIFEST.SKIP
===================================================================
--- Catalyst-Helper-AuthDBIC/MANIFEST.SKIP (rev 0)
+++ Catalyst-Helper-AuthDBIC/MANIFEST.SKIP 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,8 @@
+.git/
+blib
+pm_to_blib
+MANIFEST.bak
+MANIFEST.SKIP~
+cover_db
+Makefile$
+Makefile.old$
Added: Catalyst-Helper-AuthDBIC/Makefile.PL
===================================================================
--- Catalyst-Helper-AuthDBIC/Makefile.PL (rev 0)
+++ Catalyst-Helper-AuthDBIC/Makefile.PL 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,31 @@
+use inc::Module::Install;
+
+my $module = 'Catalyst::Helper::AuthDBIC';
+
+my $dist = $module;
+$dist =~ s/::/-/g;
+name($dist);
+
+my @path = split '::', $module;
+all_from('lib/'. (join '/', at path). '.pm');
+
+build_requires 'Catalyst::Runtime';
+build_requires 'Test::WWW::Mechanize::Catalyst';
+build_requires 'Test::More';
+build_requires 'ok';
+requires 'DBIx::Class::DigestColumns';
+requires 'Digest::SHA1';
+requires 'PPI';
+requires 'DBIx::Class::Schema::Loader';
+
+# not real deps but the generated bits of app need them.
+requires 'Catalyst::Plugin::Authentication';
+requires 'Catalyst::Plugin::Authorization::Roles';
+requires 'Catalyst::Plugin::Session';
+requires 'Catalyst::Plugin::Session::State::Cookie';
+requires 'Catalyst::Plugin::Session::Store::FastMmap';
+requires 'Catalyst::Plugin::Authentication::Store::DBIC';
+
+install_script glob('script/*.pl');
+
+WriteAll();
Added: Catalyst-Helper-AuthDBIC/README
===================================================================
--- Catalyst-Helper-AuthDBIC/README (rev 0)
+++ Catalyst-Helper-AuthDBIC/README 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,3 @@
+Helper to provide a simple authentication scaffold for a Catalyst
+application. Run the script authdbic.pl in your application's root
+directory to create a simple database based authentication system.
Added: Catalyst-Helper-AuthDBIC/inc/Module/Install.pm
===================================================================
--- Catalyst-Helper-AuthDBIC/inc/Module/Install.pm (rev 0)
+++ Catalyst-Helper-AuthDBIC/inc/Module/Install.pm 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,281 @@
+#line 1
+package Module::Install;
+
+# For any maintainers:
+# The load order for Module::Install is a bit magic.
+# It goes something like this...
+#
+# IF ( host has Module::Install installed, creating author mode ) {
+# 1. Makefile.PL calls "use inc::Module::Install"
+# 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install
+# 3. The installed version of inc::Module::Install loads
+# 4. inc::Module::Install calls "require Module::Install"
+# 5. The ./inc/ version of Module::Install loads
+# } ELSE {
+# 1. Makefile.PL calls "use inc::Module::Install"
+# 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install
+# 3. The ./inc/ version of Module::Install loads
+# }
+
+use 5.004;
+use strict 'vars';
+
+use vars qw{$VERSION};
+BEGIN {
+ # All Module::Install core packages now require synchronised versions.
+ # This will be used to ensure we don't accidentally load old or
+ # different versions of modules.
+ # 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 = '0.64';
+}
+
+# Whether or not inc::Module::Install is actually loaded, the
+# $INC{inc/Module/Install.pm} is what will still get set as long as
+# the caller loaded module this in the documented manner.
+# If not set, the caller may NOT have loaded the bundled version, and thus
+# they may not have a MI version that works with the Makefile.PL. This would
+# result in false errors or unexpected behaviour. And we don't want that.
+my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
+unless ( $INC{$file} ) {
+ die <<"END_DIE";
+Please invoke ${\__PACKAGE__} with:
+
+ use inc::${\__PACKAGE__};
+
+not:
+
+ use ${\__PACKAGE__};
+
+END_DIE
+}
+
+# If the script that is loading Module::Install is from the future,
+# then make will detect this and cause it to re-run over and over
+# again. This is bad. Rather than taking action to touch it (which
+# is unreliable on some platforms and requires write permissions)
+# for now we should catch this and refuse to run.
+if ( -f $0 and (stat($0))[9] > time ) {
+ die << "END_DIE";
+Your installer $0 has a modification time in the future.
+
+This is known to create infinite loops in make.
+
+Please correct this, then run $0 again.
+
+END_DIE
+}
+
+use Cwd ();
+use File::Find ();
+use File::Path ();
+use FindBin;
+
+*inc::Module::Install::VERSION = *VERSION;
+ at inc::Module::Install::ISA = __PACKAGE__;
+
+sub autoload {
+ my $self = shift;
+ my $who = $self->_caller;
+ my $cwd = Cwd::cwd();
+ my $sym = "${who}::AUTOLOAD";
+ $sym->{$cwd} = sub {
+ my $pwd = Cwd::cwd();
+ if ( my $code = $sym->{$pwd} ) {
+ # delegate back to parent dirs
+ goto &$code unless $cwd eq $pwd;
+ }
+ $$sym =~ /([^:]+)$/ or die "Cannot autoload $who - $sym";
+ unshift @_, ($self, $1);
+ goto &{$self->can('call')} unless uc($1) eq $1;
+ };
+}
+
+sub import {
+ my $class = shift;
+ my $self = $class->new(@_);
+ my $who = $self->_caller;
+
+ unless ( -f $self->{file} ) {
+ require "$self->{path}/$self->{dispatch}.pm";
+ File::Path::mkpath("$self->{prefix}/$self->{author}");
+ $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self );
+ $self->{admin}->init;
+ @_ = ($class, _self => $self);
+ goto &{"$self->{name}::import"};
+ }
+
+ *{"${who}::AUTOLOAD"} = $self->autoload;
+ $self->preload;
+
+ # Unregister loader and worker packages so subdirs can use them again
+ delete $INC{"$self->{file}"};
+ delete $INC{"$self->{path}.pm"};
+}
+
+sub preload {
+ my ($self) = @_;
+
+ unless ( $self->{extensions} ) {
+ $self->load_extensions(
+ "$self->{prefix}/$self->{path}", $self
+ );
+ }
+
+ my @exts = @{$self->{extensions}};
+ unless ( @exts ) {
+ my $admin = $self->{admin};
+ @exts = $admin->load_all_extensions;
+ }
+
+ my %seen;
+ foreach my $obj ( @exts ) {
+ while (my ($method, $glob) = each %{ref($obj) . '::'}) {
+ next unless $obj->can($method);
+ next if $method =~ /^_/;
+ next if $method eq uc($method);
+ $seen{$method}++;
+ }
+ }
+
+ my $who = $self->_caller;
+ foreach my $name ( sort keys %seen ) {
+ *{"${who}::$name"} = sub {
+ ${"${who}::AUTOLOAD"} = "${who}::$name";
+ goto &{"${who}::AUTOLOAD"};
+ };
+ }
+}
+
+sub new {
+ my ($class, %args) = @_;
+
+ # ignore the prefix on extension modules built from top level.
+ my $base_path = Cwd::abs_path($FindBin::Bin);
+ unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) {
+ delete $args{prefix};
+ }
+
+ return $args{_self} if $args{_self};
+
+ $args{dispatch} ||= 'Admin';
+ $args{prefix} ||= 'inc';
+ $args{author} ||= ($^O eq 'VMS' ? '_author' : '.author');
+ $args{bundle} ||= 'inc/BUNDLES';
+ $args{base} ||= $base_path;
+ $class =~ s/^\Q$args{prefix}\E:://;
+ $args{name} ||= $class;
+ $args{version} ||= $class->VERSION;
+ unless ( $args{path} ) {
+ $args{path} = $args{name};
+ $args{path} =~ s!::!/!g;
+ }
+ $args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm";
+
+ bless( \%args, $class );
+}
+
+sub call {
+ my ($self, $method) = @_;
+ my $obj = $self->load($method) or return;
+ splice(@_, 0, 2, $obj);
+ goto &{$obj->can($method)};
+}
+
+sub load {
+ my ($self, $method) = @_;
+
+ $self->load_extensions(
+ "$self->{prefix}/$self->{path}", $self
+ ) unless $self->{extensions};
+
+ foreach my $obj (@{$self->{extensions}}) {
+ return $obj if $obj->can($method);
+ }
+
+ my $admin = $self->{admin} or die <<"END_DIE";
+The '$method' method does not exist in the '$self->{prefix}' path!
+Please remove the '$self->{prefix}' directory and run $0 again to load it.
+END_DIE
+
+ my $obj = $admin->load($method, 1);
+ push @{$self->{extensions}}, $obj;
+
+ $obj;
+}
+
+sub load_extensions {
+ my ($self, $path, $top) = @_;
+
+ unless ( grep { lc $_ eq lc $self->{prefix} } @INC ) {
+ unshift @INC, $self->{prefix};
+ }
+
+ foreach my $rv ( $self->find_extensions($path) ) {
+ my ($file, $pkg) = @{$rv};
+ next if $self->{pathnames}{$pkg};
+
+ local $@;
+ my $new = eval { require $file; $pkg->can('new') };
+ unless ( $new ) {
+ warn $@ if $@;
+ next;
+ }
+ $self->{pathnames}{$pkg} = delete $INC{$file};
+ push @{$self->{extensions}}, &{$new}($pkg, _top => $top );
+ }
+
+ $self->{extensions} ||= [];
+}
+
+sub find_extensions {
+ my ($self, $path) = @_;
+
+ my @found;
+ File::Find::find( sub {
+ my $file = $File::Find::name;
+ return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is;
+ my $subpath = $1;
+ return if lc($subpath) eq lc($self->{dispatch});
+
+ $file = "$self->{path}/$subpath.pm";
+ my $pkg = "$self->{name}::$subpath";
+ $pkg =~ s!/!::!g;
+
+ # If we have a mixed-case package name, assume case has been preserved
+ # correctly. Otherwise, root through the file to locate the case-preserved
+ # version of the package name.
+ if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) {
+ open PKGFILE, "<$subpath.pm" or die "find_extensions: Can't open $subpath.pm: $!";
+ my $in_pod = 0;
+ while ( <PKGFILE> ) {
+ $in_pod = 1 if /^=\w/;
+ $in_pod = 0 if /^=cut/;
+ next if ($in_pod || /^=cut/); # skip pod text
+ next if /^\s*#/; # and comments
+ if ( m/^\s*package\s+($pkg)\s*;/i ) {
+ $pkg = $1;
+ last;
+ }
+ }
+ close PKGFILE;
+ }
+
+ push @found, [ $file, $pkg ];
+ }, $path ) if -d $path;
+
+ @found;
+}
+
+sub _caller {
+ my $depth = 0;
+ my $call = caller($depth);
+ while ( $call eq __PACKAGE__ ) {
+ $depth++;
+ $call = caller($depth);
+ }
+ return $call;
+}
+
+1;
Added: Catalyst-Helper-AuthDBIC/lib/Catalyst/Helper/AuthDBIC.pm
===================================================================
--- Catalyst-Helper-AuthDBIC/lib/Catalyst/Helper/AuthDBIC.pm (rev 0)
+++ Catalyst-Helper-AuthDBIC/lib/Catalyst/Helper/AuthDBIC.pm 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,416 @@
+package Catalyst::Helper::AuthDBIC;
+use strict;
+use warnings;
+use Catalyst::Helper;
+our $VERSION = '0.01';
+use Carp;
+use UNIVERSAL::require;
+use DBI;
+use DBIx::Class::Schema::Loader qw/ make_schema_at /;
+use Memoize;
+use PPI;
+use PPI::Find;
+use Catalyst::Utils;
+use PPI::Dumper;
+memoize('app_name');
+
+=head1 NAME
+
+Catalyst::Helper::AuthDBIC (EXPERIMENTAL)
+
+=head1 SUMMARY
+
+This is an experimental module to bootstrap the authentication portion
+of a Catalyst application. It creates a Catalyst model,
+DBIx::Class::Schema classes, basic templates adjusts the required
+plugins for you, and configures authentication. There are no options,
+and it doesn't do much inthe way of error checking for you, so you are
+recommended to back up your application before using this module.
+
+=head2 USAGE
+
+run the auth_bootstrap.pl in your application's root dir.
+
+=head2 sub app_name()
+
+Get the name of the application from Makefile.PL
+
+=cut
+
+sub app_name {
+ my $app_name;
+ my $file = "Makefile.PL";
+ open my ($FH), "<", $file or croak "Makefile.PL not found, run this script from your application root dir\n";
+ while (<$FH>) {
+ next unless /^name '(.*?)';/;
+ $app_name=$1;
+ croak "Makefile.PL appears to have no name for the application\n" unless $app_name;
+ last;
+ }
+ return $app_name
+}
+
+=head2 sub make_model()
+
+Creates the sqlite auth db in ./db and makes the dbic schema and
+catalyst model with Catalyst::Helper::Model::DBIC::Schema
+
+=cut
+
+sub make_model {
+ # put sqlitedb in __path_to('db')__;
+ my $helper = Catalyst::Helper->new();
+ $helper->mk_dir('db');
+ my $dbh = DBI->connect("dbi:SQLite:dbname=db/auth.db","","");
+ my @sql = ("CREATE TABLE role (
+ id INTEGER PRIMARY KEY,
+ role TEXT );",
+ "CREATE TABLE user (
+ id INTEGER PRIMARY KEY,
+ username TEXT,
+ email TEXT,
+ password TEXT,
+ status TEXT,
+ role_text TEXT,
+ session_data TEXT );",
+ "CREATE TABLE user_role (
+ id INTEGER PRIMARY KEY,
+ user INTEGER REFERENCES user(id),
+ roleid INTEGER REFERENCES role(id) );"
+ );
+
+ map { $dbh->do($_) } @sql;
+ my $app_name = Catalyst::Utils::appprefix(app_name());
+ make_schema_at("Auth::Schema",
+ { components => ['DigestColumns'],
+ dump_directory => 'lib' ,
+ },
+ ["dbi:SQLite:dbname=db/auth.db", "",""]);
+
+ my @cmd = ( "./script/$app_name" . "_create.pl" ,
+ 'model',
+ 'Auth',
+ 'DBIC::Schema',
+ 'Auth::Schema',
+ 'dbi:SQLite:db/auth.db,"",""');
+ system( @cmd );
+ my $user_schema = 'Auth::Schema::User';
+ my @path = split /::/, $user_schema;
+ my $user_schema_path = join '/', @path;
+ my $module = "lib/$user_schema_path.pm";
+ my $doc = PPI::Document->new($module);
+ my $digest_code = $helper->get_file(__PACKAGE__, 'digest');
+
+ my $comments = $doc->find(
+ sub { $_[1]->isa('PPI::Token::Comment')}
+ );
+ my $last_comment = $comments->[$#{$comments}];
+ $last_comment->set_content($digest_code);
+ $doc->save($module);
+}
+
+=head2 sub mk_auth_controller()
+
+uses Catalyst::Helper to make a ::Controller::Auth
+
+=cut
+
+sub mk_auth_controller {
+ my $helper = Catalyst::Helper->new();
+ my $app_name = app_name();
+ my $controller_file = "lib/$app_name/Controller/Auth.pm";
+ $helper->render_file ('auth_controller',
+ $controller_file,
+ {app_name => $app_name});
+}
+
+=head2 sub add_plugins()
+
+ uses ppi to add the auth plugins in the use Catalyst qw// statement
+
+=cut
+
+sub add_plugins {
+ my ($module, $doc) = _get_ppi();
+
+ my $find = PPI::Find->new( \&_find_use_catalyst);
+ my ($found) = $find->in($doc);
+ my $find_plugins = PPI::Find->new(\&_find_plugins);
+ my ($plugins) = $find_plugins->in($found);
+ croak "Your app is not using any plugins, so we can't continue\n" if !$plugins;
+ my $plugin_str = scalar($plugins);
+ my $tail = chop $plugin_str;
+ $plugin_str .= "\n Authentication\n Authorization::Roles\n Session\n Session::State::Cookie\n Session::Store::FastMmap $tail";
+ $plugins->set_content($plugin_str);
+ $doc->save($module);
+}
+
+sub _find_plugins {
+ my ($element, $search) = @_;
+ return 1 if $element->isa('PPI::Token::QuoteLike::Words');
+ return 0
+}
+
+sub _find_use_catalyst {
+ my ($element, $search) = @_;
+ if ( $element->isa('PPI::Statement::Include') &&
+ $element->type eq 'use' &&
+ $element->module eq 'Catalyst'
+ ) {
+ return 1;
+ }
+ return 0;
+}
+
+=head2 sub add_config()
+
+Add the auth configuration in MyApp.pm
+
+=cut
+
+sub add_config {
+ my ($module, $doc) = _get_ppi();
+ my $found = PPI::Find->new(\&_find_setup);
+ my ($setup) = $found->in($doc);
+ croak "unable to find __PACKAGE__->setup in $module\n" if !$setup;
+ my $auth_doc = PPI::Document->new(\(Catalyst::Helper->get_file(__PACKAGE__, 'auth_conf')));
+ my $auth_conf = $auth_doc->find_first('PPI::Statement');
+ # can't get this working, so we'll cope with cosmetic uglyness
+ # my $space = PPI::Document->new(\"\n")->find_first('PPI::Token::Whitespace');
+ # $setup->insert_before($space);
+ # my $sib = $setup->previous_sibling;
+ $setup->insert_before($auth_conf);
+ $doc->save($module);
+}
+
+sub _find_setup {
+ my ($element, $search) = @_;
+ if ( $element->isa('PPI::Statement')
+ && $element =~ /setup.*?;/
+ ) {
+ return 1;
+ }
+ return 0;
+}
+
+sub _get_ppi {
+ my $app_name = app_name() || 'TestApp';
+ my @path = split /::/, $app_name;
+ my $app_path = join '/', @path;
+ my $module = "lib/$app_path.pm";
+ my $doc = PPI::Document->new($module);
+ return ($module, $doc);
+}
+
+=head2 write_templates()
+
+make the login, logout and unauth templates
+
+=cut
+
+sub write_templates {
+ my $helper = Catalyst::Helper->new();
+ my $login = $helper->get_file(__PACKAGE__, 'login.tt');
+ my $logout = $helper->get_file(__PACKAGE__, 'logout.tt');
+ my $unauth = $helper->get_file(__PACKAGE__, 'unauth.tt');
+ $helper->mk_dir("root/auth");
+ $helper->mk_file("root/auth/login.tt", $login);
+ $helper->mk_file("root/auth/logout.tt", $logout);
+ $helper->mk_file("root/auth/unauth.tt", $unauth);
+}
+
+=head2 update_makefile()
+
+Adds the auth and session dependencies to Makefile.PL
+
+=cut
+
+sub update_makefile {
+ my $deps = Catalyst::Helper->get_file(__PACKAGE__, 'requires');
+ my $doc = PPI::Document->new('Makefile.PL');
+ my $find = PPI::Find->new( \&_find_install_script );
+ my ($found) = $find->in($doc);
+ croak "There's something wrong with your Makefile.PL so we can't continue (can't find the install_script directive\n" if ! $found;
+ my $install_script = $found->find_first('PPI::Token::Word');
+ my $install_script_str = scalar($install_script);
+ $install_script->set_content($deps . "\n" . $install_script_str);
+ $doc->save('Makefile.PL')
+}
+
+sub _find_install_script {
+ my ($element, $search) = @_;
+ if ($element->isa('PPI::Statement')
+ && $element =~ 'install_script') {
+ return 1;
+ }
+ return 0;
+}
+
+
+=head2 BUGS
+
+This is experimental, fairly rough code. It's a proof of concept for
+helper modules for Catalyst that need to alter the application
+configuration, Makefile.PL and other parts of the application. Bug
+reports, and patches are encouraged. Report bugs or provide patches
+to http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Helper-AuthDBIC.
+
+=head2 AUTHOR
+
+Kieren Diment <zarquon at cpan.org>
+
+
+=head1 COPYRIGHT AND LICENCE
+
+Copyright (c) 2008 Kieren Diment
+
+This library is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+See L<http://www.perl.com/perl/misc/Artistic.html>
+
+=cut
+
+1;
+
+__DATA__
+
+=begin pod_to_ignore
+
+__auth_controller__
+package [% app_name %]::Controller::Auth;
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller';
+
+sub index :Path :Args(0) {
+ my ($self, $c) = @_;
+ $c->detach('get_login');
+}
+
+sub get_login : Local {
+ my ($self, $c) = @_;
+ $c->stash->{destination} = $c->req->path;
+ $c->stash->{template} = 'auth/login.tt';
+}
+
+sub logout : Local {
+ my ( $self, $c ) = @_;
+ $c->logout;
+ $c->stash->{template} = 'auth/logout.tt';
+}
+
+sub login : Local {
+ my ( $self, $c ) = @_;
+ my $user = $c->req->params->{user};
+ my $password = $c->req->params->{password};
+ $c->flash->{destination} = $c->req->params->{destination} || $c->req->path;
+ $c->stash->{remember} = $c->req->params->{remember};
+ if ( $user && $password ) {
+ if ( $c->authenticate( { username => $user,
+ password => $password } ) ) {
+ $c->{session}{expires} = 999999999999 if $c->req->params->{remember};
+ $c->res->redirect($c->uri_for($c->flash->{destination}));
+ }
+ else {
+ # login incorrect
+ $c->stash->{message} = 'Invalid user and/or password';
+ $c->stash->{template} = 'auth/login.tt';
+ }
+ }
+ else {
+ # invalid form input
+ $c->stash->{message} = 'invalid form input';
+ $c->stash->{template} = 'auth/login.tt';
+ }
+}
+
+sub unauthorized : Private {
+ my ($self, $c) = @_;
+ $c->stash->{template}= 'auth/unauth.tt';
+}
+
+1;
+
+=head1 NAME
+
+[% app_name %]Controller::Auth
+
+=head2 SUMMARY
+
+This is a controller to provide simple authentication provided by
+Catalyst::Helper::AuthDBIC. The database schema provided by the Helper
+will also provide autheorization facilities. As an example, If you
+wanted to use this controller to provide application wide requirement
+for login you would put something like the following in
+MyApp::Controller::Root:
+
+ sub auto : Private {
+ my ( $self, $c) = @_;
+ if ( !$c->user && $c->req->path !~ /^auth.*?login/) {
+ $c->forward('[% app_name %]::Controller::Auth');
+ return 0;
+ }
+ return 1;
+ }
+
+
+__auth_conf__
+ __PACKAGE__->config( authentication => {
+ 'default_realm' => 'users',
+ 'realms' => {
+ 'users' => {
+ 'store' => {
+ 'role_column' => 'role_text',
+ 'user_class' => 'AuthSchema::User',
+ 'class' => 'DBIx::Class',
+ },
+ 'credential' => {
+ 'password_type' => 'hashed',
+ 'password_field' => 'password',
+ 'password_hash_type' => 'SHA-1',
+ 'class' => 'Password'
+ }
+ }
+ },
+});
+
+__digest__
+ __PACKAGE__->digestcolumns(
+ columns => [qw/ password /],
+ algorithm => 'SHA-1',
+ encoding => 'base64',
+ auto => 1,
+);
+
+__requires__
+requires 'Catalyst::Plugin::Authentication';
+requires 'Catalyst::Plugin::Authorization::Roles';
+requires 'Catalyst::Plugin::Session';
+requires 'Catalyst::Plugin::Session::State::Cookie';
+requires 'Catalyst::Plugin::Session::Store::FastMmap';
+requires 'Catalyst::Plugin::Authentication::Store::DBIC';
+requires 'Digest::SHA1';
+__login.tt__
+<h1> Please login</h1>
+[% IF c.stash.message != '' %] <h2 style='color:red'> [% c.stash.message %] </h2
+> [% END %]
+<form name="login" method='post' action='[% c.uri_for('/auth/login') %]'>
+User: <input name='user' type='text' /><br />
+Password: <input name='password' type='password' /><br />
+<input type='checkbox' name='remember' >Remember me</input> <br />
+<input type='hidden' value='[% c.flash.destination %]' />
+<input type='submit' name='Log In' /> <input type='reset' name='Reset' />
+</form>
+
+__logout.tt__
+<h1> Logout successful</h1>
+<a href='[% c.uri_for('/') %]'>Return to home page</a>
+__unauth.tt__
+<h1> [%c.user.id %]: You are not allowed to view this page.</h1>
+You can <a href="[% c.req.referrer %]">go back</a> where you came from, or <a h
+ref="[% c.uri_for('/auth/logout') %]">logout</a> and try logging in again as a d
+ifferent user. If you think this is an error, please contact <a href="mailto:[%
+c.config.admin %]">[% c.config.admin %]</a>
+
Added: Catalyst-Helper-AuthDBIC/script/auth_bootstrap.pl
===================================================================
--- Catalyst-Helper-AuthDBIC/script/auth_bootstrap.pl (rev 0)
+++ Catalyst-Helper-AuthDBIC/script/auth_bootstrap.pl 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Catalyst::Helper::AuthDBIC;
+
+=head1 NAME
+
+auth_bootstrap.pl
+
+=head1 Summary
+
+Run with no arguments in the root directory of a catalyst application
+to bootstrap a catalyst application. This uses
+Catalyst::Helper::AuthDBIC to do so. This is an experiemntal module,
+and you are urged to back up your application before using this
+script. At present there are no options to pass on to the script.
+
+=cut
+
+Catalyst::Helper::AuthDBIC::make_model();
+Catalyst::Helper::AuthDBIC::mk_auth_controller();
+Catalyst::Helper::AuthDBIC::add_plugins();
+Catalyst::Helper::AuthDBIC::add_config();
+Catalyst::Helper::AuthDBIC::write_templates();
+Catalyst::Helper::AuthDBIC::update_makefile();
Added: Catalyst-Helper-AuthDBIC/t/00-load.t
===================================================================
--- Catalyst-Helper-AuthDBIC/t/00-load.t (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/00-load.t 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,6 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More tests => 1;
+use ok 'Catalyst::Helper::AuthDBIC';
Property changes on: Catalyst-Helper-AuthDBIC/t/00-load.t
___________________________________________________________________
Name: svn:mime-type
+ text/script
Added: Catalyst-Helper-AuthDBIC/t/01-functions.t
===================================================================
--- Catalyst-Helper-AuthDBIC/t/01-functions.t (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/01-functions.t 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More qw/no_plan/;;
+use ok 'Catalyst::Helper::AuthDBIC';
+use FindBin qw/$Bin/;
+my $app_dir = "$Bin/lib/";
+my $cwd = $ENV{PWD};
+chdir("$app_dir");
+my $app_name = Catalyst::Helper::AuthDBIC->app_name();
+ok($app_name eq 'TestApp', 'got app name');
+
+ok(Catalyst::Helper::AuthDBIC->make_model(), "model made ok");
+ok(-e ("$app_dir/db/auth.db"), "db file made ok");
+
+# clean up
+
+unlink "$app_dir/db/auth.db";
+rmdir "$app_dir/db";
Property changes on: Catalyst-Helper-AuthDBIC/t/01-functions.t
___________________________________________________________________
Name: svn:mime-type
+ text/script
Added: Catalyst-Helper-AuthDBIC/t/author/pod-coverage.t
===================================================================
--- Catalyst-Helper-AuthDBIC/t/author/pod-coverage.t (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/author/pod-coverage.t 2008-08-20 21:50:36 UTC (rev 8236)
@@ -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: Catalyst-Helper-AuthDBIC/t/author/pod.t
===================================================================
--- Catalyst-Helper-AuthDBIC/t/author/pod.t (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/author/pod.t 2008-08-20 21:50:36 UTC (rev 8236)
@@ -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: Catalyst-Helper-AuthDBIC/t/lib/Makefile.PL
===================================================================
--- Catalyst-Helper-AuthDBIC/t/lib/Makefile.PL (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/lib/Makefile.PL 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1 @@
+name 'TestApp';
Added: Catalyst-Helper-AuthDBIC/t/lib/TestApp/Controller/Root.pm
===================================================================
--- Catalyst-Helper-AuthDBIC/t/lib/TestApp/Controller/Root.pm (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/lib/TestApp/Controller/Root.pm 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,12 @@
+package TestApp::Controller::Root;
+use strict;
+use warnings;
+
+__PACKAGE__->config(namespace => q{});
+
+use base 'Catalyst::Controller';
+
+# your actions replace this one
+sub main :Path { $_[1]->res->body('<h1>It works</h1>') }
+
+1;
Added: Catalyst-Helper-AuthDBIC/t/lib/TestApp/Model/.gitignore
===================================================================
Added: Catalyst-Helper-AuthDBIC/t/lib/TestApp.pm
===================================================================
--- Catalyst-Helper-AuthDBIC/t/lib/TestApp.pm (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/lib/TestApp.pm 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,12 @@
+package TestApp;
+use strict;
+use warnings;
+
+use parent qw/Catalyst/;
+use Catalyst qw/-Debug
+ ConfigLoader
+ Static::Simple/;
+
+__PACKAGE__->setup;
+
+1;
Added: Catalyst-Helper-AuthDBIC/t/lib/db/auth.db,"",""
===================================================================
Added: Catalyst-Helper-AuthDBIC/t/lib/db/auth.db,,
===================================================================
Added: Catalyst-Helper-AuthDBIC/t/lib/script/testapp_create.pl
===================================================================
--- Catalyst-Helper-AuthDBIC/t/lib/script/testapp_create.pl (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/lib/script/testapp_create.pl 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,74 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+use Catalyst::Helper;
+
+my $force = 0;
+my $mech = 0;
+my $help = 0;
+
+GetOptions(
+ 'nonew|force' => \$force,
+ 'mech|mechanize' => \$mech,
+ 'help|?' => \$help
+ );
+
+pod2usage(1) if ( $help || !$ARGV[0] );
+
+my $helper = Catalyst::Helper->new( { '.newfiles' => !$force, mech => $mech } );
+
+pod2usage(1) unless $helper->mk_component( 'TestApp', @ARGV );
+
+1;
+
+=head1 NAME
+
+testapp_create.pl - Create a new Catalyst Component
+
+=head1 SYNOPSIS
+
+testapp_create.pl [options] model|view|controller name [helper] [options]
+
+ Options:
+ -force don't create a .new file where a file to be created exists
+ -mechanize use Test::WWW::Mechanize::Catalyst for tests if available
+ -help display this help and exits
+
+ Examples:
+ testapp_create.pl controller My::Controller
+ testapp_create.pl -mechanize controller My::Controller
+ testapp_create.pl view My::View
+ testapp_create.pl view MyView TT
+ testapp_create.pl view TT TT
+ testapp_create.pl model My::Model
+ testapp_create.pl model SomeDB DBIC::Schema MyApp::Schema create=dynamic\
+ dbi:SQLite:/tmp/my.db
+ testapp_create.pl model AnotherDB DBIC::Schema MyApp::Schema create=static\
+ dbi:Pg:dbname=foo root 4321
+
+ See also:
+ perldoc Catalyst::Manual
+ perldoc Catalyst::Manual::Intro
+
+=head1 DESCRIPTION
+
+Create a new Catalyst Component.
+
+Existing component files are not overwritten. If any of the component files
+to be created already exist the file will be written with a '.new' suffix.
+This behavior can be suppressed with the C<-force> option.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri at oook.de>
+Maintained by the Catalyst Core Team.
+
+=head1 COPYRIGHT
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
Property changes on: Catalyst-Helper-AuthDBIC/t/lib/script/testapp_create.pl
___________________________________________________________________
Name: svn:executable
+ *
Added: Catalyst-Helper-AuthDBIC/t/lib/script/testapp_server.pl
===================================================================
--- Catalyst-Helper-AuthDBIC/t/lib/script/testapp_server.pl (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/lib/script/testapp_server.pl 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,121 @@
+#!/usr/bin/env perl
+
+BEGIN {
+ $ENV{CATALYST_ENGINE} ||= 'HTTP';
+ $ENV{CATALYST_SCRIPT_GEN} = 31;
+ require Catalyst::Engine::HTTP;
+}
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+use FindBin;
+use lib "$FindBin::Bin/..";
+
+my $debug = 0;
+my $fork = 0;
+my $help = 0;
+my $host = undef;
+my $port = 3000;
+my $keepalive = 0;
+my $restart = 0;
+my $restart_delay = 1;
+my $restart_regex = '\.yml$|\.yaml$|\.pm$';
+my $restart_directory = undef;
+my $background = 0;
+my $pidfile = "/tmp/testapp.pid";
+
+my @argv = @ARGV;
+
+GetOptions(
+ 'debug|d' => \$debug,
+ 'fork' => \$fork,
+ 'help|?' => \$help,
+ 'host=s' => \$host,
+ 'port=s' => \$port,
+ 'keepalive|k' => \$keepalive,
+ 'restart|r' => \$restart,
+ 'restartdelay|rd=s' => \$restart_delay,
+ 'restartregex|rr=s' => \$restart_regex,
+ 'restartdirectory=s' => \$restart_directory,
+ 'daemon' => \$background,
+ 'pidfile=s' => \$pidfile,
+);
+
+pod2usage(1) if $help;
+
+if ( $restart ) {
+ $ENV{CATALYST_ENGINE} = 'HTTP::Restarter';
+}
+if ( $debug ) {
+ $ENV{CATALYST_DEBUG} = 1;
+}
+
+# This is require instead of use so that the above environment
+# variables can be set at runtime.
+require TestApp;
+
+TestApp->run( $port, $host, {
+ argv => \@argv,
+ 'fork' => $fork,
+ keepalive => $keepalive,
+ restart => $restart,
+ restart_delay => $restart_delay,
+ restart_regex => qr/$restart_regex/,
+ restart_directory => $restart_directory,
+ background => $background,
+ pidfile => $pidfile,
+} );
+
+1;
+
+=head1 NAME
+
+testapp_server.pl - Catalyst Testserver
+
+=head1 SYNOPSIS
+
+testapp_server.pl [options]
+
+ Options:
+ -d -debug force debug mode
+ -f -fork handle each request in a new process
+ (defaults to false)
+ -? -help display this help and exits
+ -host host (defaults to all)
+ -p -port port (defaults to 3000)
+ -k -keepalive enable keep-alive connections
+ -r -restart restart when files get modified
+ (defaults to false)
+ -rd -restartdelay delay between file checks
+ -rr -restartregex regex match files that trigger
+ a restart when modified
+ (defaults to '\.yml$|\.yaml$|\.pm$')
+ -restartdirectory the directory to search for
+ modified files
+ (defaults to '../')
+
+ -daemon background the server
+ -pidfile=filename store the pid if the server in filename, if
+ daemonizing
+
+ See also:
+ perldoc Catalyst::Manual
+ perldoc Catalyst::Manual::Intro
+
+=head1 DESCRIPTION
+
+Run a Catalyst Testserver for this application.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri at oook.de>
+Maintained by the Catalyst Core Team.
+
+=head1 COPYRIGHT
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
Property changes on: Catalyst-Helper-AuthDBIC/t/lib/script/testapp_server.pl
___________________________________________________________________
Name: svn:mime-type
+ text/script
Added: Catalyst-Helper-AuthDBIC/t/lib/script/testapp_test.pl
===================================================================
--- Catalyst-Helper-AuthDBIC/t/lib/script/testapp_test.pl (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/lib/script/testapp_test.pl 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,12 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/..";
+use Catalyst::Test 'TestApp';
+
+print request($ARGV[0])->content . "\n";
+
+1;
Property changes on: Catalyst-Helper-AuthDBIC/t/lib/script/testapp_test.pl
___________________________________________________________________
Name: svn:mime-type
+ text/script
Added: Catalyst-Helper-AuthDBIC/t/live-test.t
===================================================================
--- Catalyst-Helper-AuthDBIC/t/live-test.t (rev 0)
+++ Catalyst-Helper-AuthDBIC/t/live-test.t 2008-08-20 21:50:36 UTC (rev 8236)
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+# setup library path
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+
+# make sure testapp works
+use ok 'TestApp';
+
+# a live test against TestApp, the test application
+use Test::WWW::Mechanize::Catalyst 'TestApp';
+my $mech = Test::WWW::Mechanize::Catalyst->new;
+$mech->get_ok('http://localhost/', 'get main page');
+$mech->content_like(qr/it works/i, 'see if it has our text');
+
Property changes on: Catalyst-Helper-AuthDBIC/t/live-test.t
___________________________________________________________________
Name: svn:mime-type
+ text/script
More information about the Catalyst-commits
mailing list