OSDN Git Service

Inserted "use warnings".
[mt-acme/Grass.git] / Build.PL
1 use strict;
2 use warnings;
3 use Module::Build;
4 use File::Spec;
5 use File::Basename;
6 use YAML qw/ Load /;
7
8 my $class = Module::Build->subclass(
9         class => 'MTToiplanPluginDirectoryBuilder',
10         code => q{
11                 # Don't make blib
12                 # sub ACTION_code {};
13                 # Don't make blib
14                 sub ACTION_docs {};
15                 # Don't make META.yml
16                 sub ACTION_distmeta {
17                         # no warning on ACTION_distdir
18                         $_[0]->{metafile} = 'MANIFEST';
19                 };
20                 # Don't add MEATA.yml to MANIFEST
21                 sub ACTION_manifest {
22                         $_[0]->{metafile} = 'MANIFEST',
23                         $_[0]->SUPER::ACTION_manifest(@_);
24                 };
25                 sub ACTION_test {
26                         my $p = $_[0]->{properties};
27                         unshift(
28                                 @INC,
29                                 File::Spec->catdir($p->{base_dir}, 'extlib'),
30                                 File::Spec->catdir($p->{base_dir}, '../../lib'),
31                                 File::Spec->catdir($p->{base_dir}, '../../extlib'),
32                         );
33
34                         $_[0]->SUPER::ACTION_test(@_);
35                 };
36                 sub ACTION_upload_google {
37                         my ($self) = @_;
38                         my $prj = 'toiplan-mtplugin-directory';
39                         my $ver = $self->dist_version;
40                         my $dist_dir = $self->dist_dir;
41                         my $name = $self->dist_name;
42
43                         $self->depends_on('dist');
44                         #$self->_call_action('distdir');
45                         $self->ACTION_distdir;
46                         $self->depends_on('zipdist');
47                         system(
48                                 "googlecode_upload.py -s 'Release $ver (TGZ)' -p $prj -l $name $dist_dir.tar.gz"
49                         );
50                         system(
51                                 "googlecode_upload.py -s 'Release $ver (ZIP)' -p $prj -l $name $dist_dir.zip"
52                         );
53                         unlink("$dist_dir.tar.gz");
54                         unlink("$dist_dir.zip");
55                 };
56
57                 sub ACTION_zipdist {
58                         my ($self) = @_;
59                         my $dist_dir = $self->dist_dir;
60                         $self->depends_on('distdir');
61                         print "Creating $dist_dir.zip\n";
62                         system("zip -r $dist_dir.zip $dist_dir") == 0 or die $?;
63                         $self->delete_filetree($dist_dir);
64                 }
65
66                 sub ACTION_distdir {
67                         my ($self) = @_;
68
69                         $_[0]->SUPER::ACTION_distdir(@_);
70
71                         my $dist_dir = $self->dist_dir;
72                         rename($dist_dir, $self->{properties}{dist_name});
73                         use File::Path;
74                         use File::Spec;
75                         use File::Basename;
76                         my $plugins = File::Spec->catfile($dist_dir, 'plugins');
77                         mkpath($plugins, 1, 0755);
78
79                         my $new_dist_dir = File::Spec->catfile(
80                                 $plugins, $self->{properties}{dist_name}
81                         );
82                         rename($self->{properties}{dist_name}, $new_dist_dir);
83
84                         foreach my $f (glob(File::Spec->catfile($new_dist_dir, 'LIC*'))) {
85                                 rename($f, File::Spec->catfile($dist_dir, basename($f)));
86                         }
87
88                         if (my @statics = glob(File::Spec->catfile($new_dist_dir, 'static/*'))) {
89                                 my $static = File::Spec->catfile(
90                                         $dist_dir, 'mt-static/plugins'
91                                 );
92                                 mkpath($static, 1, 0755);
93
94                                 my $d = File::Spec->catfile(
95                                         $static, $self->{properties}{dist_name}
96                                 );
97                                 mkpath($d, 1, 0755);
98
99                                 foreach my $f (@statics) {
100                                         rename($f, File::Spec->catfile($d, basename($f)));
101                                 }
102                         }
103                 }
104         }
105 );
106
107 my $yaml_string = do {
108         open(my $fh, File::Spec->catfile(dirname(__FILE__), 'config.yaml'));
109         local $/;
110         <$fh>
111 };
112 $yaml_string =~ s/^(\s*)\*/$1App::\*/gm;
113 my $yaml = Load($yaml_string);
114
115 my $builder = $class->new(
116         dist_name           => $yaml->{name},
117     dist_author         => 'Movable Type ACME Plugin Project',
118     dist_version        => $yaml->{version},
119     module_name         => $yaml->{name} . '::App',
120     license             => 'MIT License',
121     add_to_cleanup      => [ $yaml->{name} . '-*' ],
122 );
123
124 $builder->create_build_script();