root/lang/perl/Module-Setup/trunk/lib/Module/Setup/Plugin.pm @ 20431

Revision 20431, 2.5 kB (checked in by yappo, 5 years ago)

ひな形を作った後のフェーズを変更

Line 
1package Module::Setup::Plugin;
2use strict;
3use warnings;
4
5use Path::Class;
6use Scalar::Util qw(weaken);
7
8use Module::Setup::Flavor;
9
10sub new {
11    my($class, %args) = @_;
12    my $self = bless { %args }, $class;
13    weaken $self->{context};
14    $self->register;
15    $self;
16}
17
18sub register {}
19
20sub add_trigger {
21    my($self, @args) = @_;
22    $self->{context}->add_trigger(@args);
23}
24
25sub 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
461;
47
48__END__
49
50=head1 NAME
51
52Module::Setup::Plugin - Module::Setup Plugin
53
54=head1 Trigger Point
55
56=head2 befor_dump_config $config
57
58config setup L<Module::Setup::Plugin::Config::Basic>
59
60=head2 after_setup_module_attribute
61
62module attribute setup L<Module::Setup::Plugin::VC::SVN>
63
64=head2 after_setup_template_vars
65
66template parameters setup
67
68=head2 append_template_file $template_vars, $module_attribute
69
70add module template file for new module L<Module::Setup::Plugin::VC::Git>
71
72=head2 template_process $options
73
74for 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
87aftter create_skeleton
88
89=head2 finalize_create_skeleton $attributes
90
91last 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
122or command option
123
124  $ module-setup --plugin=+MyFlavor::Plugin New::Module
125
126=cut
127
128
Note: See TracBrowser for help on using the browser.