[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] CGI::App Generator


Hi Jason,

This is a great start!  I really like that you are targeting CPAN-style
modules and including a test framework right from the start.

On IRC I rambled for a bit about Module::Build vs. ExtUtils::MakeMaker.
Here are some more concrete thoughts.

Both systems have good support for Perl module files that will
(a) eventually go into your site_perl lib directory, (b) will be owned
by root and (c) will be read onlly.  Beyond that, you have to write your
own installation code.

However, Module::Build allows you to create your own hooks for different
types of files.  For CAF, we built a Module::Build-based installer to
install files into cgi-bin, htdocs and other user-specified directories.
We also install user-editable templates and example Perl modules.  The
permissions are set according to questions that the user answers at the
beginning of the install process.

To follow along with this explanation, you can download the whole CAF
distribution at:

   http://www.occamstoothbrush.com/caf/CGI-Application-Framework-0.20_7.tar.gz

Alternately, I've made the M::B build files (temporarily) available at:

   http://www.occamstoothbrush.com/caf/build/

So you can look at the source online.  The key files are:

    Build.PL
    CAF_MB_Installer.pm


I think the custom stuff we put into the CAF installer will be useful
for other web projects.  For a typical web project, you need to apply
special processing rules to different kinds of files.  Consider:

  - different files need to be copied into different target directories
  - some files need to be owned by the webserver user
  - most files need to be writable
  - some files need their shbang lines fixed up
  - some need content changes, e.g.
    - fixing a path in a config file
    - adding a unique id (md5 hash) to a config file
    - adding some other user or system specific stuff to files
    (for CAF we use HTML::Template to make content changes)


For CAF we separate the different kinds of files into different
directories:

    caf_cgi
    caf_config
    caf_htdoc
    caf_image
    caf_project
    caf_server
    caf_sql

We then register these as Module::Build 'build elements', so that we can
handle each group of files differently (e.g. different target directory
or different permissions, etc.).


Here are the steps the installer goes through:

   $ perl Build.PL
     - Ask user questions about paths, users, etc.
     - store the user's answers in $builder->notes
     - register the custom caf_* 'build elements'

   $ ./Build
     - the system copies lib files and custom build elements into blib/
       - copy files from caf_* into blib/caf_*
       - do custom content processing, e.g.
         - fix up shbang lines
         - process files through HTML::Template

   $ ./Build test
     - run the tests in t/

   $ ./Build install
     - the system copies files from blib into the user's target
       directories and fixes file ownership and permissions.


The "Build install" step is often run as root (or via sudo).  The other
steps aren't.  So any custom installation and permission changing should
happen during the "Build install" stage.

To hook into the "Build" step, we override 'process_files_by_extension',
and do our custom content processing there.

To hook into the "Build install" stage, we override Module::Build's
ACTION_install.  We first call Module::Build's own ACTION_install (to
install the Perl library files into lib/site_perl), and then we do our
own installation:

     sub ACTION_install {
        my $self = shift;
        $self->SUPER::ACTION_install(@_);

        my $user  = $self->notes('examples_user_num');
        my $group = $self->notes('examples_group_num');

        $self->caf_install_example_files($self->caf_install_map, 1, $user, $group);

        $self->caf_fix_server_directories;
     }


The caf_install_example_files method here is basically stolen from
ExtUtils::Install::install, except (a) it allows you to specify the user
and group ownership of the final files and directories, and (b) it
doesn't try to make the files read only.  It would be nice if these
features eventually made it back into the ExtUtils package.


Okay, after all that, as we all know, on IRC recently hide pointed us to
App::Build, which seems to do a lot of the same things as the CAF
installer.

When I get the time, I'm going to try rewriting the CAF installer in
App::Build and see what happens.

But if someone wants to take a stab at making a general-purpose "web-enabled"
CPAN installer for Perl (either via App::Build or just Module::Build), I
think it will be an excellent project and be *very* useful to the Perl
community.  I will try to get around to it eventually, but someone
please feel free to beat me to it!


Michael


--
Michael Graham <suppressed>



---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.