1
0

Metadata.pm 18 KB

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