Metadata.pm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. #line 1
  2. package Module::Install::Metadata;
  3. use strict 'vars';
  4. use Module::Install::Base ();
  5. use vars qw{$VERSION @ISA $ISCORE};
  6. BEGIN {
  7. $VERSION = '1.04';
  8. @ISA = 'Module::Install::Base';
  9. $ISCORE = 1;
  10. }
  11. my @boolean_keys = qw{
  12. sign
  13. };
  14. my @scalar_keys = qw{
  15. name
  16. module_name
  17. abstract
  18. version
  19. distribution_type
  20. tests
  21. installdirs
  22. };
  23. my @tuple_keys = qw{
  24. configure_requires
  25. build_requires
  26. requires
  27. recommends
  28. bundles
  29. resources
  30. };
  31. my @resource_keys = qw{
  32. homepage
  33. bugtracker
  34. repository
  35. };
  36. my @array_keys = qw{
  37. keywords
  38. author
  39. };
  40. *authors = \&author;
  41. sub Meta { shift }
  42. sub Meta_BooleanKeys { @boolean_keys }
  43. sub Meta_ScalarKeys { @scalar_keys }
  44. sub Meta_TupleKeys { @tuple_keys }
  45. sub Meta_ResourceKeys { @resource_keys }
  46. sub Meta_ArrayKeys { @array_keys }
  47. foreach my $key ( @boolean_keys ) {
  48. *$key = sub {
  49. my $self = shift;
  50. if ( defined wantarray and not @_ ) {
  51. return $self->{values}->{$key};
  52. }
  53. $self->{values}->{$key} = ( @_ ? $_[0] : 1 );
  54. return $self;
  55. };
  56. }
  57. foreach my $key ( @scalar_keys ) {
  58. *$key = sub {
  59. my $self = shift;
  60. return $self->{values}->{$key} if defined wantarray and !@_;
  61. $self->{values}->{$key} = shift;
  62. return $self;
  63. };
  64. }
  65. foreach my $key ( @array_keys ) {
  66. *$key = sub {
  67. my $self = shift;
  68. return $self->{values}->{$key} if defined wantarray and !@_;
  69. $self->{values}->{$key} ||= [];
  70. push @{$self->{values}->{$key}}, @_;
  71. return $self;
  72. };
  73. }
  74. foreach my $key ( @resource_keys ) {
  75. *$key = sub {
  76. my $self = shift;
  77. unless ( @_ ) {
  78. return () unless $self->{values}->{resources};
  79. return map { $_->[1] }
  80. grep { $_->[0] eq $key }
  81. @{ $self->{values}->{resources} };
  82. }
  83. return $self->{values}->{resources}->{$key} unless @_;
  84. my $uri = shift or die(
  85. "Did not provide a value to $key()"
  86. );
  87. $self->resources( $key => $uri );
  88. return 1;
  89. };
  90. }
  91. foreach my $key ( grep { $_ ne "resources" } @tuple_keys) {
  92. *$key = sub {
  93. my $self = shift;
  94. return $self->{values}->{$key} unless @_;
  95. my @added;
  96. while ( @_ ) {
  97. my $module = shift or last;
  98. my $version = shift || 0;
  99. push @added, [ $module, $version ];
  100. }
  101. push @{ $self->{values}->{$key} }, @added;
  102. return map {@$_} @added;
  103. };
  104. }
  105. # Resource handling
  106. my %lc_resource = map { $_ => 1 } qw{
  107. homepage
  108. license
  109. bugtracker
  110. repository
  111. };
  112. sub resources {
  113. my $self = shift;
  114. while ( @_ ) {
  115. my $name = shift or last;
  116. my $value = shift or next;
  117. if ( $name eq lc $name and ! $lc_resource{$name} ) {
  118. die("Unsupported reserved lowercase resource '$name'");
  119. }
  120. $self->{values}->{resources} ||= [];
  121. push @{ $self->{values}->{resources} }, [ $name, $value ];
  122. }
  123. $self->{values}->{resources};
  124. }
  125. # Aliases for build_requires that will have alternative
  126. # meanings in some future version of META.yml.
  127. sub test_requires { shift->build_requires(@_) }
  128. sub install_requires { shift->build_requires(@_) }
  129. # Aliases for installdirs options
  130. sub install_as_core { $_[0]->installdirs('perl') }
  131. sub install_as_cpan { $_[0]->installdirs('site') }
  132. sub install_as_site { $_[0]->installdirs('site') }
  133. sub install_as_vendor { $_[0]->installdirs('vendor') }
  134. sub dynamic_config {
  135. my $self = shift;
  136. my $value = @_ ? shift : 1;
  137. if ( $self->{values}->{dynamic_config} ) {
  138. # Once dynamic we never change to static, for safety
  139. return 0;
  140. }
  141. $self->{values}->{dynamic_config} = $value ? 1 : 0;
  142. return 1;
  143. }
  144. # Convenience command
  145. sub static_config {
  146. shift->dynamic_config(0);
  147. }
  148. sub perl_version {
  149. my $self = shift;
  150. return $self->{values}->{perl_version} unless @_;
  151. my $version = shift or die(
  152. "Did not provide a value to perl_version()"
  153. );
  154. # Normalize the version
  155. $version = $self->_perl_version($version);
  156. # We don't support the really old versions
  157. unless ( $version >= 5.005 ) {
  158. die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n";
  159. }
  160. $self->{values}->{perl_version} = $version;
  161. }
  162. sub all_from {
  163. my ( $self, $file ) = @_;
  164. unless ( defined($file) ) {
  165. my $name = $self->name or die(
  166. "all_from called with no args without setting name() first"
  167. );
  168. $file = join('/', 'lib', split(/-/, $name)) . '.pm';
  169. $file =~ s{.*/}{} unless -e $file;
  170. unless ( -e $file ) {
  171. die("all_from cannot find $file from $name");
  172. }
  173. }
  174. unless ( -f $file ) {
  175. die("The path '$file' does not exist, or is not a file");
  176. }
  177. $self->{values}{all_from} = $file;
  178. # Some methods pull from POD instead of code.
  179. # If there is a matching .pod, use that instead
  180. my $pod = $file;
  181. $pod =~ s/\.pm$/.pod/i;
  182. $pod = $file unless -e $pod;
  183. # Pull the different values
  184. $self->name_from($file) unless $self->name;
  185. $self->version_from($file) unless $self->version;
  186. $self->perl_version_from($file) unless $self->perl_version;
  187. $self->author_from($pod) unless @{$self->author || []};
  188. $self->license_from($pod) unless $self->license;
  189. $self->abstract_from($pod) unless $self->abstract;
  190. return 1;
  191. }
  192. sub provides {
  193. my $self = shift;
  194. my $provides = ( $self->{values}->{provides} ||= {} );
  195. %$provides = (%$provides, @_) if @_;
  196. return $provides;
  197. }
  198. sub auto_provides {
  199. my $self = shift;
  200. return $self unless $self->is_admin;
  201. unless (-e 'MANIFEST') {
  202. warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
  203. return $self;
  204. }
  205. # Avoid spurious warnings as we are not checking manifest here.
  206. local $SIG{__WARN__} = sub {1};
  207. require ExtUtils::Manifest;
  208. local *ExtUtils::Manifest::manicheck = sub { return };
  209. require Module::Build;
  210. my $build = Module::Build->new(
  211. dist_name => $self->name,
  212. dist_version => $self->version,
  213. license => $self->license,
  214. );
  215. $self->provides( %{ $build->find_dist_packages || {} } );
  216. }
  217. sub feature {
  218. my $self = shift;
  219. my $name = shift;
  220. my $features = ( $self->{values}->{features} ||= [] );
  221. my $mods;
  222. if ( @_ == 1 and ref( $_[0] ) ) {
  223. # The user used ->feature like ->features by passing in the second
  224. # argument as a reference. Accomodate for that.
  225. $mods = $_[0];
  226. } else {
  227. $mods = \@_;
  228. }
  229. my $count = 0;
  230. push @$features, (
  231. $name => [
  232. map {
  233. ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_
  234. } @$mods
  235. ]
  236. );
  237. return @$features;
  238. }
  239. sub features {
  240. my $self = shift;
  241. while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
  242. $self->feature( $name, @$mods );
  243. }
  244. return $self->{values}->{features}
  245. ? @{ $self->{values}->{features} }
  246. : ();
  247. }
  248. sub no_index {
  249. my $self = shift;
  250. my $type = shift;
  251. push @{ $self->{values}->{no_index}->{$type} }, @_ if $type;
  252. return $self->{values}->{no_index};
  253. }
  254. sub read {
  255. my $self = shift;
  256. $self->include_deps( 'YAML::Tiny', 0 );
  257. require YAML::Tiny;
  258. my $data = YAML::Tiny::LoadFile('META.yml');
  259. # Call methods explicitly in case user has already set some values.
  260. while ( my ( $key, $value ) = each %$data ) {
  261. next unless $self->can($key);
  262. if ( ref $value eq 'HASH' ) {
  263. while ( my ( $module, $version ) = each %$value ) {
  264. $self->can($key)->($self, $module => $version );
  265. }
  266. } else {
  267. $self->can($key)->($self, $value);
  268. }
  269. }
  270. return $self;
  271. }
  272. sub write {
  273. my $self = shift;
  274. return $self unless $self->is_admin;
  275. $self->admin->write_meta;
  276. return $self;
  277. }
  278. sub version_from {
  279. require ExtUtils::MM_Unix;
  280. my ( $self, $file ) = @_;
  281. $self->version( ExtUtils::MM_Unix->parse_version($file) );
  282. # for version integrity check
  283. $self->makemaker_args( VERSION_FROM => $file );
  284. }
  285. sub abstract_from {
  286. require ExtUtils::MM_Unix;
  287. my ( $self, $file ) = @_;
  288. $self->abstract(
  289. bless(
  290. { DISTNAME => $self->name },
  291. 'ExtUtils::MM_Unix'
  292. )->parse_abstract($file)
  293. );
  294. }
  295. # Add both distribution and module name
  296. sub name_from {
  297. my ($self, $file) = @_;
  298. if (
  299. Module::Install::_read($file) =~ m/
  300. ^ \s*
  301. package \s*
  302. ([\w:]+)
  303. \s* ;
  304. /ixms
  305. ) {
  306. my ($name, $module_name) = ($1, $1);
  307. $name =~ s{::}{-}g;
  308. $self->name($name);
  309. unless ( $self->module_name ) {
  310. $self->module_name($module_name);
  311. }
  312. } else {
  313. die("Cannot determine name from $file\n");
  314. }
  315. }
  316. sub _extract_perl_version {
  317. if (
  318. $_[0] =~ m/
  319. ^\s*
  320. (?:use|require) \s*
  321. v?
  322. ([\d_\.]+)
  323. \s* ;
  324. /ixms
  325. ) {
  326. my $perl_version = $1;
  327. $perl_version =~ s{_}{}g;
  328. return $perl_version;
  329. } else {
  330. return;
  331. }
  332. }
  333. sub perl_version_from {
  334. my $self = shift;
  335. my $perl_version=_extract_perl_version(Module::Install::_read($_[0]));
  336. if ($perl_version) {
  337. $self->perl_version($perl_version);
  338. } else {
  339. warn "Cannot determine perl version info from $_[0]\n";
  340. return;
  341. }
  342. }
  343. sub author_from {
  344. my $self = shift;
  345. my $content = Module::Install::_read($_[0]);
  346. if ($content =~ m/
  347. =head \d \s+ (?:authors?)\b \s*
  348. ([^\n]*)
  349. |
  350. =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
  351. .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
  352. ([^\n]*)
  353. /ixms) {
  354. my $author = $1 || $2;
  355. # XXX: ugly but should work anyway...
  356. if (eval "require Pod::Escapes; 1") {
  357. # Pod::Escapes has a mapping table.
  358. # It's in core of perl >= 5.9.3, and should be installed
  359. # as one of the Pod::Simple's prereqs, which is a prereq
  360. # of Pod::Text 3.x (see also below).
  361. $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
  362. {
  363. defined $2
  364. ? chr($2)
  365. : defined $Pod::Escapes::Name2character_number{$1}
  366. ? chr($Pod::Escapes::Name2character_number{$1})
  367. : do {
  368. warn "Unknown escape: E<$1>";
  369. "E<$1>";
  370. };
  371. }gex;
  372. }
  373. elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) {
  374. # Pod::Text < 3.0 has yet another mapping table,
  375. # though the table name of 2.x and 1.x are different.
  376. # (1.x is in core of Perl < 5.6, 2.x is in core of
  377. # Perl < 5.9.3)
  378. my $mapping = ($Pod::Text::VERSION < 2)
  379. ? \%Pod::Text::HTML_Escapes
  380. : \%Pod::Text::ESCAPES;
  381. $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
  382. {
  383. defined $2
  384. ? chr($2)
  385. : defined $mapping->{$1}
  386. ? $mapping->{$1}
  387. : do {
  388. warn "Unknown escape: E<$1>";
  389. "E<$1>";
  390. };
  391. }gex;
  392. }
  393. else {
  394. $author =~ s{E<lt>}{<}g;
  395. $author =~ s{E<gt>}{>}g;
  396. }
  397. $self->author($author);
  398. } else {
  399. warn "Cannot determine author info from $_[0]\n";
  400. }
  401. }
  402. #Stolen from M::B
  403. my %license_urls = (
  404. perl => 'http://dev.perl.org/licenses/',
  405. apache => 'http://apache.org/licenses/LICENSE-2.0',
  406. apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1',
  407. artistic => 'http://opensource.org/licenses/artistic-license.php',
  408. artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php',
  409. lgpl => 'http://opensource.org/licenses/lgpl-license.php',
  410. lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php',
  411. lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html',
  412. bsd => 'http://opensource.org/licenses/bsd-license.php',
  413. gpl => 'http://opensource.org/licenses/gpl-license.php',
  414. gpl2 => 'http://opensource.org/licenses/gpl-2.0.php',
  415. gpl3 => 'http://opensource.org/licenses/gpl-3.0.html',
  416. mit => 'http://opensource.org/licenses/mit-license.php',
  417. mozilla => 'http://opensource.org/licenses/mozilla1.1.php',
  418. open_source => undef,
  419. unrestricted => undef,
  420. restrictive => undef,
  421. unknown => undef,
  422. );
  423. sub license {
  424. my $self = shift;
  425. return $self->{values}->{license} unless @_;
  426. my $license = shift or die(
  427. 'Did not provide a value to license()'
  428. );
  429. $license = __extract_license($license) || lc $license;
  430. $self->{values}->{license} = $license;
  431. # Automatically fill in license URLs
  432. if ( $license_urls{$license} ) {
  433. $self->resources( license => $license_urls{$license} );
  434. }
  435. return 1;
  436. }
  437. sub _extract_license {
  438. my $pod = shift;
  439. my $matched;
  440. return __extract_license(
  441. ($matched) = $pod =~ m/
  442. (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?)
  443. (=head \d.*|=cut.*|)\z
  444. /xms
  445. ) || __extract_license(
  446. ($matched) = $pod =~ m/
  447. (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?)
  448. (=head \d.*|=cut.*|)\z
  449. /xms
  450. );
  451. }
  452. sub __extract_license {
  453. my $license_text = shift or return;
  454. my @phrases = (
  455. '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1,
  456. '(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1,
  457. 'Artistic and GPL' => 'perl', 1,
  458. 'GNU general public license' => 'gpl', 1,
  459. 'GNU public license' => 'gpl', 1,
  460. 'GNU lesser general public license' => 'lgpl', 1,
  461. 'GNU lesser public license' => 'lgpl', 1,
  462. 'GNU library general public license' => 'lgpl', 1,
  463. 'GNU library public license' => 'lgpl', 1,
  464. 'GNU Free Documentation license' => 'unrestricted', 1,
  465. 'GNU Affero General Public License' => 'open_source', 1,
  466. '(?:Free)?BSD license' => 'bsd', 1,
  467. 'Artistic license 2\.0' => 'artistic_2', 1,
  468. 'Artistic license' => 'artistic', 1,
  469. 'Apache (?:Software )?license' => 'apache', 1,
  470. 'GPL' => 'gpl', 1,
  471. 'LGPL' => 'lgpl', 1,
  472. 'BSD' => 'bsd', 1,
  473. 'Artistic' => 'artistic', 1,
  474. 'MIT' => 'mit', 1,
  475. 'Mozilla Public License' => 'mozilla', 1,
  476. 'Q Public License' => 'open_source', 1,
  477. 'OpenSSL License' => 'unrestricted', 1,
  478. 'SSLeay License' => 'unrestricted', 1,
  479. 'zlib License' => 'open_source', 1,
  480. 'proprietary' => 'proprietary', 0,
  481. );
  482. while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
  483. $pattern =~ s#\s+#\\s+#gs;
  484. if ( $license_text =~ /\b$pattern\b/i ) {
  485. return $license;
  486. }
  487. }
  488. return '';
  489. }
  490. sub license_from {
  491. my $self = shift;
  492. if (my $license=_extract_license(Module::Install::_read($_[0]))) {
  493. $self->license($license);
  494. } else {
  495. warn "Cannot determine license info from $_[0]\n";
  496. return 'unknown';
  497. }
  498. }
  499. sub _extract_bugtracker {
  500. my @links = $_[0] =~ m#L<(
  501. https?\Q://rt.cpan.org/\E[^>]+|
  502. https?\Q://github.com/\E[\w_]+/[\w_]+/issues|
  503. https?\Q://code.google.com/p/\E[\w_\-]+/issues/list
  504. )>#gx;
  505. my %links;
  506. @links{@links}=();
  507. @links=keys %links;
  508. return @links;
  509. }
  510. sub bugtracker_from {
  511. my $self = shift;
  512. my $content = Module::Install::_read($_[0]);
  513. my @links = _extract_bugtracker($content);
  514. unless ( @links ) {
  515. warn "Cannot determine bugtracker info from $_[0]\n";
  516. return 0;
  517. }
  518. if ( @links > 1 ) {
  519. warn "Found more than one bugtracker link in $_[0]\n";
  520. return 0;
  521. }
  522. # Set the bugtracker
  523. bugtracker( $links[0] );
  524. return 1;
  525. }
  526. sub requires_from {
  527. my $self = shift;
  528. my $content = Module::Install::_readperl($_[0]);
  529. my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg;
  530. while ( @requires ) {
  531. my $module = shift @requires;
  532. my $version = shift @requires;
  533. $self->requires( $module => $version );
  534. }
  535. }
  536. sub test_requires_from {
  537. my $self = shift;
  538. my $content = Module::Install::_readperl($_[0]);
  539. my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg;
  540. while ( @requires ) {
  541. my $module = shift @requires;
  542. my $version = shift @requires;
  543. $self->test_requires( $module => $version );
  544. }
  545. }
  546. # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
  547. # numbers (eg, 5.006001 or 5.008009).
  548. # Also, convert double-part versions (eg, 5.8)
  549. sub _perl_version {
  550. my $v = $_[-1];
  551. $v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e;
  552. $v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e;
  553. $v =~ s/(\.\d\d\d)000$/$1/;
  554. $v =~ s/_.+$//;
  555. if ( ref($v) ) {
  556. # Numify
  557. $v = $v + 0;
  558. }
  559. return $v;
  560. }
  561. sub add_metadata {
  562. my $self = shift;
  563. my %hash = @_;
  564. for my $key (keys %hash) {
  565. warn "add_metadata: $key is not prefixed with 'x_'.\n" .
  566. "Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/;
  567. $self->{values}->{$key} = $hash{$key};
  568. }
  569. }
  570. ######################################################################
  571. # MYMETA Support
  572. sub WriteMyMeta {
  573. die "WriteMyMeta has been deprecated";
  574. }
  575. sub write_mymeta_yaml {
  576. my $self = shift;
  577. # We need YAML::Tiny to write the MYMETA.yml file
  578. unless ( eval { require YAML::Tiny; 1; } ) {
  579. return 1;
  580. }
  581. # Generate the data
  582. my $meta = $self->_write_mymeta_data or return 1;
  583. # Save as the MYMETA.yml file
  584. print "Writing MYMETA.yml\n";
  585. YAML::Tiny::DumpFile('MYMETA.yml', $meta);
  586. }
  587. sub write_mymeta_json {
  588. my $self = shift;
  589. # We need JSON to write the MYMETA.json file
  590. unless ( eval { require JSON; 1; } ) {
  591. return 1;
  592. }
  593. # Generate the data
  594. my $meta = $self->_write_mymeta_data or return 1;
  595. # Save as the MYMETA.yml file
  596. print "Writing MYMETA.json\n";
  597. Module::Install::_write(
  598. 'MYMETA.json',
  599. JSON->new->pretty(1)->canonical->encode($meta),
  600. );
  601. }
  602. sub _write_mymeta_data {
  603. my $self = shift;
  604. # If there's no existing META.yml there is nothing we can do
  605. return undef unless -f 'META.yml';
  606. # We need Parse::CPAN::Meta to load the file
  607. unless ( eval { require Parse::CPAN::Meta; 1; } ) {
  608. return undef;
  609. }
  610. # Merge the perl version into the dependencies
  611. my $val = $self->Meta->{values};
  612. my $perl = delete $val->{perl_version};
  613. if ( $perl ) {
  614. $val->{requires} ||= [];
  615. my $requires = $val->{requires};
  616. # Canonize to three-dot version after Perl 5.6
  617. if ( $perl >= 5.006 ) {
  618. $perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e
  619. }
  620. unshift @$requires, [ perl => $perl ];
  621. }
  622. # Load the advisory META.yml file
  623. my @yaml = Parse::CPAN::Meta::LoadFile('META.yml');
  624. my $meta = $yaml[0];
  625. # Overwrite the non-configure dependency hashs
  626. delete $meta->{requires};
  627. delete $meta->{build_requires};
  628. delete $meta->{recommends};
  629. if ( exists $val->{requires} ) {
  630. $meta->{requires} = { map { @$_ } @{ $val->{requires} } };
  631. }
  632. if ( exists $val->{build_requires} ) {
  633. $meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } };
  634. }
  635. return $meta;
  636. }
  637. 1;