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.16',
25 'namespace::autoclean' => '0.09',
29 desc => 'Modules required for the use_moose option',
38 title => 'dbicdump config file',
39 desc => 'Modules required for using a config file with dbicdump',
43 test_dbicdump_config => {
46 'Config::General' => '0',
49 title => 'dbicdump config file testing',
50 desc => 'Modules required for using testing using a config file with dbicdump',
56 my ($class, $group) = @_;
58 croak "req_list_for() expects a requirement group name"
61 my $deps = $reqs->{$group}{req}
62 or croak "Requirement group '$group' does not exist";
68 our %req_availability_cache;
70 my ($class, $group) = @_;
72 croak "req_ok_for() expects a requirement group name"
75 $class->_check_deps ($group) unless $req_availability_cache{$group};
77 return $req_availability_cache{$group}{status};
81 my ($class, $group) = @_;
83 croak "req_missing_for() expects a requirement group name"
86 $class->_check_deps ($group) unless $req_availability_cache{$group};
88 return $req_availability_cache{$group}{missing};
91 sub req_errorlist_for {
92 my ($class, $group) = @_;
94 croak "req_errorlist_for() expects a requirement group name"
97 $class->_check_deps ($group) unless $req_availability_cache{$group};
99 return $req_availability_cache{$group}{errorlist};
103 my ($class, $group) = @_;
105 my $deps = $class->req_list_for ($group);
108 for my $mod (keys %$deps) {
109 if (my $ver = $deps->{$mod}) {
110 eval "use $mod $ver ()";
116 $errors{$mod} = $@ if $@;
120 my $missing = join (', ', map { $deps->{$_} ? "$_ >= $deps->{$_}" : $_ } (sort keys %errors) );
121 $missing .= " (see $class for details)" if $reqs->{$group}{pod};
122 $req_availability_cache{$group} = {
124 errorlist => { %errors },
129 $req_availability_cache{$group} = {
138 return { map { $_ => { %{ $reqs->{$_}{req} || {} } } } (keys %$reqs) };
141 # This is to be called by the author only (automatically in Makefile.PL)
145 my $modfn = __PACKAGE__ . '.pm';
146 $modfn =~ s/\:\:/\//g;
148 my $podfn = __FILE__;
149 $podfn =~ s/\.pm$/\.pod/;
152 eval { require DBIx::Class::Schema::Loader; DBIx::Class::Schema::Loader->VERSION; }
156 "\n\n---------------------------------------------------------------------\n" .
157 'Unable to load the DBIx::Class::Schema::Loader module to determine current ' .
158 'version, possibly due to missing dependencies. Author-mode autodocumentation ' .
160 "\n\n---------------------------------------------------------------------\n"
168 #########################################################################
169 ##################### A U T O G E N E R A T E D ########################
170 #########################################################################
172 # The contents of this POD file are auto-generated. Any changes you make
173 # will be lost. If you need to change the generated text edit _gen_pod()
174 # at the end of $modfn
178 "$class - Optional module dependency specifications (for module authors)",
181 Somewhere in your build-file (e.g. L<Module::Install>'s Makefile.PL):
185 configure_requires 'DBIx::Class::Schema::Loader' => '$distver';
189 my \$use_moose_deps = $class->req_list_for ('use_moose');
191 for (keys %\$use_moose_deps) {
192 requires \$_ => \$use_moose_deps->{\$_};
197 Note that there are some caveats regarding C<configure_requires()>, more info
198 can be found at L<Module::Install/configure_requires>
200 '=head1 DESCRIPTION',
202 Some of the features of L<DBIx::Class::Schema::Loader> have external
203 module dependencies on their own. In order not to burden the average user
204 with modules he will never use, these optional dependencies are not included
205 in the base Makefile.PL. Instead an exception with a descriptive message is
206 thrown when a specific feature is missing one or several modules required for
207 its operation. This module is the central holding place for the current list
208 of such dependencies.
210 '=head1 CURRENT REQUIREMENT GROUPS',
212 Dependencies are organized in C<groups> and each group can list one or more
213 required modules, with an optional minimum version (or 0 for any version).
217 for my $group (sort keys %$reqs) {
218 my $p = $reqs->{$group}{pod}
221 my $modlist = $reqs->{$group}{req}
224 next unless keys %$modlist;
227 "=head2 $p->{title}",
230 ( map { "=item * $_" . ($modlist->{$_} ? " >= $modlist->{$_}" : '') } (sort keys %$modlist) ),
232 "Requirement group: B<$group>",
238 '=head2 req_group_list',
240 '=item Arguments: $none',
241 '=item Returns: \%list_of_requirement_groups',
244 This method should be used by DBIx::Class packagers, to get a hashref of all
245 dependencies keyed by dependency group. Each key (group name) can be supplied
246 to one of the group-specific methods below.
249 '=head2 req_list_for',
251 '=item Arguments: $group_name',
252 '=item Returns: \%list_of_module_version_pairs',
255 This method should be used by DBIx::Class extension authors, to determine the
256 version of modules a specific feature requires in the B<current> version of
257 L<DBIx::Class::Schema::Loader>. See the L</SYNOPSIS> for a real-world
263 '=item Arguments: $group_name',
264 '=item Returns: 1|0',
266 'Returns true or false depending on whether all modules required by C<$group_name> are present on the system and loadable',
268 '=head2 req_missing_for',
270 '=item Arguments: $group_name',
271 '=item Returns: $error_message_string',
274 Returns a single line string suitable for inclusion in larger error messages.
275 This method would normally be used by L<DBIx::Class::Schema::Loader>
276 maintainers, to indicate to the user that he needs to install specific modules
277 before he will be able to use a specific feature.
279 For example if some of the requirements for C<use_moose> are not available,
280 the returned string could look like:
282 Moose >= 0 (see use_moose for details)
284 The author is expected to prepend the necessary text to this message before
285 returning the actual error seen by the user.
288 '=head2 req_errorlist_for',
290 '=item Arguments: $group_name',
291 '=item Returns: \%list_of_loaderrors_per_module',
294 Returns a hashref containing the actual errors that occured while attempting
295 to load each module in the requirement group.
298 'See L<DBIx::Class/CONTRIBUTORS>.',
300 'You may distribute this code under the same terms as Perl itself',
303 open (my $fh, '>', $podfn) or croak "Unable to write to $podfn: $!";
304 print $fh join ("\n\n", @chunks);