Use Optional::Dependencies for CDBICompat and its tests
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Optional / Dependencies.pm
CommitLineData
8057ed01 1package DBIx::Class::Optional::Dependencies;
2
3use warnings;
4use strict;
5
9c1700e3 6use Carp ();
fb39747c 7
8# NO EXTERNAL NON-5.8.1 CORE DEPENDENCIES EVER (e.g. C::A::G)
8057ed01 9# This module is to be loaded by Makefile.PM on a pristine system
10
f6b26571 11# POD is generated automatically by calling _gen_pod from the
12# Makefile.PL in $AUTHOR mode
13
3ade80ee 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
17my $min_json_any = {
be855469 18 'JSON::Any' => '1.23',
2a2a7b23 19};
3ade80ee 20my $test_and_dist_json_any = {
21 'JSON::Any' => '1.31',
22};
2a2a7b23 23
2b48ebff 24my $moose_basic = {
68de9438 25 'Moose' => '0.98',
26 'MooseX::Types' => '0.21',
d401ab6b 27 'MooseX::Types::LoadableClass' => '0.011',
68de9438 28};
29
30my $replicated = {
31 %$moose_basic,
2b48ebff 32};
33
ebcd0e4f 34my $admin_basic = {
35 %$moose_basic,
3ade80ee 36 %$min_json_any,
68de9438 37 'MooseX::Types::Path::Class' => '0.05',
38 'MooseX::Types::JSON' => '0.02',
68de9438 39};
40
a0361822 41my $admin_script = {
42 %$moose_basic,
43 %$admin_basic,
44 'Getopt::Long::Descriptive' => '0.081',
45 'Text::CSV' => '1.16',
46};
47
68de9438 48my $datetime_basic = {
49 'DateTime' => '0.55',
50 'DateTime::Format::Strptime' => '1.2',
ebcd0e4f 51};
52
c7d50a7d 53my $id_shortener = {
26022fb5 54 'Math::BigInt' => '1.80',
c7d50a7d 55 'Math::Base36' => '0.07',
56};
57
be68095d 58my $rdbms_sqlite = {
59 'DBD::SQLite' => '0',
60};
61my $rdbms_pg = {
62 'DBD::Pg' => '0',
63};
64my $rdbms_mssql_odbc = {
65 'DBD::ODBC' => '0',
66};
67my $rdbms_mssql_sybase = {
68 'DBD::Sybase' => '0',
69};
56dca25f 70my $rdbms_mssql_ado = {
71 'DBD::ADO' => '0',
72};
726c8f65 73my $rdbms_msaccess_odbc = {
74 'DBD::ODBC' => '0',
75};
76my $rdbms_msaccess_ado = {
77 'DBD::ADO' => '0',
78};
be68095d 79my $rdbms_mysql = {
80 'DBD::mysql' => '0',
81};
82my $rdbms_oracle = {
83 'DBD::Oracle' => '0',
84 %$id_shortener,
85};
86my $rdbms_ase = {
87 'DBD::Sybase' => '0',
88};
89my $rdbms_db2 = {
90 'DBD::DB2' => '0',
91};
199fbc45 92my $rdbms_db2_400 = {
93 'DBD::ODBC' => '0',
94};
95my $rdbms_informix = {
96 'DBD::Informix' => '0',
97};
98my $rdbms_sqlanywhere = {
99 'DBD::SQLAnywhere' => '0',
100};
101my $rdbms_sqlanywhere_odbc = {
102 'DBD::ODBC' => '0',
103};
104my $rdbms_firebird = {
105 'DBD::Firebird' => '0',
106};
107my $rdbms_firebird_interbase = {
108 'DBD::InterBase' => '0',
109};
e02b39b4 110my $rdbms_firebird_odbc = {
111 'DBD::ODBC' => '0',
112};
be68095d 113
8057ed01 114my $reqs = {
8057ed01 115 replicated => {
68de9438 116 req => $replicated,
f6b26571 117 pod => {
118 title => 'Storage::Replicated',
119 desc => 'Modules required for L<DBIx::Class::Storage::DBI::Replicated>',
120 },
8057ed01 121 },
122
68de9438 123 test_replicated => {
124 req => {
125 %$replicated,
126 'Test::Moose' => '0',
127 },
128 },
129
130
8057ed01 131 admin => {
2b48ebff 132 req => {
ebcd0e4f 133 %$admin_basic,
134 },
135 pod => {
136 title => 'DBIx::Class::Admin',
137 desc => 'Modules required for the DBIx::Class administrative library',
138 },
139 },
140
a4a02f15 141 admin_script => {
ebcd0e4f 142 req => {
a0361822 143 %$admin_script,
2b48ebff 144 },
e144415f 145 pod => {
146 title => 'dbicadmin',
147 desc => 'Modules required for the CLI DBIx::Class interface dbicadmin',
148 },
8057ed01 149 },
150
151 deploy => {
f6b26571 152 req => {
08ac7648 153 'SQL::Translator' => '0.11018',
f6b26571 154 },
155 pod => {
156 title => 'Storage::DBI::deploy()',
5529838f 157 desc => 'Modules required for L<DBIx::Class::Storage::DBI/deployment_statements> and L<DBIx::Class::Schema/deploy>',
f6b26571 158 },
8057ed01 159 },
160
c7d50a7d 161 id_shortener => {
162 req => $id_shortener,
163 },
164
0d374214 165 test_component_accessor => {
166 req => {
167 'Class::Unload' => '0.07',
168 },
169 },
170
a109c954 171 test_pod => {
f6b26571 172 req => {
cbb19edf 173 'Test::Pod' => '1.42',
a109c954 174 },
175 },
176
177 test_podcoverage => {
178 req => {
f6b26571 179 'Test::Pod::Coverage' => '1.08',
180 'Pod::Coverage' => '0.20',
a109c954 181 },
182 },
183
ffce4b65 184 test_whitespace => {
a109c954 185 req => {
8273e845 186 'Test::EOL' => '1.0',
ffce4b65 187 'Test::NoTabs' => '0.9',
f6b26571 188 },
8057ed01 189 },
190
4a233f30 191 test_strictures => {
192 req => {
b2c1212f 193 'Test::Strict' => '0.20',
4a233f30 194 },
195 },
196
2a2a7b23 197 test_prettydebug => {
3ade80ee 198 req => $min_json_any,
2a2a7b23 199 },
200
99503754 201 test_admin_script => {
202 req => {
203 %$admin_script,
3ade80ee 204 %$test_and_dist_json_any,
99503754 205 'JSON' => 0,
be855469 206 'JSON::PP' => 0,
207 'Cpanel::JSON::XS' => 0,
99503754 208 'JSON::XS' => 0,
209 $^O eq 'MSWin32'
210 # for t/admin/10script.t
211 ? ('Win32::ShellQuote' => 0)
212 # DWIW does not compile (./configure even) on win32
213 : ('JSON::DWIW' => 0 )
214 ,
215 }
216 },
217
556c4fe6 218 test_leaks_heavy => {
f6b26571 219 req => {
556c4fe6 220 'Class::MethodCache' => '0.02',
221 'PadWalker' => '1.06',
a109c954 222 },
223 },
f6b26571 224
68de9438 225 test_dt => {
226 req => $datetime_basic,
227 },
228
229 test_dt_sqlite => {
a109c954 230 req => {
68de9438 231 %$datetime_basic,
f6b26571 232 # t/36datetime.t
233 # t/60core.t
234 'DateTime::Format::SQLite' => '0',
68de9438 235 },
236 },
f6b26571 237
68de9438 238 test_dt_mysql => {
239 req => {
240 %$datetime_basic,
9c92bb1c 241 # t/inflate/datetime_mysql.t
242 # (doesn't need Mysql itself)
68de9438 243 'DateTime::Format::MySQL' => '0',
244 },
245 },
9c92bb1c 246
68de9438 247 test_dt_pg => {
248 req => {
249 %$datetime_basic,
9c92bb1c 250 # t/inflate/datetime_pg.t
251 # (doesn't need PG itself)
ab35aeab 252 'DateTime::Format::Pg' => '0.16004',
f6b26571 253 },
8057ed01 254 },
255
68de9438 256 test_cdbicompat => {
f6b26571 257 req => {
d9bd5195 258 %$datetime_basic,
f6b26571 259 'Time::Piece::MySQL' => '0',
f6b26571 260 'Date::Simple' => '3.03',
261 },
8057ed01 262 },
263
c8dc7d33 264 test_cdbicompat_deepabstractsearch => {
265 req => {
266 'Class::DBI::Plugin::DeepAbstractSearch' => '0',
267 },
268 },
269
270 cdbicompat => {
271 req => {
272 'Class::Trigger' => '0',
273 'DBIx::ContextualFetch' => '0',
274 'Clone' => '0',
275 },
276 },
277
278 cdbicompat => {
279 req => {
280 'Class::Trigger' => '0',
281 'DBIx::ContextualFetch' => '0',
282 'Clone' => '0',
283 },
284 },
285
be68095d 286 # this is just for completeness as SQLite
287 # is a core dep of DBIC for testing
288 rdbms_sqlite => {
289 req => {
290 %$rdbms_sqlite,
291 },
292 pod => {
293 title => 'SQLite support',
294 desc => 'Modules required to connect to SQLite',
295 },
296 },
297
298 rdbms_pg => {
299 req => {
a4fc1239 300 # when changing this list make sure to adjust xt/optional_deps.t
be68095d 301 %$rdbms_pg,
302 },
303 pod => {
304 title => 'PostgreSQL support',
305 desc => 'Modules required to connect to PostgreSQL',
306 },
307 },
308
309 rdbms_mssql_odbc => {
310 req => {
311 %$rdbms_mssql_odbc,
312 },
313 pod => {
314 title => 'MSSQL support via DBD::ODBC',
315 desc => 'Modules required to connect to MSSQL via DBD::ODBC',
316 },
317 },
318
319 rdbms_mssql_sybase => {
320 req => {
321 %$rdbms_mssql_sybase,
322 },
323 pod => {
324 title => 'MSSQL support via DBD::Sybase',
56dca25f 325 desc => 'Modules required to connect to MSSQL via DBD::Sybase',
326 },
327 },
328
329 rdbms_mssql_ado => {
330 req => {
331 %$rdbms_mssql_ado,
332 },
333 pod => {
334 title => 'MSSQL support via DBD::ADO (Windows only)',
335 desc => 'Modules required to connect to MSSQL via DBD::ADO. This particular DBD is available on Windows only',
be68095d 336 },
337 },
338
726c8f65 339 rdbms_msaccess_odbc => {
340 req => {
341 %$rdbms_msaccess_odbc,
342 },
343 pod => {
344 title => 'MS Access support via DBD::ODBC',
345 desc => 'Modules required to connect to MS Access via DBD::ODBC',
346 },
347 },
348
349 rdbms_msaccess_ado => {
350 req => {
351 %$rdbms_msaccess_ado,
352 },
353 pod => {
354 title => 'MS Access support via DBD::ADO (Windows only)',
355 desc => 'Modules required to connect to MS Access via DBD::ADO. This particular DBD is available on Windows only',
356 },
357 },
358
be68095d 359 rdbms_mysql => {
360 req => {
361 %$rdbms_mysql,
362 },
363 pod => {
364 title => 'MySQL support',
365 desc => 'Modules required to connect to MySQL',
366 },
367 },
368
369 rdbms_oracle => {
370 req => {
371 %$rdbms_oracle,
372 },
373 pod => {
374 title => 'Oracle support',
375 desc => 'Modules required to connect to Oracle',
376 },
377 },
378
379 rdbms_ase => {
380 req => {
381 %$rdbms_ase,
382 },
383 pod => {
384 title => 'Sybase ASE support',
385 desc => 'Modules required to connect to Sybase ASE',
386 },
387 },
388
389 rdbms_db2 => {
390 req => {
391 %$rdbms_db2,
392 },
393 pod => {
394 title => 'DB2 support',
395 desc => 'Modules required to connect to DB2',
396 },
397 },
398
199fbc45 399 rdbms_db2_400 => {
400 req => {
401 %$rdbms_db2_400,
402 },
403 pod => {
404 title => 'DB2 on AS/400 support',
405 desc => 'Modules required to connect to DB2 on AS/400',
406 },
407 },
408
409 rdbms_informix => {
410 req => {
411 %$rdbms_informix,
412 },
413 pod => {
414 title => 'Informix support',
415 desc => 'Modules required to connect to Informix',
416 },
8273e845 417 },
199fbc45 418
419 rdbms_sqlanywhere => {
420 req => {
421 %$rdbms_sqlanywhere,
422 },
423 pod => {
424 title => 'SQLAnywhere support',
425 desc => 'Modules required to connect to SQLAnywhere',
426 },
8273e845 427 },
199fbc45 428
429 rdbms_sqlanywhere_odbc => {
430 req => {
431 %$rdbms_sqlanywhere_odbc,
432 },
433 pod => {
434 title => 'SQLAnywhere support via DBD::ODBC',
435 desc => 'Modules required to connect to SQLAnywhere via DBD::ODBC',
436 },
8273e845 437 },
199fbc45 438
439 rdbms_firebird => {
440 req => {
441 %$rdbms_firebird,
442 },
443 pod => {
444 title => 'Firebird support',
445 desc => 'Modules required to connect to Firebird',
446 },
8273e845 447 },
199fbc45 448
449 rdbms_firebird_interbase => {
450 req => {
451 %$rdbms_firebird_interbase,
452 },
453 pod => {
454 title => 'Firebird support via DBD::InterBase',
455 desc => 'Modules required to connect to Firebird via DBD::InterBase',
456 },
8273e845 457 },
199fbc45 458
459 rdbms_firebird_odbc => {
460 req => {
461 %$rdbms_firebird_odbc,
462 },
463 pod => {
464 title => 'Firebird support via DBD::ODBC',
465 desc => 'Modules required to connect to Firebird via DBD::ODBC',
466 },
8273e845 467 },
199fbc45 468
be68095d 469# the order does matter because the rdbms support group might require
470# a different version that the test group
68de9438 471 test_rdbms_pg => {
f6b26571 472 req => {
473 $ENV{DBICTEST_PG_DSN}
474 ? (
a4fc1239 475 # when changing this list make sure to adjust xt/optional_deps.t
be68095d 476 %$rdbms_pg,
f6b26571 477 'DBD::Pg' => '2.009002',
f6b26571 478 ) : ()
479 },
8057ed01 480 },
481
afae8507 482 test_rdbms_mssql_odbc => {
483 req => {
484 $ENV{DBICTEST_MSSQL_ODBC_DSN}
485 ? (
be68095d 486 %$rdbms_mssql_odbc,
afae8507 487 ) : ()
488 },
489 },
490
56dca25f 491 test_rdbms_mssql_ado => {
492 req => {
493 $ENV{DBICTEST_MSSQL_ADO_DSN}
494 ? (
495 %$rdbms_mssql_ado,
496 ) : ()
497 },
498 },
499
afae8507 500 test_rdbms_mssql_sybase => {
501 req => {
502 $ENV{DBICTEST_MSSQL_DSN}
503 ? (
be68095d 504 %$rdbms_mssql_sybase,
afae8507 505 ) : ()
506 },
507 },
508
726c8f65 509 test_rdbms_msaccess_odbc => {
510 req => {
511 $ENV{DBICTEST_MSACCESS_ODBC_DSN}
512 ? (
513 %$rdbms_msaccess_odbc,
514 %$datetime_basic,
515 'Data::GUID' => '0',
516 ) : ()
517 },
518 },
519
520 test_rdbms_msaccess_ado => {
521 req => {
522 $ENV{DBICTEST_MSACCESS_ADO_DSN}
523 ? (
524 %$rdbms_msaccess_ado,
525 %$datetime_basic,
526 'Data::GUID' => 0,
527 ) : ()
528 },
529 },
530
68de9438 531 test_rdbms_mysql => {
f6b26571 532 req => {
533 $ENV{DBICTEST_MYSQL_DSN}
534 ? (
be68095d 535 %$rdbms_mysql,
f6b26571 536 ) : ()
537 },
8057ed01 538 },
539
68de9438 540 test_rdbms_oracle => {
f6b26571 541 req => {
542 $ENV{DBICTEST_ORA_DSN}
543 ? (
be68095d 544 %$rdbms_oracle,
f6b26571 545 'DateTime::Format::Oracle' => '0',
e1b7e9b4 546 'DBD::Oracle' => '1.24',
f6b26571 547 ) : ()
548 },
8057ed01 549 },
550
68de9438 551 test_rdbms_ase => {
f6b26571 552 req => {
553 $ENV{DBICTEST_SYBASE_DSN}
554 ? (
be68095d 555 %$rdbms_ase,
f6b26571 556 ) : ()
557 },
8057ed01 558 },
559
68de9438 560 test_rdbms_db2 => {
f58a165c 561 req => {
562 $ENV{DBICTEST_DB2_DSN}
563 ? (
be68095d 564 %$rdbms_db2,
f58a165c 565 ) : ()
566 },
567 },
568
199fbc45 569 test_rdbms_db2_400 => {
570 req => {
571 $ENV{DBICTEST_DB2_400_DSN}
572 ? (
573 %$rdbms_db2_400,
574 ) : ()
575 },
576 },
577
578 test_rdbms_informix => {
579 req => {
580 $ENV{DBICTEST_INFORMIX_DSN}
581 ? (
582 %$rdbms_informix,
583 ) : ()
584 },
585 },
586
587 test_rdbms_sqlanywhere => {
588 req => {
589 $ENV{DBICTEST_SQLANYWHERE_DSN}
590 ? (
591 %$rdbms_sqlanywhere,
592 ) : ()
593 },
594 },
595
596 test_rdbms_sqlanywhere_odbc => {
597 req => {
598 $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN}
599 ? (
600 %$rdbms_sqlanywhere_odbc,
601 ) : ()
602 },
603 },
604
605 test_rdbms_firebird => {
606 req => {
607 $ENV{DBICTEST_FIREBIRD_DSN}
608 ? (
609 %$rdbms_firebird,
610 ) : ()
611 },
612 },
613
614 test_rdbms_firebird_interbase => {
615 req => {
616 $ENV{DBICTEST_FIREBIRD_INTERBASE_DSN}
617 ? (
618 %$rdbms_firebird_interbase,
619 ) : ()
620 },
621 },
622
e02b39b4 623 test_rdbms_firebird_odbc => {
624 req => {
625 $ENV{DBICTEST_FIREBIRD_ODBC_DSN}
626 ? (
627 %$rdbms_firebird_odbc,
628 ) : ()
629 },
630 },
631
42168332 632 test_memcached => {
633 req => {
634 $ENV{DBICTEST_MEMCACHED}
635 ? (
636 'Cache::Memcached' => 0,
637 ) : ()
638 },
639 },
640
344f1f52 641 dist_dir => {
642 req => {
3ade80ee 643 %$test_and_dist_json_any,
b81d8515 644 'ExtUtils::MakeMaker' => '6.64',
06fc872a 645 'Pod::Inherit' => '0.91',
646 },
344f1f52 647 },
648
649 dist_upload => {
650 req => {
651 'CPAN::Uploader' => '0.103001',
652 },
653 },
654
8057ed01 655};
656
344f1f52 657our %req_availability_cache;
f6b26571 658
fb39747c 659sub req_list_for {
660 my ($class, $group) = @_;
661
9c1700e3 662 Carp::croak "req_list_for() expects a requirement group name"
fb39747c 663 unless $group;
664
f6b26571 665 my $deps = $reqs->{$group}{req}
9c1700e3 666 or Carp::croak "Requirement group '$group' does not exist";
fb39747c 667
668 return { %$deps };
669}
670
671
344f1f52 672sub die_unless_req_ok_for {
673 my ($class, $group) = @_;
674
675 Carp::croak "die_unless_req_ok_for() expects a requirement group name"
676 unless $group;
677
678 $class->_check_deps($group)->{status}
679 or die sprintf( "Required modules missing, unable to continue: %s\n", $class->_check_deps($group)->{missing} );
680}
681
fb39747c 682sub req_ok_for {
683 my ($class, $group) = @_;
684
9c1700e3 685 Carp::croak "req_ok_for() expects a requirement group name"
fb39747c 686 unless $group;
687
d8799bab 688 return $class->_check_deps($group)->{status};
fb39747c 689}
690
691sub req_missing_for {
692 my ($class, $group) = @_;
693
9c1700e3 694 Carp::croak "req_missing_for() expects a requirement group name"
fb39747c 695 unless $group;
696
d8799bab 697 return $class->_check_deps($group)->{missing};
fb39747c 698}
699
700sub req_errorlist_for {
701 my ($class, $group) = @_;
702
9c1700e3 703 Carp::croak "req_errorlist_for() expects a requirement group name"
fb39747c 704 unless $group;
705
d8799bab 706 return $class->_check_deps($group)->{errorlist};
fb39747c 707}
708
709sub _check_deps {
710 my ($class, $group) = @_;
711
d8799bab 712 return $req_availability_cache{$group} ||= do {
713
714 my $deps = $class->req_list_for ($group);
715
716 my %errors;
717 for my $mod (keys %$deps) {
718 my $req_line = "require $mod;";
719 if (my $ver = $deps->{$mod}) {
720 $req_line .= "$mod->VERSION($ver);";
721 }
722
723 eval $req_line;
724
725 $errors{$mod} = $@ if $@;
726 }
727
728 my $res;
fb39747c 729
d8799bab 730 if (keys %errors) {
731 my $missing = join (', ', map { $deps->{$_} ? "$_ >= $deps->{$_}" : $_ } (sort keys %errors) );
732 $missing .= " (see $class for details)" if $reqs->{$group}{pod};
733 $res = {
734 status => 0,
735 errorlist => \%errors,
736 missing => $missing,
737 };
fb39747c 738 }
739 else {
d8799bab 740 $res = {
741 status => 1,
742 errorlist => {},
743 missing => '',
744 };
fb39747c 745 }
746
d8799bab 747 $res;
748 };
fb39747c 749}
750
e3fc11e1 751sub req_group_list {
752 return { map { $_ => { %{ $reqs->{$_}{req} || {} } } } (keys %$reqs) };
753}
754
755# This is to be called by the author only (automatically in Makefile.PL)
f6b26571 756sub _gen_pod {
47589465 757 my ($class, $distver, $pod_dir) = @_;
31fa1764 758
47589465 759 die "No POD root dir supplied" unless $pod_dir;
31fa1764 760
ccebe1f1 761 $distver ||=
31fa1764 762 eval { require DBIx::Class; DBIx::Class->VERSION; }
763 ||
ccebe1f1 764 die
31fa1764 765"\n\n---------------------------------------------------------------------\n" .
766'Unable to load core DBIx::Class module to determine current version, '.
767'possibly due to missing dependencies. Author-mode autodocumentation ' .
768"halted\n\n" . $@ .
769"\n\n---------------------------------------------------------------------\n"
31fa1764 770 ;
771
3d4c5a84 772 # do not ask for a recent version, use 1.x API calls
47589465 773 # this *may* execute on a smoker with old perl or whatnot
774 require File::Path;
775
776 (my $modfn = __PACKAGE__ . '.pm') =~ s|::|/|g;
777
778 (my $podfn = "$pod_dir/$modfn") =~ s/\.pm$/\.pod/;
779 (my $dir = $podfn) =~ s|/[^/]+$||;
780
781 File::Path::mkpath([$dir]);
782
e3fc11e1 783 my $sqltver = $class->req_list_for ('deploy')->{'SQL::Translator'}
784 or die "Hrmm? No sqlt dep?";
7e3dc46f 785
f6b26571 786 my @chunks = (
6343a203 787 <<"EOC",
af4ac504 788#########################################################################
789##################### A U T O G E N E R A T E D ########################
790#########################################################################
791#
792# The contents of this POD file are auto-generated. Any changes you make
793# will be lost. If you need to change the generated text edit _gen_pod()
794# at the end of $modfn
795#
796EOC
f6b26571 797 '=head1 NAME',
7e3dc46f 798 "$class - Optional module dependency specifications (for module authors)",
e3fc11e1 799 '=head1 SYNOPSIS',
d8799bab 800 <<"EOS",
7e3dc46f 801Somewhere in your build-file (e.g. L<Module::Install>'s Makefile.PL):
802
803 ...
804
805 configure_requires 'DBIx::Class' => '$distver';
806
807 require $class;
808
be68095d 809 my \$deploy_deps = $class->req_list_for('deploy');
7e3dc46f 810
811 for (keys %\$deploy_deps) {
812 requires \$_ => \$deploy_deps->{\$_};
813 }
814
815 ...
816
817Note that there are some caveats regarding C<configure_requires()>, more info
818can be found at L<Module::Install/configure_requires>
819EOS
f6b26571 820 '=head1 DESCRIPTION',
821 <<'EOD',
822Some of the less-frequently used features of L<DBIx::Class> have external
823module dependencies on their own. In order not to burden the average user
824with modules he will never use, these optional dependencies are not included
825in the base Makefile.PL. Instead an exception with a descriptive message is
826thrown when a specific feature is missing one or several modules required for
827its operation. This module is the central holding place for the current list
7e3dc46f 828of such dependencies, for DBIx::Class core authors, and DBIx::Class extension
829authors alike.
f6b26571 830EOD
831 '=head1 CURRENT REQUIREMENT GROUPS',
832 <<'EOD',
833Dependencies are organized in C<groups> and each group can list one or more
834required modules, with an optional minimum version (or 0 for any version).
ecb68746 835The group name can be used in the
f6b26571 836EOD
837 );
838
839 for my $group (sort keys %$reqs) {
840 my $p = $reqs->{$group}{pod}
841 or next;
842
843 my $modlist = $reqs->{$group}{req}
844 or next;
845
846 next unless keys %$modlist;
847
848 push @chunks, (
849 "=head2 $p->{title}",
850 "$p->{desc}",
851 '=over',
852 ( map { "=item * $_" . ($modlist->{$_} ? " >= $modlist->{$_}" : '') } (sort keys %$modlist) ),
853 '=back',
854 "Requirement group: B<$group>",
855 );
856 }
857
858 push @chunks, (
859 '=head1 METHODS',
e3fc11e1 860 '=head2 req_group_list',
861 '=over',
d8799bab 862 '=item Arguments: none',
fb13a49f 863 '=item Return Value: \%list_of_requirement_groups',
e3fc11e1 864 '=back',
d8799bab 865 <<'EOD',
e3fc11e1 866This method should be used by DBIx::Class packagers, to get a hashref of all
867dependencies keyed by dependency group. Each key (group name) can be supplied
868to one of the group-specific methods below.
869EOD
870
f6b26571 871 '=head2 req_list_for',
872 '=over',
873 '=item Arguments: $group_name',
fb13a49f 874 '=item Return Value: \%list_of_module_version_pairs',
f6b26571 875 '=back',
d8799bab 876 <<'EOD',
f6b26571 877This method should be used by DBIx::Class extension authors, to determine the
7e3dc46f 878version of modules a specific feature requires in the B<current> version of
e3fc11e1 879DBIx::Class. See the L</SYNOPSIS> for a real-world
7e3dc46f 880example.
f6b26571 881EOD
882
883 '=head2 req_ok_for',
884 '=over',
885 '=item Arguments: $group_name',
fb13a49f 886 '=item Return Value: 1|0',
f6b26571 887 '=back',
d8799bab 888 <<'EOD',
889Returns true or false depending on whether all modules required by
890C<$group_name> are present on the system and loadable.
891EOD
f6b26571 892
893 '=head2 req_missing_for',
894 '=over',
895 '=item Arguments: $group_name',
fb13a49f 896 '=item Return Value: $error_message_string',
f6b26571 897 '=back',
d8799bab 898 <<"EOD",
f6b26571 899Returns a single line string suitable for inclusion in larger error messages.
900This method would normally be used by DBIx::Class core-module author, to
901indicate to the user that he needs to install specific modules before he will
902be able to use a specific feature.
903
e3fc11e1 904For example if some of the requirements for C<deploy> are not available,
905the returned string could look like:
f6b26571 906
e3fc11e1 907 SQL::Translator >= $sqltver (see $class for details)
f6b26571 908
909The author is expected to prepend the necessary text to this message before
910returning the actual error seen by the user.
911EOD
912
344f1f52 913 '=head2 die_unless_req_ok_for',
914 '=over',
915 '=item Arguments: $group_name',
916 '=back',
917 <<'EOD',
918Checks if L</req_ok_for> passes for the supplied C<$group_name>, and
919in case of failure throws an exception including the information
920from L</req_missing_for>.
921EOD
922
f6b26571 923 '=head2 req_errorlist_for',
924 '=over',
925 '=item Arguments: $group_name',
fb13a49f 926 '=item Return Value: \%list_of_loaderrors_per_module',
f6b26571 927 '=back',
928 <<'EOD',
4a0eed52 929Returns a hashref containing the actual errors that occurred while attempting
f6b26571 930to load each module in the requirement group.
931EOD
a2bd3796 932 '=head1 FURTHER QUESTIONS?',
933 'Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.',
934 '=head1 COPYRIGHT AND LICENSE',
935 <<'EOL',
936This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
937by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
938redistribute it and/or modify it under the same terms as the
939L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
940EOL
941
f6b26571 942 );
943
9c1700e3 944 open (my $fh, '>', $podfn) or Carp::croak "Unable to write to $podfn: $!";
f6b26571 945 print $fh join ("\n\n", @chunks);
47589465 946 print $fh "\n";
f6b26571 947 close ($fh);
948}
949
8057ed01 9501;