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',
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 my ($class, $group) = @_;
59 croak "req_list_for() expects a requirement group name"
62 my $deps = $reqs->{$group}{req}
63 or croak "Requirement group '$group' does not exist";
69 our %req_availability_cache;
71 my ($class, $group) = @_;
73 croak "req_ok_for() expects a requirement group name"
76 $class->_check_deps ($group) unless $req_availability_cache{$group};
78 return $req_availability_cache{$group}{status};
82 my ($class, $group) = @_;
84 croak "req_missing_for() expects a requirement group name"
87 $class->_check_deps ($group) unless $req_availability_cache{$group};
89 return $req_availability_cache{$group}{missing};
92 sub req_errorlist_for {
93 my ($class, $group) = @_;
95 croak "req_errorlist_for() expects a requirement group name"
98 $class->_check_deps ($group) unless $req_availability_cache{$group};
100 return $req_availability_cache{$group}{errorlist};
104 my ($class, $group) = @_;
106 my $deps = $class->req_list_for ($group);
109 for my $mod (keys %$deps) {
110 if (my $ver = $deps->{$mod}) {
111 eval "use $mod $ver ()";
117 $errors{$mod} = $@ if $@;
121 my $missing = join (', ', map { $deps->{$_} ? "$_ >= $deps->{$_}" : $_ } (sort keys %errors) );
122 $missing .= " (see $class for details)" if $reqs->{$group}{pod};
123 $req_availability_cache{$group} = {
125 errorlist => { %errors },
130 $req_availability_cache{$group} = {
139 return { map { $_ => { %{ $reqs->{$_}{req} || {} } } } (keys %$reqs) };
142 # This is to be called by the author only (automatically in Makefile.PL)
146 my $modfn = __PACKAGE__ . '.pm';
147 $modfn =~ s/\:\:/\//g;
149 my $podfn = __FILE__;
150 $podfn =~ s/\.pm$/\.pod/;
153 eval { require DBIx::Class::Schema::Loader; DBIx::Class::Schema::Loader->VERSION; }
157 "\n\n---------------------------------------------------------------------\n" .
158 'Unable to load the DBIx::Class::Schema::Loader module to determine current ' .
159 'version, possibly due to missing dependencies. Author-mode autodocumentation ' .
161 "\n\n---------------------------------------------------------------------\n"
169 #########################################################################
170 ##################### A U T O G E N E R A T E D ########################
171 #########################################################################
173 # The contents of this POD file are auto-generated. Any changes you make
174 # will be lost. If you need to change the generated text edit _gen_pod()
175 # at the end of $modfn
179 "$class - Optional module dependency specifications (for module authors)",
182 Somewhere in your build-file (e.g. L<Module::Install>'s Makefile.PL):
186 configure_requires 'DBIx::Class::Schema::Loader' => '$distver';
190 my \$use_moose_deps = $class->req_list_for ('use_moose');
192 for (keys %\$use_moose_deps) {
193 requires \$_ => \$use_moose_deps->{\$_};
198 Note that there are some caveats regarding C<configure_requires()>, more info
199 can be found at L<Module::Install/configure_requires>
201 '=head1 DESCRIPTION',
203 Some of the features of L<DBIx::Class::Schema::Loader> have external
204 module dependencies on their own. In order not to burden the average user
205 with modules he will never use, these optional dependencies are not included
206 in the base Makefile.PL. Instead an exception with a descriptive message is
207 thrown when a specific feature is missing one or several modules required for
208 its operation. This module is the central holding place for the current list
209 of such dependencies.
211 '=head1 CURRENT REQUIREMENT GROUPS',
213 Dependencies are organized in C<groups> and each group can list one or more
214 required modules, with an optional minimum version (or 0 for any version).
218 for my $group (sort keys %$reqs) {
219 my $p = $reqs->{$group}{pod}
222 my $modlist = $reqs->{$group}{req}
225 next unless keys %$modlist;
228 "=head2 $p->{title}",
231 ( map { "=item * $_" . ($modlist->{$_} ? " >= $modlist->{$_}" : '') } (sort keys %$modlist) ),
233 "Requirement group: B<$group>",
239 '=head2 req_group_list',
241 '=item Arguments: $none',
242 '=item Returns: \%list_of_requirement_groups',
245 This method should be used by DBIx::Class packagers, to get a hashref of all
246 dependencies keyed by dependency group. Each key (group name) can be supplied
247 to one of the group-specific methods below.
250 '=head2 req_list_for',
252 '=item Arguments: $group_name',
253 '=item Returns: \%list_of_module_version_pairs',
256 This method should be used by DBIx::Class extension authors, to determine the
257 version of modules a specific feature requires in the B<current> version of
258 L<DBIx::Class::Schema::Loader>. See the L</SYNOPSIS> for a real-world
264 '=item Arguments: $group_name',
265 '=item Returns: 1|0',
267 'Returns true or false depending on whether all modules required by C<$group_name> are present on the system and loadable',
269 '=head2 req_missing_for',
271 '=item Arguments: $group_name',
272 '=item Returns: $error_message_string',
275 Returns a single line string suitable for inclusion in larger error messages.
276 This method would normally be used by L<DBIx::Class::Schema::Loader>
277 maintainers, to indicate to the user that he needs to install specific modules
278 before he will be able to use a specific feature.
280 For example if some of the requirements for C<use_moose> are not available,
281 the returned string could look like:
283 Moose >= 0 (see use_moose for details)
285 The author is expected to prepend the necessary text to this message before
286 returning the actual error seen by the user.
289 '=head2 req_errorlist_for',
291 '=item Arguments: $group_name',
292 '=item Returns: \%list_of_loaderrors_per_module',
295 Returns a hashref containing the actual errors that occured while attempting
296 to load each module in the requirement group.
299 'See L<DBIx::Class/CONTRIBUTORS>.',
301 'You may distribute this code under the same terms as Perl itself',
304 open (my $fh, '>', $podfn) or croak "Unable to write to $podfn: $!";
305 print $fh join ("\n\n", @chunks);