[Jifty-commit] r1040 - in jifty/trunk: lib/Jifty/Script

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri May 12 18:09:25 EDT 2006


Author: alexmv
Date: Fri May 12 18:09:20 2006
New Revision: 1040

Added:
   jifty/trunk/lib/Jifty/Script/Plugin.pm
Modified:
   jifty/trunk/   (props changed)

Log:
 r12970 at zoq-fot-pik:  chmrr | 2006-05-12 18:09:12 -0400
  * jifty plugin --name Something


Added: jifty/trunk/lib/Jifty/Script/Plugin.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Script/Plugin.pm	Fri May 12 18:09:20 2006
@@ -0,0 +1,149 @@
+use warnings;
+use strict;
+
+package Jifty::Script::Plugin;
+use base qw'App::CLI::Command Class::Accessor::Fast';
+
+use File::Copy;
+use Jifty::Config;
+use Jifty::YAML;
+use File::Basename;
+
+__PACKAGE__->mk_accessors(qw/prefix dist_name mod_name lib_dir/);
+
+
+=head1 NAME
+
+Jifty::Script::Plugin - Create the skeleton of a Jifty plugin
+
+=head1 DESCRIPTION
+
+Creates a skeleton of a new L<Jifty::Plugin>.
+
+=head2 options
+
+This script only takes one option, C<--name>, which is required; it is
+the name of the plugin to create; this will be prefixed with
+C<Jifty::Plugin::> automatically.  Jifty will create a directory with
+that name, and place all of the files it creates inside that
+directory.
+
+=cut
+
+sub options {
+    (
+     'n|name=s' => 'name',
+    )
+}
+
+=head2 run
+
+Create a directory for the application, a skeleton directory
+structure, and a C<Makefile.PL> for you application.
+
+=cut
+
+sub run {
+    my $self = shift;
+
+    $self->prefix( $self->{name} ||''); 
+
+    unless ($self->prefix =~ /\w+/ ) { die "You need to give your new Jifty app a --name"."\n";}
+    $self->prefix( $self->prefix );
+
+    # Turn my-plugin-name into My::Plugin::Name.
+    $self->mod_name ("Jifty::Plugin::" . join ("::", map { ucfirst } split (/\-/, $self->prefix)));
+    $self->dist_name("Jifty-Plugin-".$self->prefix);
+    $self->lib_dir(join("/",grep{$_} split '::', $self->mod_name));
+
+    print("Creating new plugin ".$self->mod_name."\n");
+    $self->_make_directories();
+    $self->_write_makefile();
+    $self->_write_default_files();
+}
+
+sub _write_makefile {
+    my $self = shift;
+    my $prefix = $self->prefix;
+    # Write a makefile
+    open(MAKEFILE, ">$prefix/Makefile.PL") or die "Can't write Makefile.PL: $!";
+    print MAKEFILE <<"EOT";
+use inc::Module::Install;
+name('@{[$self->dist_name]}');
+version('0.01');
+requires('Jifty' => '@{[$Jifty::VERSION]}');
+
+install_share;
+
+WriteAll;
+EOT
+    close MAKEFILE;
+} 
+
+sub _write_default_files {
+    my $self = shift;
+    my $mod_name = $self->mod_name;
+    my $prefix = $self->prefix;
+    my $lib = $self->lib_dir;
+    open(PLUGIN, ">$prefix/lib/$lib.pm") or die "Can't write $prefix/$lib.pm: $!";
+    print PLUGIN <<"EOT";
+use strict;
+use warnings;
+
+package $mod_name;
+use base qw/Jifty::Plugin/;
+
+# Your plugin goes here.  If takes any configuration or arguments, you
+# probably want to override L<Jifty::Plugin/init>.
+
+1;
+EOT
+    close PLUGIN;
+
+    open(DISPATCHER, ">$prefix/lib/$lib/Dispatcher.pm") or die "Can't write $prefix/lib/$lib/Dispatcher.pm: $!";
+    print DISPATCHER <<"EOT";
+use strict;
+use warnings;
+
+package @{[$mod_name]}::Dispatcher;
+use Jifty::Dispatcher -base;
+
+# Put any plugin-specific dispatcher rules here.
+
+EOT
+}
+
+sub _make_directories {
+    my $self = shift;
+
+    mkdir($self->prefix);
+    my @dirs = qw( lib );
+    my @dir_parts = split('/',$self->lib_dir);
+    push @dirs, join('/', 'lib', @dir_parts[0..$_]) for 0.. at dir_parts-1;
+
+    @dirs = (@dirs, $self->_directories); 
+
+    foreach my $dir (@dirs) {
+        $dir =~ s/__APP__/$self->lib_dir/e;
+        print("Creating directory $dir\n");
+        mkdir( $self->prefix."/$dir") or die "Can't create ". $self->prefix."/$dir: $!";
+    }
+}
+
+sub _directories {
+    return qw(
+        doc
+        share
+        share/po
+        share/web
+        share/web/templates
+        share/web/static
+        lib/__APP__/Model
+        lib/__APP__/Action
+        t
+    );
+}
+
+
+1;
+


More information about the Jifty-commit mailing list