1 package DBIx::Class::Optional::Dependencies;
8 # NO EXTERNAL NON-5.8.1 CORE DEPENDENCIES EVER (e.g. C::A::G)
9 # This module is to be loaded by Makefile.PM on a pristine system
11 # POD is generated automatically by calling _gen_pod from the
12 # Makefile.PL in $AUTHOR mode
14 # NOTE: the rationale for 2 JSON::Any versions is that
15 # we need the newer only to work around JSON::XS, which
16 # itself is an optional dep
18 'JSON::Any' => '1.23',
20 my $test_and_dist_json_any = {
21 'JSON::Any' => '1.31',
26 'MooseX::Types' => '0.21',
27 'MooseX::Types::LoadableClass' => '0.011',
37 'MooseX::Types::Path::Class' => '0.05',
38 'MooseX::Types::JSON' => '0.02',
44 'Getopt::Long::Descriptive' => '0.081',
45 'Text::CSV' => '1.16',
48 my $datetime_basic = {
50 'DateTime::Format::Strptime' => '1.2',
54 'Math::BigInt' => '1.80',
55 'Math::Base36' => '0.07',
64 my $rdbms_mssql_odbc = {
67 my $rdbms_mssql_sybase = {
70 my $rdbms_mssql_ado = {
73 my $rdbms_msaccess_odbc = {
76 my $rdbms_msaccess_ado = {
95 my $rdbms_informix = {
96 'DBD::Informix' => '0',
98 my $rdbms_sqlanywhere = {
99 'DBD::SQLAnywhere' => '0',
101 my $rdbms_sqlanywhere_odbc = {
104 my $rdbms_firebird = {
105 'DBD::Firebird' => '0',
107 my $rdbms_firebird_interbase = {
108 'DBD::InterBase' => '0',
110 my $rdbms_firebird_odbc = {
118 title => 'Storage::Replicated',
119 desc => 'Modules required for L<DBIx::Class::Storage::DBI::Replicated>',
126 'Test::Moose' => '0',
136 title => 'DBIx::Class::Admin',
137 desc => 'Modules required for the DBIx::Class administrative library',
146 title => 'dbicadmin',
147 desc => 'Modules required for the CLI DBIx::Class interface dbicadmin',
153 'SQL::Translator' => '0.11018',
156 title => 'Storage::DBI::deploy()',
157 desc => 'Modules required for L<DBIx::Class::Storage::DBI/deployment_statements> and L<DBIx::Class::Schema/deploy>',
162 req => $id_shortener,
165 test_component_accessor => {
167 'Class::Unload' => '0.07',
173 'Test::Pod' => '1.42',
177 test_podcoverage => {
179 'Test::Pod::Coverage' => '1.08',
180 'Pod::Coverage' => '0.20',
186 'Test::EOL' => '1.0',
187 'Test::NoTabs' => '0.9',
193 'Test::Strict' => '0.20',
197 test_prettydebug => {
198 req => $min_json_any,
201 test_admin_script => {
204 %$test_and_dist_json_any,
207 'Cpanel::JSON::XS' => 0,
210 # for t/admin/10script.t
211 ? ('Win32::ShellQuote' => 0)
212 # DWIW does not compile (./configure even) on win32
213 : ('JSON::DWIW' => 0 )
218 test_leaks_heavy => {
220 'Class::MethodCache' => '0.02',
221 'PadWalker' => '1.06',
226 req => $datetime_basic,
234 'DateTime::Format::SQLite' => '0',
241 # t/inflate/datetime_mysql.t
242 # (doesn't need Mysql itself)
243 'DateTime::Format::MySQL' => '0',
250 # t/inflate/datetime_pg.t
251 # (doesn't need PG itself)
252 'DateTime::Format::Pg' => '0.16004',
258 'Class::DBI::Plugin::DeepAbstractSearch' => '0',
260 'Time::Piece::MySQL' => '0',
261 'Date::Simple' => '3.03',
265 # this is just for completeness as SQLite
266 # is a core dep of DBIC for testing
272 title => 'SQLite support',
273 desc => 'Modules required to connect to SQLite',
279 # when changing this list make sure to adjust xt/optional_deps.t
283 title => 'PostgreSQL support',
284 desc => 'Modules required to connect to PostgreSQL',
288 rdbms_mssql_odbc => {
293 title => 'MSSQL support via DBD::ODBC',
294 desc => 'Modules required to connect to MSSQL via DBD::ODBC',
298 rdbms_mssql_sybase => {
300 %$rdbms_mssql_sybase,
303 title => 'MSSQL support via DBD::Sybase',
304 desc => 'Modules required to connect to MSSQL via DBD::Sybase',
313 title => 'MSSQL support via DBD::ADO (Windows only)',
314 desc => 'Modules required to connect to MSSQL via DBD::ADO. This particular DBD is available on Windows only',
318 rdbms_msaccess_odbc => {
320 %$rdbms_msaccess_odbc,
323 title => 'MS Access support via DBD::ODBC',
324 desc => 'Modules required to connect to MS Access via DBD::ODBC',
328 rdbms_msaccess_ado => {
330 %$rdbms_msaccess_ado,
333 title => 'MS Access support via DBD::ADO (Windows only)',
334 desc => 'Modules required to connect to MS Access via DBD::ADO. This particular DBD is available on Windows only',
343 title => 'MySQL support',
344 desc => 'Modules required to connect to MySQL',
353 title => 'Oracle support',
354 desc => 'Modules required to connect to Oracle',
363 title => 'Sybase ASE support',
364 desc => 'Modules required to connect to Sybase ASE',
373 title => 'DB2 support',
374 desc => 'Modules required to connect to DB2',
383 title => 'DB2 on AS/400 support',
384 desc => 'Modules required to connect to DB2 on AS/400',
393 title => 'Informix support',
394 desc => 'Modules required to connect to Informix',
398 rdbms_sqlanywhere => {
403 title => 'SQLAnywhere support',
404 desc => 'Modules required to connect to SQLAnywhere',
408 rdbms_sqlanywhere_odbc => {
410 %$rdbms_sqlanywhere_odbc,
413 title => 'SQLAnywhere support via DBD::ODBC',
414 desc => 'Modules required to connect to SQLAnywhere via DBD::ODBC',
423 title => 'Firebird support',
424 desc => 'Modules required to connect to Firebird',
428 rdbms_firebird_interbase => {
430 %$rdbms_firebird_interbase,
433 title => 'Firebird support via DBD::InterBase',
434 desc => 'Modules required to connect to Firebird via DBD::InterBase',
438 rdbms_firebird_odbc => {
440 %$rdbms_firebird_odbc,
443 title => 'Firebird support via DBD::ODBC',
444 desc => 'Modules required to connect to Firebird via DBD::ODBC',
450 $ENV{DBICTEST_PG_DSN}
452 # the order does matter because the rdbms support group might require
453 # a different version that the test group
455 # when changing this list make sure to adjust xt/optional_deps.t
457 'DBD::Pg' => '2.009002',
462 test_rdbms_mssql_odbc => {
464 $ENV{DBICTEST_MSSQL_ODBC_DSN}
471 test_rdbms_mssql_ado => {
473 $ENV{DBICTEST_MSSQL_ADO_DSN}
480 test_rdbms_mssql_sybase => {
482 $ENV{DBICTEST_MSSQL_DSN}
484 %$rdbms_mssql_sybase,
489 test_rdbms_msaccess_odbc => {
491 $ENV{DBICTEST_MSACCESS_ODBC_DSN}
493 %$rdbms_msaccess_odbc,
500 test_rdbms_msaccess_ado => {
502 $ENV{DBICTEST_MSACCESS_ADO_DSN}
504 %$rdbms_msaccess_ado,
511 test_rdbms_mysql => {
513 $ENV{DBICTEST_MYSQL_DSN}
520 test_rdbms_oracle => {
522 $ENV{DBICTEST_ORA_DSN}
525 'DateTime::Format::Oracle' => '0',
526 'DBD::Oracle' => '1.24',
533 $ENV{DBICTEST_SYBASE_DSN}
542 $ENV{DBICTEST_DB2_DSN}
549 test_rdbms_db2_400 => {
551 $ENV{DBICTEST_DB2_400_DSN}
558 test_rdbms_informix => {
560 $ENV{DBICTEST_INFORMIX_DSN}
567 test_rdbms_sqlanywhere => {
569 $ENV{DBICTEST_SQLANYWHERE_DSN}
576 test_rdbms_sqlanywhere_odbc => {
578 $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN}
580 %$rdbms_sqlanywhere_odbc,
585 test_rdbms_firebird => {
587 $ENV{DBICTEST_FIREBIRD_DSN}
594 test_rdbms_firebird_interbase => {
596 $ENV{DBICTEST_FIREBIRD_INTERBASE_DSN}
598 %$rdbms_firebird_interbase,
603 test_rdbms_firebird_odbc => {
605 $ENV{DBICTEST_FIREBIRD_ODBC_DSN}
607 %$rdbms_firebird_odbc,
614 $ENV{DBICTEST_MEMCACHED}
616 'Cache::Memcached' => 0,
623 %$test_and_dist_json_any,
624 'ExtUtils::MakeMaker' => '6.64',
625 'Pod::Inherit' => '0.91',
631 'CPAN::Uploader' => '0.103001',
641 # OO for (mistakenly considered) ease of extensibility, not due to any need to
642 # carry state of any sort. This API is currently used outside, so leave as-is.
643 # FIXME - make sure to not propagate this further if module is extracted as a
644 # standalone library - keep the stupidity to a DBIC-secific shim!
647 shift->_groups_to_reqs(@_)->{modreqs};
652 { $_ => $_[0]->_groups_to_reqs($_) }
657 sub req_errorlist_for {
659 $self->_errorlist_for_modreqs( $self->_groups_to_reqs(@_)->{modreqs} );
664 $self->_errorlist_for_modreqs( $self->_groups_to_reqs(@_)->{modreqs} )
670 sub req_missing_for {
673 my $reqs = $self->_groups_to_reqs(@_);
674 my $modreq_errors = $self->_errorlist_for_modreqs($reqs->{modreqs}) or return '';
677 (map { $reqs->{modreqs}{$_} ? qq("$_~>=$reqs->{modreqs}{$_}") : $_ } sort keys %$modreq_errors),
678 ( $reqs->{modreqs_fully_documented} ? "(see @{[ ref $self || $self ]} documentation for details)" : () ),
682 sub die_unless_req_ok_for {
683 if (my $err = shift->req_missing_for(@_) ) {
684 die "Required modules missing, unable to continue: $err\n";
691 our %req_unavailability_cache;
693 # this method is just a lister/metadata checker - it does not try to load anything
694 sub _groups_to_reqs {
695 my ($self, $groups) = @_;
697 $groups = [ $groups || () ]
698 unless ref $groups eq 'ARRAY';
700 croak "@{[ (caller(1))[3] ]}() expects a requirement group name or arrayref of group names"
705 modreqs_fully_documented => 1,
709 for my $group ( @$groups ) {
711 $group =~ /\A [A-Za-z][0-9A-Z_a-z]* \z/x
712 or croak "Invalid requirement group name '$group': only ascii alphanumerics and _ are allowed";
714 my $group_reqs = ($dbic_reqs->{$group}||{})->{req}
715 or croak "Requirement group '$group' is not defined";
718 for (keys %$group_reqs) {
720 $_ =~ /\A [A-Z_a-z][0-9A-Z_a-z]* (?:::[0-9A-Z_a-z]+)* \z /x
721 or croak "Requirement '$_' in group '$group' is not a valid module name";
723 # !!!DO NOT CHANGE!!!
724 # remember - version.pm may not be available on the system
725 croak "Requirement '$_' in group '$group' specifies an invalid version '$group_reqs->{$_}' (only plain non-underscored floating point decimals are supported)"
726 if ( ($group_reqs->{$_}||0) !~ / \A [0-9]+ (?: \. [0-9]+ )? \z /x );
729 # assemble into the final ret
730 for (keys %$group_reqs) {
732 $ret->{modreqs}{$_} = $group_reqs->{$_}||0 if (
734 ! exists $ret->{modreqs}{$_}
736 # we sanitized the version to be numeric above - we can just -gt it
737 ($group_reqs->{$_}||0) > $ret->{modreqs}{$_}
742 $ret->{modreqs_fully_documented} &&= !!$dbic_reqs->{$group}{pod};
749 # this method tries to load specified modreqs and returns a hashref of
750 # module/loaderror pairs for anything that failed
751 sub _errorlist_for_modreqs {
752 # args supposedly already went through _groups_to_reqs and are therefore sanitized
753 # safe to eval at will
754 my ($self, $reqs) = @_;
758 for my $m ( keys %$reqs ) {
761 if (! exists $req_unavailability_cache{$m}{$v} ) {
763 eval( "require $m;" . ( $v ? "$m->VERSION(q($v))" : '' ) );
764 $req_unavailability_cache{$m}{$v} = $@;
767 $ret->{$m} = $req_unavailability_cache{$m}{$v}
768 if $req_unavailability_cache{$m}{$v};
775 # This is to be called by the author only (automatically in Makefile.PL)
777 my ($class, $distver, $pod_dir) = @_;
779 die "No POD root dir supplied" unless $pod_dir;
782 eval { require DBIx::Class; DBIx::Class->VERSION; }
785 "\n\n---------------------------------------------------------------------\n" .
786 'Unable to load core DBIx::Class module to determine current version, '.
787 'possibly due to missing dependencies. Author-mode autodocumentation ' .
789 "\n\n---------------------------------------------------------------------\n"
792 # do not ask for a recent version, use 1.x API calls
793 # this *may* execute on a smoker with old perl or whatnot
796 (my $modfn = __PACKAGE__ . '.pm') =~ s|::|/|g;
798 (my $podfn = "$pod_dir/$modfn") =~ s/\.pm$/\.pod/;
799 (my $dir = $podfn) =~ s|/[^/]+$||;
801 File::Path::mkpath([$dir]);
803 my $sqltver = $class->req_list_for('deploy')->{'SQL::Translator'}
804 or die "Hrmm? No sqlt dep?";
812 push @chunks, <<"EOC";
813 #########################################################################
814 ##################### A U T O G E N E R A T E D ########################
815 #########################################################################
817 # The contents of this POD file are auto-generated. Any changes you make
818 # will be lost. If you need to change the generated text edit _gen_pod()
819 # at the end of $modfn
824 $class - Optional module dependency specifications (for module authors)
831 push @chunks, <<"EOC";
834 Somewhere in your build-file (e.g. L<ExtUtils::MakeMaker>'s F<Makefile.PL>):
838 \$EUMM_ARGS{CONFIGURE_REQUIRES} = {
839 \%{ \$EUMM_ARGS{CONFIGURE_REQUIRES} || {} },
840 'DBIx::Class' => '$distver',
845 my %DBIC_DEPLOY_DEPS = %{ eval {
847 $class->req_list_for('deploy');
850 \$EUMM_ARGS{PREREQ_PM} = {
852 \%{ \$EUMM_ARGS{PREREQ_PM} || {} },
857 ExtUtils::MakeMaker::WriteMakefile(\%EUMM_ARGS);
859 B<Note>: The C<eval> protection within the example is due to support for
860 requirements during L<the C<configure> build phase|CPAN::Meta::Spec/Phases>
861 not being available on a sufficient portion of production installations of
862 Perl. Robust support for such dependency requirements is available in the
863 L<CPAN> installer only since version C<1.94_56> first made available for
864 production with perl version C<5.12>. It is the belief of the current
865 maintainer that support for requirements during the C<configure> build phase
866 will not be sufficiently ubiquitous until the B<year 2020> at the earliest,
867 hence the extra care demonstrated above. It should also be noted that some
868 3rd party installers (e.g. L<cpanminus|App::cpanminus>) do the right thing
869 with configure requirements independent from the versions of perl and CPAN
875 #@@ DESCRIPTION HEADING
877 push @chunks, <<'EOC';
880 Some of the less-frequently used features of L<DBIx::Class> have external
881 module dependencies on their own. In order not to burden the average user
882 with modules they will never use, these optional dependencies are not included
883 in the base Makefile.PL. Instead an exception with a descriptive message is
884 thrown when a specific feature can't find one or several modules required for
885 its operation. This module is the central holding place for the current list
886 of such dependencies, for DBIx::Class core authors, and DBIx::Class extension
889 Dependencies are organized in L<groups|/CURRENT REQUIREMENT GROUPS> where each
890 group can list one or more required modules, with an optional minimum version
891 (or 0 for any version). Each group name (or a combination thereof) can be used
892 in the L<public methods|/METHODS> as described below.
897 #@@ REQUIREMENT GROUPLIST HEADING
899 push @chunks, '=head1 CURRENT REQUIREMENT GROUPS';
901 for my $group (sort keys %$dbic_reqs) {
902 my $p = $dbic_reqs->{$group}{pod}
905 my $modlist = $dbic_reqs->{$group}{req}
908 next unless keys %$modlist;
911 "=head2 $p->{title}",
914 ( map { "=item * $_" . ($modlist->{$_} ? " >= $modlist->{$_}" : '') } (sort keys %$modlist) ),
916 "Requirement group: B<$group>",
922 #@@ API DOCUMENTATION HEADING
924 push @chunks, <<'EOC';
928 =head2 req_group_list
932 =item Arguments: none
934 =item Return Value: \%list_of_requirement_groups
938 This method should be used by DBIx::Class packagers, to get a hashref of all
939 dependencies B<keyed> by dependency group. Each key (group name), or a combination
940 thereof (as an arrayref) can be supplied to the methods below.
941 The B<values> of the returned hash are currently a set of options B<without a
942 well defined structure>. If you have use for any of the contents - contact the
943 maintainers, instead of treating this as public (left alone stable) API.
949 =item Arguments: $group_name | \@group_names
951 =item Return Value: \%set_of_module_version_pairs
955 This method should be used by DBIx::Class extension authors, to determine the
956 version of modules a specific set of features requires for this version of
957 DBIx::Class. See the L</SYNOPSIS> for a real-world example.
963 =item Arguments: $group_name | \@group_names
965 =item Return Value: 1|0
969 Returns true or false depending on whether all modules required by
970 the group(s) are present on the system and loadable.
972 =head2 req_missing_for
976 =item Arguments: $group_name | \@group_names
978 =item Return Value: $error_message_string
982 Returns a single-line string suitable for inclusion in larger error messages.
983 This method would normally be used by DBIx::Class core-modules, to indicate to
984 the user that they need to install specific modules before being able to use a
985 specific feature set.
987 For example if some of the requirements for C<deploy> are not available,
988 the returned string could look like:
991 push @chunks, qq{ "SQL::Translator~>=$sqltver" (see $class documentation for details)};
993 push @chunks, <<'EOC';
994 The author is expected to prepend the necessary text to this message before
995 returning the actual error seen by the user.
997 =head2 die_unless_req_ok_for
1001 =item Arguments: $group_name | \@group_names
1005 Checks if L</req_ok_for> passes for the supplied group(s), and
1006 in case of failure throws an exception including the information
1007 from L</req_missing_for>.
1009 =head2 req_errorlist_for
1013 =item Arguments: $group_name | \@group_names
1015 =item Return Value: \%set_of_loaderrors_per_module
1019 Returns a hashref containing the actual errors that occurred while attempting
1020 to load each module in the requirement group(s).
1027 push @chunks, <<'EOC';
1028 =head1 FURTHER QUESTIONS?
1030 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
1032 =head1 COPYRIGHT AND LICENSE
1034 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
1035 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
1036 redistribute it and/or modify it under the same terms as the
1037 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
1041 open (my $fh, '>', $podfn) or die;
1042 print $fh join ("\n\n", @chunks) or die;
1043 print $fh "\n" or die;
1045 } or croak( "Unable to write $podfn: " . ( $! || $@ || 'unknown error') );