| 1 | package Module::Setup::Plugin; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | |
|---|
| 5 | use Path::Class; |
|---|
| 6 | use Scalar::Util qw(weaken); |
|---|
| 7 | |
|---|
| 8 | use Module::Setup::Flavor; |
|---|
| 9 | |
|---|
| 10 | sub new { |
|---|
| 11 | my($class, %args) = @_; |
|---|
| 12 | my $self = bless { %args }, $class; |
|---|
| 13 | weaken $self->{context}; |
|---|
| 14 | $self->register; |
|---|
| 15 | $self; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | sub register {} |
|---|
| 19 | |
|---|
| 20 | sub add_trigger { |
|---|
| 21 | my($self, @args) = @_; |
|---|
| 22 | $self->{context}->add_trigger(@args); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | sub append_template_file { |
|---|
| 26 | my($self, $context, $template_vars, $module_attribute) = @_; |
|---|
| 27 | my $caller = caller; |
|---|
| 28 | |
|---|
| 29 | my @template = Module::Setup::Flavor::loader($caller); |
|---|
| 30 | |
|---|
| 31 | for my $tmpl (@template) { |
|---|
| 32 | next unless exists $tmpl->{file}; |
|---|
| 33 | my $dist_path = Path::Class::File->new(@{ $module_attribute->{dist_path} }, $tmpl->{file}); |
|---|
| 34 | |
|---|
| 35 | my $options = { |
|---|
| 36 | dist_path => $dist_path, |
|---|
| 37 | template => $tmpl->{template}, |
|---|
| 38 | vars => $template_vars, |
|---|
| 39 | content => undef, |
|---|
| 40 | }; |
|---|
| 41 | $options->{chmod} = $tmpl->{chmod} if $tmpl->{chmod}; |
|---|
| 42 | $context->write_template($options); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | 1; |
|---|
| 47 | |
|---|
| 48 | __END__ |
|---|
| 49 | |
|---|
| 50 | =head1 NAME |
|---|
| 51 | |
|---|
| 52 | Module::Setup::Plugin - Module::Setup Plugin |
|---|
| 53 | |
|---|
| 54 | =head1 Trigger Point |
|---|
| 55 | |
|---|
| 56 | =head2 befor_dump_config $config |
|---|
| 57 | |
|---|
| 58 | config setup L<Module::Setup::Plugin::Config::Basic> |
|---|
| 59 | |
|---|
| 60 | =head2 after_setup_module_attribute |
|---|
| 61 | |
|---|
| 62 | module attribute setup L<Module::Setup::Plugin::VC::SVN> |
|---|
| 63 | |
|---|
| 64 | =head2 after_setup_template_vars |
|---|
| 65 | |
|---|
| 66 | template parameters setup |
|---|
| 67 | |
|---|
| 68 | =head2 append_template_file $template_vars, $module_attribute |
|---|
| 69 | |
|---|
| 70 | add module template file for new module L<Module::Setup::Plugin::VC::Git> |
|---|
| 71 | |
|---|
| 72 | =head2 template_process $options |
|---|
| 73 | |
|---|
| 74 | for template process L<Module::Setup::Plugin::Template> |
|---|
| 75 | |
|---|
| 76 | =head2 check_skeleton_directory $attributes |
|---|
| 77 | |
|---|
| 78 | for test L<Module::Setup::Plugin::Test::Makefile> |
|---|
| 79 | |
|---|
| 80 | $attributes = +{ |
|---|
| 81 | module_attribute => $module_attribute, |
|---|
| 82 | template_vars => $template_vars, |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 85 | =head2 after_create_skeleton $attributes |
|---|
| 86 | |
|---|
| 87 | aftter create_skeleton |
|---|
| 88 | |
|---|
| 89 | =head2 finalize_create_skeleton $attributes |
|---|
| 90 | |
|---|
| 91 | last trriger of run method |
|---|
| 92 | |
|---|
| 93 | =head1 Plugin Example |
|---|
| 94 | |
|---|
| 95 | ~/.module-setup/flavor/myflavor/plugins/plugin.pl |
|---|
| 96 | package MyFlavor::Plugin; |
|---|
| 97 | use strict; |
|---|
| 98 | use warnings; |
|---|
| 99 | use base 'Module::Setup::Plugin'; |
|---|
| 100 | |
|---|
| 101 | use Path::Class; |
|---|
| 102 | |
|---|
| 103 | sub register { |
|---|
| 104 | my($self, ) = @_; |
|---|
| 105 | $self->add_trigger( check_skeleton_directory => \&check_skeleton_directory ); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | sub check_skeleton_directory { |
|---|
| 109 | my $self = shift; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | ~/.module-setup/flavor/myflavor/config.yaml |
|---|
| 113 | |
|---|
| 114 | config: |
|---|
| 115 | plugins: |
|---|
| 116 | - Config::Basic |
|---|
| 117 | - VC::SVN |
|---|
| 118 | - Template |
|---|
| 119 | - Test::Makefile |
|---|
| 120 | - +MyFlavor::Plugin |
|---|
| 121 | |
|---|
| 122 | or command option |
|---|
| 123 | |
|---|
| 124 | $ module-setup --plugin=+MyFlavor::Plugin New::Module |
|---|
| 125 | |
|---|
| 126 | =cut |
|---|
| 127 | |
|---|
| 128 | |
|---|