]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/commitdiff
Put the META extraction logic into a separate ->meta method
authorVincent Pit <vince@profvince.com>
Sat, 17 Apr 2010 12:26:56 +0000 (14:26 +0200)
committerVincent Pit <vince@profvince.com>
Sat, 17 Apr 2010 12:44:55 +0000 (14:44 +0200)
lib/CPANPLUS/Dist/Gentoo.pm

index a3264bb0d6ee34e0573061862a8ac3c460b23aba..5f7545f99581049312c7ec5795124051aee564db 100644 (file)
@@ -193,6 +193,7 @@ sub init {
  my $conf = $self->parent->parent->configure_object;
 
  $stat->mk_accessors(qw/name version author distribution desc uri src license
  my $conf = $self->parent->parent->configure_object;
 
  $stat->mk_accessors(qw/name version author distribution desc uri src license
+                        meta
                         fetched_arch requires
                         ebuild_name ebuild_version ebuild_dir ebuild_file
                         portdir_overlay
                         fetched_arch requires
                         ebuild_name ebuild_version ebuild_dir ebuild_file
                         portdir_overlay
@@ -365,6 +366,36 @@ sub prepare {
  return $OK->();
 }
 
  return $OK->();
 }
 
+=head2 C<meta>
+
+Returns the contents of the F<META.yml> or F<META.json> files as parsed by L<Parse::CPAN::Meta>.
+
+=cut
+
+sub meta {
+ my $self = shift;
+ my $mod  = $self->parent;
+ my $stat = $self->status;
+
+ my $meta = $stat->meta;
+ return $meta if defined $meta;
+
+ my $extract_dir = $mod->status->extract;
+
+ for my $name (qw/META.json META.yml/) {
+  my $meta_file = File::Spec->catdir($extract_dir, $name);
+  next unless -e $meta_file;
+
+  my $meta = eval { Parse::CPAN::Meta::LoadFile($meta_file) };
+  if (defined $meta) {
+   $stat->meta($meta);
+   return $meta;
+  }
+ }
+
+ return;
+}
+
 =head2 C<intuit_license>
 
 Returns an array reference to a list of Gentoo licences identifiers under which the current distribution is released.
 =head2 C<intuit_license>
 
 Returns an array reference to a list of Gentoo licences identifiers under which the current distribution is released.
@@ -390,20 +421,10 @@ sub intuit_license {
   return \@licenses if @licenses;
  }
 
   return \@licenses if @licenses;
  }
 
- my $extract_dir = $mod->status->extract;
-
- for my $meta_file (qw/META.json META.yml/) {
-  my $meta = eval {
-   Parse::CPAN::Meta::LoadFile(File::Spec->catdir(
-    $extract_dir,
-    $meta_file,
-   ));
-  } or next;
-  my $license = $meta->{license};
-  if (defined $license) {
-   my @licenses = CPANPLUS::Dist::Gentoo::Maps::license_c2g($license);
-   return \@licenses if @licenses;
-  }
+ my $license = $self->meta->{license};
+ if (defined $license) {
+  my @licenses = CPANPLUS::Dist::Gentoo::Maps::license_c2g($license);
+  return \@licenses if @licenses;
  }
 
  return [ CPANPLUS::Dist::Gentoo::Maps::license_c2g('perl') ];
  }
 
  return [ CPANPLUS::Dist::Gentoo::Maps::license_c2g('perl') ];