1 package DBIx::Class::Schema::Loader::Optional::Dependencies;
8 # Stolen from DBIx::Class
10 # NO EXTERNAL NON-5.8.1 CORE DEPENDENCIES EVER (e.g. C::A::G)
11 # This module is to be loaded by Makefile.PM on a pristine system
13 # POD is generated automatically by calling _gen_pod from the
14 # Makefile.PL in $AUTHOR mode
18 #'Module::Install::Pod::Inherit' => '0.01',
24 'MooseX::NonMoose' => '0.25',
25 'namespace::autoclean' => '0.09',
26 'MooseX::MarkAsMethods' => '0.13',
30 desc => 'Modules required for the use_moose option',
39 title => 'dbicdump config file',
40 desc => 'Modules required for using a config file with dbicdump',
44 test_dbicdump_config => {
47 'Config::General' => '0',
50 title => 'dbicdump config file testing',
51 desc => 'Modules required for using testing using a config file with dbicdump',
57 'Test::Pod' => '1.14',
58 'Pod::Simple' => '3.22',
61 title => 'POD testing',
62 desc => 'Modules required for testing POD in this distribution',
68 my ($class, $group) = @_;
70 croak "req_list_for() expects a requirement group name"
73 my $deps = $reqs->{$group}{req}
74 or croak "Requirement group '$group' does not exist";
80 our %req_availability_cache;
82 my ($class, $group) = @_;
84 croak "req_ok_for() expects a requirement group name"
87 $class->_check_deps ($group) unless $req_availability_cache{$group};
89 return $req_availability_cache{$group}{status};
93 my ($class, $group) = @_;
95 croak "req_missing_for() expects a requirement group name"
98 $class->_check_deps ($group) unless $req_availability_cache{$group};
100 return $req_availability_cache{$group}{missing};
103 sub req_errorlist_for {
104 my ($class, $group) = @_;
106 croak "req_errorlist_for() expects a requirement group name"
109 $class->_check_deps ($group) unless $req_availability_cache{$group};
111 return $req_availability_cache{$group}{errorlist};
115 my ($class, $group) = @_;
117 my $deps = $class->req_list_for ($group);
120 for my $mod (keys %$deps) {
121 if (my $ver = $deps->{$mod}) {
122 eval "use $mod $ver ()";
128 $errors{$mod} = $@ if $@;
132 my $missing = join (', ', map { $deps->{$_} ? "$_ >= $deps->{$_}" : $_ } (sort keys %errors) );
133 $missing .= " (see $class for details)" if $reqs->{$group}{pod};
134 $req_availability_cache{$group} = {
136 errorlist => { %errors },
141 $req_availability_cache{$group} = {
150 return { map { $_ => { %{ $reqs->{$_}{req} || {} } } } (keys %$reqs) };
153 # This is to be called by the author only (automatically in Makefile.PL)
157 my $modfn = __PACKAGE__ . '.pm';
158 $modfn =~ s/\:\:/\//g;
160 my $podfn = __FILE__;
161 $podfn =~ s/\.pm$/\.pod/;
164 eval { require DBIx::Class::Schema::Loader; DBIx::Class::Schema::Loader->VERSION; }
168 "\n\n---------------------------------------------------------------------\n" .
169 'Unable to load the DBIx::Class::Schema::Loader module to determine current ' .
170 'version, possibly due to missing dependencies. Author-mode autodocumentation ' .
172 "\n\n---------------------------------------------------------------------\n"
180 #########################################################################
181 ##################### A U T O G E N E R A T E D ########################
182 #########################################################################
184 # The contents of this POD file are auto-generated. Any changes you make
185 # will be lost. If you need to change the generated text edit _gen_pod()
186 # at the end of $modfn
190 "$class - Optional module dependency specifications (for module authors)",
193 Somewhere in your build-file (e.g. L<Module::Install>'s Makefile.PL):
197 configure_requires 'DBIx::Class::Schema::Loader' => '$distver';
201 my \$use_moose_deps = $class->req_list_for ('use_moose');
203 for (keys %\$use_moose_deps) {
204 requires \$_ => \$use_moose_deps->{\$_};
209 Note that there are some caveats regarding C<configure_requires()>, more info
210 can be found at L<Module::Install/configure_requires>
212 '=head1 DESCRIPTION',
214 Some of the features of L<DBIx::Class::Schema::Loader> have external
215 module dependencies on their own. In order not to burden the average user
216 with modules he will never use, these optional dependencies are not included
217 in the base Makefile.PL. Instead an exception with a descriptive message is
218 thrown when a specific feature is missing one or several modules required for
219 its operation. This module is the central holding place for the current list
220 of such dependencies.
222 '=head1 CURRENT REQUIREMENT GROUPS',
224 Dependencies are organized in C<groups> and each group can list one or more
225 required modules, with an optional minimum version (or 0 for any version).
229 for my $group (sort keys %$reqs) {
230 my $p = $reqs->{$group}{pod}
233 my $modlist = $reqs->{$group}{req}
236 next unless keys %$modlist;
239 "=head2 $p->{title}",
242 ( map { "=item * $_" . ($modlist->{$_} ? " >= $modlist->{$_}" : '') } (sort keys %$modlist) ),
244 "Requirement group: B<$group>",
250 '=head2 req_group_list',
252 '=item Arguments: $none',
253 '=item Returns: \%list_of_requirement_groups',
256 This method should be used by DBIx::Class packagers, to get a hashref of all
257 dependencies keyed by dependency group. Each key (group name) can be supplied
258 to one of the group-specific methods below.
261 '=head2 req_list_for',
263 '=item Arguments: $group_name',
264 '=item Returns: \%list_of_module_version_pairs',
267 This method should be used by DBIx::Class extension authors, to determine the
268 version of modules a specific feature requires in the B<current> version of
269 L<DBIx::Class::Schema::Loader>. See the L</SYNOPSIS> for a real-world
275 '=item Arguments: $group_name',
276 '=item Returns: 1|0',
278 'Returns true or false depending on whether all modules required by C<$group_name> are present on the system and loadable',
280 '=head2 req_missing_for',
282 '=item Arguments: $group_name',
283 '=item Returns: $error_message_string',
286 Returns a single line string suitable for inclusion in larger error messages.
287 This method would normally be used by L<DBIx::Class::Schema::Loader>
288 maintainers, to indicate to the user that he needs to install specific modules
289 before he will be able to use a specific feature.
291 For example if some of the requirements for C<use_moose> are not available,
292 the returned string could look like:
294 Moose >= 0 (see use_moose for details)
296 The author is expected to prepend the necessary text to this message before
297 returning the actual error seen by the user.
300 '=head2 req_errorlist_for',
302 '=item Arguments: $group_name',
303 '=item Returns: \%list_of_loaderrors_per_module',
306 Returns a hashref containing the actual errors that occurred while attempting
307 to load each module in the requirement group.
310 'See L<DBIx::Class/CONTRIBUTORS>.',
312 'You may distribute this code under the same terms as Perl itself',
315 open (my $fh, '>', $podfn) or croak "Unable to write to $podfn: $!";
316 print $fh join ("\n\n", @chunks);