Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / maint / Makefile.PL.inc / 53_autogen_pod.pl
1 use File::Path();
2 use File::Glob();
3
4 # leftovers in old checkouts
5 unlink 'lib/DBIx/Class/Optional/Dependencies.pod'
6   if -f 'lib/DBIx/Class/Optional/Dependencies.pod';
7 File::Path::rmtree([ '.generated_pod' ])
8   if -d '.generated_pod';
9
10 my $pod_dir = 'maint/.Generated_Pod';
11 my $ver = Meta->version;
12
13 # cleanup the generated pod dir (again - kill leftovers from old checkouts)
14 if (-d $pod_dir) {
15   File::Path::rmtree([ File::Glob::bsd_glob("$pod_dir/*") ]);
16 }
17 else {
18   mkdir $pod_dir or die "Unable to create $pod_dir: $!";
19 }
20
21 # generate the OptDeps pod both in the clone-dir and during the makefile distdir
22 {
23   print "Regenerating Optional/Dependencies.pod\n";
24
25   eval {
26     require DBIx::Class::Optional::Dependencies;
27     DBIx::Class::Optional::Dependencies->_gen_pod ($ver, "$pod_dir/lib");
28     1;
29   }
30     or
31   printf ("FAILED!!! Subsequent `make dist` will fail. %s\n",
32     $ENV{DBICDIST_DEBUG}
33       ? "Full error: $@"
34       : 'Re-run with $ENV{DBICDIST_DEBUG} set for more info'
35   );
36
37   postamble <<"EOP";
38
39 clonedir_generate_files : dbic_clonedir_gen_optdeps_pod
40
41 dbic_clonedir_gen_optdeps_pod :
42 \t@{[
43   $mm_proto->oneliner("DBIx::Class::Optional::Dependencies->_gen_pod(q($ver), q($pod_dir/lib))", [qw/-Ilib -MDBIx::Class::Optional::Dependencies/])
44 ]}
45
46 EOP
47 }
48
49
50 # generate the script/dbicadmin pod
51 {
52   print "Regenerating script/dbicadmin.pod\n";
53
54   # generating it in the root of $pod_dir
55   # it will *not* be copied over due to not being listed at the top
56   # of MANIFEST.SKIP - this is a *good* thing
57   # we only want to ship a script/dbicadmin, with the POD appended
58   # (see inject_dbicadmin_pod.pl), but still want to spellcheck and
59   # whatnot the intermediate step
60   my $pod_fn = "$pod_dir/dbicadmin.pod";
61
62   # if the author doesn't have the prereqs, don't fail the initial "perl Makefile.pl" step
63   my $great_success;
64   {
65     local @ARGV = ('--documentation-as-pod', $pod_fn);
66     local $0 = 'dbicadmin';
67     local *CORE::GLOBAL::exit = sub { $great_success++; die; };
68     do 'script/dbicadmin';
69   }
70   if (!$great_success and ($@ || $!) ) {
71     printf ("FAILED!!! Subsequent `make dist` will fail. %s\n",
72       $ENV{DBICDIST_DEBUG}
73         ? 'Full error: ' . ($@ || $!)
74         : 'Re-run with $ENV{DBICDIST_DEBUG} set for more info'
75     );
76   }
77
78   postamble <<"EOP";
79
80 clonedir_generate_files : dbic_clonedir_gen_dbicadmin_pod
81
82 dbic_clonedir_gen_dbicadmin_pod :
83 \t\$(ABSPERLRUN) -Ilib -- script/dbicadmin --documentation-as-pod @{[ $mm_proto->quote_literal($pod_fn) ]}
84
85 EOP
86 }
87
88
89 # generate the inherit pods only during distbuilding phase
90 # it is too slow to do at regular Makefile.PL
91 {
92   postamble <<"EOP";
93
94 clonedir_generate_files : dbic_clonedir_gen_inherit_pods
95
96 dbic_clonedir_gen_inherit_pods :
97 \t\$(ABSPERLRUN) -Ilib maint/gen_pod_inherit
98
99 EOP
100 }
101
102
103 # generate the DBIx/Class.pod only during distdir
104 {
105   my $dist_pod_fn = "$pod_dir/lib/DBIx/Class.pod";
106
107   postamble <<"EOP";
108
109 clonedir_generate_files : dbic_distdir_gen_dbic_pod
110
111 dbic_distdir_gen_dbic_pod :
112
113 \tperldoc -u lib/DBIx/Class.pm > $dist_pod_fn
114 \t@{[ $mm_proto->oneliner(
115   "s!^.*?this line is replaced with the author list.*! qq{List of the awesome contributors who made DBIC v$ver possible\\n\\n} . qx(\$^X -Ilib maint/gen_pod_authors)!me",
116   [qw( -0777 -p -i.arghwin32 )]
117 ) ]} $dist_pod_fn
118 \t\$(RM_F) $dist_pod_fn.arghwin32
119
120 create_distdir : dbic_distdir_defang_authors
121
122 # Remove the maintainer-only warning (be nice ;)
123 dbic_distdir_defang_authors :
124 \t@{[ $mm_proto->oneliner('s/ ^ \s* \# \s* \*\*\* .+ \n ( ^ \s* \# \s*? \n )? //xmg', [qw( -0777 -p -i.arghwin32 )] ) ]} \$(DISTVNAME)/AUTHORS
125 @{[ $crlf_fixup->( '$(DISTVNAME)/AUTHORS' ) ]}
126 \t\$(RM_F) \$(DISTVNAME)/AUTHORS.arghwin32
127
128 EOP
129 }
130
131
132 # on some OSes generated files may have an incorrect \n - fix it
133 # so that the xt tests pass on a fresh checkout (also shipping a
134 # dist with CRLFs is beyond obnoxious)
135 if ($^O eq 'MSWin32' or $^O eq 'cygwin') {
136   {
137     local $ENV{PERLIO} = 'unix';
138     system( $^X, qw( -MExtUtils::Command -e dos2unix -- ), $pod_dir );
139   }
140
141   postamble <<"EOP";
142
143 clonedir_post_generate_files : pod_crlf_fixup
144
145 pod_crlf_fixup :
146 @{[ $crlf_fixup->($pod_dir) ]}
147
148 EOP
149 }
150
151 {
152   postamble <<"EOP";
153
154 clonedir_post_generate_files : dbic_clonedir_copy_generated_pod
155
156 dbic_clonedir_copy_generated_pod :
157 \t\$(RM_F) $pod_dir.packlist
158 \t@{[
159   $mm_proto->oneliner("install([ from_to => {q($pod_dir) => './', write => q($pod_dir.packlist)}, verbose => 0, uninstall_shadows => 0, skip => [] ])", ['-MExtUtils::Install'])
160 ]}
161
162 EOP
163 }
164
165
166 # everything that came from $pod_dir, needs to be removed from the workdir
167 {
168   postamble <<"EOP";
169
170 clonedir_cleanup_generated_files : dbic_clonedir_cleanup_generated_pod_copies
171
172 dbic_clonedir_cleanup_generated_pod_copies :
173 \t@{[ $mm_proto->oneliner('chomp && unlink || die', ['-n']) ]} $pod_dir.packlist
174 \t\$(RM_F) $pod_dir.packlist
175
176 EOP
177 }
178
179 # keep the Makefile.PL eval happy
180 1;