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.15',
25 'namespace::autoclean' => '0.09',
29 desc => 'Modules required for the use_moose option',
35 my ($class, $group) = @_;
37 croak "req_list_for() expects a requirement group name"
40 my $deps = $reqs->{$group}{req}
41 or croak "Requirement group '$group' does not exist";
47 our %req_availability_cache;
49 my ($class, $group) = @_;
51 croak "req_ok_for() expects a requirement group name"
54 $class->_check_deps ($group) unless $req_availability_cache{$group};
56 return $req_availability_cache{$group}{status};
60 my ($class, $group) = @_;
62 croak "req_missing_for() expects a requirement group name"
65 $class->_check_deps ($group) unless $req_availability_cache{$group};
67 return $req_availability_cache{$group}{missing};
70 sub req_errorlist_for {
71 my ($class, $group) = @_;
73 croak "req_errorlist_for() expects a requirement group name"
76 $class->_check_deps ($group) unless $req_availability_cache{$group};
78 return $req_availability_cache{$group}{errorlist};
82 my ($class, $group) = @_;
84 my $deps = $class->req_list_for ($group);
87 for my $mod (keys %$deps) {
88 if (my $ver = $deps->{$mod}) {
89 eval "use $mod $ver ()";
95 $errors{$mod} = $@ if $@;
99 my $missing = join (', ', map { $deps->{$_} ? "$_ >= $deps->{$_}" : $_ } (sort keys %errors) );
100 $missing .= " (see $class for details)" if $reqs->{$group}{pod};
101 $req_availability_cache{$group} = {
103 errorlist => { %errors },
108 $req_availability_cache{$group} = {
117 return { map { $_ => { %{ $reqs->{$_}{req} || {} } } } (keys %$reqs) };
120 # This is to be called by the author only (automatically in Makefile.PL)
124 my $modfn = __PACKAGE__ . '.pm';
125 $modfn =~ s/\:\:/\//g;
127 my $podfn = __FILE__;
128 $podfn =~ s/\.pm$/\.pod/;
131 eval { require DBIx::Class::Schema::Loader; DBIx::Class::Schema::Loader->VERSION; }
135 "\n\n---------------------------------------------------------------------\n" .
136 'Unable to load the DBIx::Class::Schema::Loader module to determine current ' .
137 'version, possibly due to missing dependencies. Author-mode autodocumentation ' .
139 "\n\n---------------------------------------------------------------------\n"
147 #########################################################################
148 ##################### A U T O G E N E R A T E D ########################
149 #########################################################################
151 # The contents of this POD file are auto-generated. Any changes you make
152 # will be lost. If you need to change the generated text edit _gen_pod()
153 # at the end of $modfn
157 "$class - Optional module dependency specifications (for module authors)",
160 Somewhere in your build-file (e.g. L<Module::Install>'s Makefile.PL):
164 configure_requires 'DBIx::Class::Schema::Loader' => '$distver';
168 my \$use_moose_deps = $class->req_list_for ('use_moose');
170 for (keys %\$use_moose_deps) {
171 requires \$_ => \$use_moose_deps->{\$_};
176 Note that there are some caveats regarding C<configure_requires()>, more info
177 can be found at L<Module::Install/configure_requires>
179 '=head1 DESCRIPTION',
181 Some of the features of L<DBIx::Class::Schema::Loader> have external
182 module dependencies on their own. In order not to burden the average user
183 with modules he will never use, these optional dependencies are not included
184 in the base Makefile.PL. Instead an exception with a descriptive message is
185 thrown when a specific feature is missing one or several modules required for
186 its operation. This module is the central holding place for the current list
187 of such dependencies.
189 '=head1 CURRENT REQUIREMENT GROUPS',
191 Dependencies are organized in C<groups> and each group can list one or more
192 required modules, with an optional minimum version (or 0 for any version).
196 for my $group (sort keys %$reqs) {
197 my $p = $reqs->{$group}{pod}
200 my $modlist = $reqs->{$group}{req}
203 next unless keys %$modlist;
206 "=head2 $p->{title}",
209 ( map { "=item * $_" . ($modlist->{$_} ? " >= $modlist->{$_}" : '') } (sort keys %$modlist) ),
211 "Requirement group: B<$group>",
217 '=head2 req_group_list',
219 '=item Arguments: $none',
220 '=item Returns: \%list_of_requirement_groups',
223 This method should be used by DBIx::Class packagers, to get a hashref of all
224 dependencies keyed by dependency group. Each key (group name) can be supplied
225 to one of the group-specific methods below.
228 '=head2 req_list_for',
230 '=item Arguments: $group_name',
231 '=item Returns: \%list_of_module_version_pairs',
234 This method should be used by DBIx::Class extension authors, to determine the
235 version of modules a specific feature requires in the B<current> version of
236 L<DBIx::Class::Schema::Loader>. See the L</SYNOPSIS> for a real-world
242 '=item Arguments: $group_name',
243 '=item Returns: 1|0',
245 'Returns true or false depending on whether all modules required by C<$group_name> are present on the system and loadable',
247 '=head2 req_missing_for',
249 '=item Arguments: $group_name',
250 '=item Returns: $error_message_string',
253 Returns a single line string suitable for inclusion in larger error messages.
254 This method would normally be used by L<DBIx::Class::Schema::Loader>
255 maintainers, to indicate to the user that he needs to install specific modules
256 before he will be able to use a specific feature.
258 For example if some of the requirements for C<use_moose> are not available,
259 the returned string could look like:
261 Moose >= 0 (see use_moose for details)
263 The author is expected to prepend the necessary text to this message before
264 returning the actual error seen by the user.
267 '=head2 req_errorlist_for',
269 '=item Arguments: $group_name',
270 '=item Returns: \%list_of_loaderrors_per_module',
273 Returns a hashref containing the actual errors that occured while attempting
274 to load each module in the requirement group.
277 'See L<DBIx::Class/CONTRIBUTORS>.',
279 'You may distribute this code under the same terms as Perl itself',
282 open (my $fh, '>', $podfn) or croak "Unable to write to $podfn: $!";
283 print $fh join ("\n\n", @chunks);