From: Sebastian Riedel Date: Wed, 20 Apr 2005 17:19:35 +0000 (+0000) Subject: Big change, new installer and home detection X-Git-Tag: 5.7099_04~1463 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=4f6748f101647dd3344339b19510947df6836412 Big change, new installer and home detection --- diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..28127f0 --- /dev/null +++ b/Build.PL @@ -0,0 +1,47 @@ +use strict; +use Module::Build; + +my $build = Module::Build->new( + create_makefile_pl => 'passthrough', + license => 'perl', + module_name => 'Catalyst', + requires => { + 'UNIVERSAL::require' => 0, + 'CGI::Simple' => 0, + 'Class::Accessor::Fast' => 0, + 'Class::Data::Inheritable' => 0, + 'HTTP::Daemon' => 0, + 'HTML::Entities' => 0, + 'HTTP::Headers' => 0, + 'HTTP::Request' => 0, + 'HTTP::Response' => 0, + 'LWP::UserAgent' => 0, + 'Module::Pluggable::Fast' => 0, + 'Path::Class' => 0, + 'Template' => 0, + 'Text::ASCIITable' => 0, + 'Tree::Simple' => 0, + 'Tree::Simple::Visitor::FindByPath' => 0, + 'URI' => 0, + }, + script_files => [ glob('script/*') ], + test_files => [ + glob('t/*.t'), glob('t/*/*.t'), glob('t/*/*/*.t'), glob('t/*/*/*/*.t') + ] +); +$build->create_build_script; + +print( '*' x 80, "\n" ); +print( + (qw/chansen draven fordmason naughton sri the_jester/)[ int( rand(6) ) ], + " is the greatest and gabb is ", + ( (localtime)[2] > 12 ? "drunk" : "hung over" ), + " again!\n" +); +print( '*' x 80, "\n" ); + +eval "use mod_perl; use Apache::Request"; +print qq/Install "mod_perl" and "Apache::Request" for Apache support.\n/ if $@; + +eval "use FCGI"; +print qq/Install "FCGI" for FastCGI support.\n/ if $@; diff --git a/Changes b/Changes index 25d07d5..3bfe327 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ This file documents the revision history for Perl extension Catalyst. +5.10 Wed Apr 20 18:00:00 2005 + - New installer for templates and stuff using Module::Build + - scripts are now prefixed, for being installable + IMPORTANT: You have to regenerate the script directory, + remove Makefile.PL and add Build.PL + 5.03 Tue Apr 19 20:35:00 2005 (Revision 462) - Fixed Test example (Torsten Seeman) - Added Plugins chapter to manual diff --git a/MANIFEST b/MANIFEST index fd628d0..f246285 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,6 +1,7 @@ Changes lib/Catalyst.pm lib/Catalyst/Base.pm +lib/Catalyst/Build.pm lib/Catalyst/Dispatcher.pm lib/Catalyst/Engine.pm lib/Catalyst/Engine/Apache.pm diff --git a/Makefile.PL b/Makefile.PL index b89c815..4606ed3 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -16,6 +16,7 @@ WriteMakefile( HTTP::Response => 0, LWP::UserAgent => 0, Module::Pluggable::Fast => 0, + Path::Class => 0, Template => 0, Text::ASCIITable => 0, Tree::Simple => 0, diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 0f7cd81..f327932 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -5,11 +5,12 @@ use base 'Catalyst::Base'; use UNIVERSAL::require; use Catalyst::Log; use Text::ASCIITable; -our $CATALYST_SCRIPT_GEN = 2; +use Path::Class; +our $CATALYST_SCRIPT_GEN = 3; __PACKAGE__->mk_classdata($_) for qw/dispatcher engine log/; -our $VERSION = '5.03'; +our $VERSION = '5.10'; our @ISA; =head1 NAME @@ -239,6 +240,28 @@ sub import { } $caller->engine($engine); $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug; + + # Find home + my $name = $caller; + $name =~ s/\:\:/\//g; + my $path = $INC{"$name.pm"}; + my $home = file($path)->absolute->dir; + $name =~ /(\w+)$/; + my $append = $1; + my $subdir = dir($home)->subdir($append); + for ( split '/', $name ) { $home = dir($home)->parent } + if ( $home =~ /blib$/ ) { $home = dir($home)->parent } + elsif ( !-f file( $home, 'Build.PL' ) ) { $home = $subdir } + + if ( $caller->debug ) { + $home + ? ( -d $home ) + ? $caller->log->debug(qq/Found home "$home"/) + : $caller->log->debug(qq/Home "$home" doesn't exist/) + : $caller->log->debug(q/Couldn't find home/); + } + $caller->config->{home} = $home; + $caller->config->{root} = dir($home)->subdir('root'); } =item $c->engine @@ -329,8 +352,8 @@ Sebastian Riedel, C Andy Grundman, Andrew Ford, Andrew Ruthven, Autrijus Tang, Christian Hansen, Christopher Hicks, Dan Sully, Danijel Milicevic, David Naughton, -Gary Ashton Jones, Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, -Tatsuhiko Miyagawa and all the others who've helped. +Gary Ashton Jones, Jesse Sheidlower, Johan Lindstrom, Leon Brocard, +Marcus Ramberg, Tatsuhiko Miyagawa and all the others who've helped. =head1 LICENSE diff --git a/lib/Catalyst/Base.pm b/lib/Catalyst/Base.pm index 04a2153..ec25476 100644 --- a/lib/Catalyst/Base.pm +++ b/lib/Catalyst/Base.pm @@ -6,8 +6,8 @@ use Catalyst::Utils; use NEXT; __PACKAGE__->mk_classdata($_) for qw/_attrcache _cache _config/; -__PACKAGE__->_cache( [] ); __PACKAGE__->_attrcache( {} ); +__PACKAGE__->_cache( [] ); # note - see attributes(3pm) sub MODIFY_CODE_ATTRIBUTES { diff --git a/lib/Catalyst/Build.pm b/lib/Catalyst/Build.pm new file mode 100644 index 0000000..c314ad8 --- /dev/null +++ b/lib/Catalyst/Build.pm @@ -0,0 +1,104 @@ +package Catalyst::Build; + +use strict; +use Module::Build; +use base 'Module::Build'; +use Path::Class; +use File::Find 'find'; + +our $FAKE; +our $ignore = '^(' + . join( '|', + qw/Build Build.PL Changes Makefile.PL README _build blib lib script t/ ) + . ')$'; + +=head1 NAME + +Catalyst::Build - Module::Build extension for Catalyst + +=head1 SYNOPSIS + +See L + +=head1 DESCRIPTION + +L extension for Catalyst. + +=head1 METHODS + +=item ACTION_install + +=cut + +sub ACTION_install { + my $self = shift; + $self->SUPER::ACTION_install; + $self->ACTION_install_extras; +} + +=item ACTION_fakeinstall + +=cut + +sub ACTION_fakeinstall { + my $self = shift; + $self->SUPER::ACTION_fakeinstall; + local $FAKE = 1; + $self->ACTION_install_extras; +} + +=item ACTION_install_extras + +=cut + +sub ACTION_install_extras { + my $self = shift; + my $prefix = $self->{properties}{destdir} || ''; + my $path = dir( + $prefix, + $self->{config}{installsitelib}, + split( '::', $self->{properties}{module_name} ) + ); + my @files = $self->_find_extras; + print "Installing extras to $path\n"; + for (@files) { + $FAKE + ? print "$_ -> $path/$_ (FAKE)\n" + : $self->copy_if_modified( $_, $path ); + } +} + +sub _find_extras { + my $self = shift; + my @all = glob '*'; + my @files; + for my $file (@all) { + next if $file =~ /$ignore/; + if ( -d $file ) { + find( + sub { + return if -d; + push @files, $File::Find::name; + }, + $file + ); + } + else { push @files, $file } + } + return @files; +} + +=back + +=head1 AUTHOR + +Sebastian Riedel, C + +=head1 LICENSE + +This library is free software . You can redistribute it and/or modify it under +the same terms as perl itself. + +=cut + +1; diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index ccf766f..8af4a13 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -60,12 +60,15 @@ sub mk_app { $self->{name} = $name; $self->{dir} = $name; $self->{dir} =~ s/\:\:/-/g; + $self->{appprefix} = lc $self->{dir}; + $self->{appprefix} =~ s/-/_/g; $self->{startperl} = $Config{startperl}; - $self->{scriptgen}=$Catalyst::CATALYST_SCRIPT_GEN; - $self->{author}=$self->{author} = $ENV{'AUTHOR'} || - @{[getpwuid($<)]}[6]; + $self->{scriptgen} = $Catalyst::CATALYST_SCRIPT_GEN; + $self->{author} = $self->{author} = $ENV{'AUTHOR'} + || @{ [ getpwuid($<) ] }[6]; $self->_mk_dirs; $self->_mk_appclass; + $self->_mk_build; $self->_mk_makefile; $self->_mk_readme; $self->_mk_changes; @@ -89,8 +92,8 @@ sub mk_component { my $self = shift; my $app = shift; $self->{app} = $app; - $self->{author}=$self->{author} = $ENV{'AUTHOR'} || - @{[getpwuid($<)]}[6]; + $self->{author} = $self->{author} = $ENV{'AUTHOR'} + || @{ [ getpwuid($<) ] }[6]; $self->{base} = File::Spec->catdir( $FindBin::Bin, '..' ); unless ( $_[0] =~ /^model|m|view|v|controller|c\$/i ) { my $helper = shift; @@ -270,6 +273,12 @@ sub _mk_appclass { $self->render_file( 'appclass', "$mod.pm" ); } +sub _mk_build { + my $self = shift; + my $dir = $self->{dir}; + $self->render_file( 'build', "$dir\/Build.PL" ); +} + sub _mk_makefile { my $self = shift; my $dir = $self->{dir}; @@ -300,36 +309,41 @@ sub _mk_apptest { sub _mk_cgi { my $self = shift; my $script = $self->{script}; - $self->render_file( 'cgi', "$script\/cgi.pl" ); - chmod 0700, "$script/cgi.pl"; + my $appprefix = $self->{appprefix}; + $self->render_file( 'cgi', "$script\/$appprefix\_cgi.pl" ); + chmod 0700, "$script/$appprefix\_cgi.pl"; } sub _mk_fcgi { my $self = shift; my $script = $self->{script}; - $self->render_file( 'fcgi', "$script\/fcgi.pl" ); - chmod 0700, "$script/fcgi.pl"; + my $appprefix = $self->{appprefix}; + $self->render_file( 'fcgi', "$script\/$appprefix\_fcgi.pl" ); + chmod 0700, "$script/$appprefix\_fcgi.pl"; } sub _mk_server { my $self = shift; my $script = $self->{script}; - $self->render_file( 'server', "$script\/server.pl" ); - chmod 0700, "$script/server.pl"; + my $appprefix = $self->{appprefix}; + $self->render_file( 'server', "$script\/$appprefix\_server.pl" ); + chmod 0700, "$script/$appprefix\_server.pl"; } sub _mk_test { my $self = shift; my $script = $self->{script}; - $self->render_file( 'test', "$script/test.pl" ); - chmod 0700, "$script/test.pl"; + my $appprefix = $self->{appprefix}; + $self->render_file( 'test', "$script/$appprefix\_test.pl" ); + chmod 0700, "$script/$appprefix\_test.pl"; } sub _mk_create { my $self = shift; my $script = $self->{script}; - $self->render_file( 'create', "$script\/create.pl" ); - chmod 0700, "$script/create.pl"; + my $appprefix = $self->{appprefix}; + $self->render_file( 'create', "$script\/$appprefix\_create.pl" ); + chmod 0700, "$script/$appprefix\_create.pl"; } sub _mk_compclass { @@ -433,18 +447,22 @@ it under the same terms as perl itself. 1; -__makefile__ -use ExtUtils::MakeMaker; - -WriteMakefile( - NAME => '[% name %]', - VERSION_FROM => 'lib/[% class %].pm', - PREREQ_PM => { Catalyst => 5 }, - test => { TESTS => join ' ', ( glob('t/*.t'), glob('t/*/*.t') ) } +__build__ +use strict; +use Catalyst::Build; + +my $build = Catalyst::Build->new( + create_makefile_pl => 'passthrough', + license => 'perl', + module_name => '[% name %]', + requires => { Catalyst => '5.04' }, + script_files => [ glob('script/*') ], + test_files => [ glob('t/*.t'), glob('t/*/*.t') ] ); +$build->create_build_script; __readme__ -Run script/server.pl to test the application. +Run script/[% apprefix %]_server.pl to test the application. __changes__ This file documents the revision history for Perl extension [% name %].