Catalyst-Helper-AuthDBIC
view release on metacpan or search on metacpan
lib/Catalyst/Helper/AuthDBIC.pm view on Meta::CPAN
=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 sub 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 sub add_user_helper()
A little script to add a user to the database.
=cut
sub add_user_helper {
my $helper = Catalyst::Helper->new;
my $app_prefix = Catalyst::Utils::appprefix(app_name());
my $script_dir = File::Spec->catdir( '.', 'script' );
my $script = "$script_dir\/$app_prefix\_auth_admin.pl";
my $startperl = "#!$Config{perlpath} -w";
$DB::single=1;
$helper->render_file('auth_admin',
$script,
{ start_perl => $startperl,
appprefix => $app_prefix,
startperl => $startperl,
app_name => app_name(),
});
chmod 0700, $script;
}
=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@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};
( run in 0.574 second using v1.01-cache-2.11-cpan-39bf76dae61 )