2 package Module::Install::Metadata;
5 use Module::Install::Base;
7 use vars qw{$VERSION $ISCORE @ISA};
11 @ISA = qw{Module::Install::Base};
15 name module_name abstract author version license
16 distribution_type perl_version tests installdirs
20 build_requires requires recommends bundles
24 sub Meta_ScalarKeys { @scalar_keys }
25 sub Meta_TupleKeys { @tuple_keys }
27 foreach my $key (@scalar_keys) {
30 return $self->{values}{$key} if defined wantarray and !@_;
31 $self->{values}{$key} = shift;
36 foreach my $key (@tuple_keys) {
39 return $self->{values}{$key} unless @_;
43 my $module = shift or last;
44 my $version = shift || 0;
45 if ( $module eq 'perl' ) {
46 $version =~ s{^(\d+)\.(\d+)\.(\d+)}
47 {$1 + $2/1_000 + $3/1_000_000}e;
48 $self->perl_version($version);
51 my $rv = [ $module, $version ];
54 push @{ $self->{values}{$key} }, @rv;
59 sub install_as_core { $_[0]->installdirs('perl') }
60 sub install_as_cpan { $_[0]->installdirs('site') }
61 sub install_as_site { $_[0]->installdirs('site') }
62 sub install_as_vendor { $_[0]->installdirs('vendor') }
66 return $self->{'values'}{'sign'} if defined wantarray and !@_;
67 $self->{'values'}{'sign'} = ( @_ ? $_[0] : 1 );
74 warn "You MUST provide an explicit true/false value to dynamic_config, skipping\n";
77 $self->{'values'}{'dynamic_config'} = $_[0] ? 1 : 0;
82 my ( $self, $file ) = @_;
84 unless ( defined($file) ) {
85 my $name = $self->name
86 or die "all_from called with no args without setting name() first";
87 $file = join('/', 'lib', split(/-/, $name)) . '.pm';
88 $file =~ s{.*/}{} unless -e $file;
89 die "all_from: cannot find $file from $name" unless -e $file;
92 $self->version_from($file) unless $self->version;
93 $self->perl_version_from($file) unless $self->perl_version;
95 # The remaining probes read from POD sections; if the file
96 # has an accompanying .pod, use that instead
98 if ( $pod =~ s/\.pm$/.pod/i and -e $pod ) {
102 $self->author_from($file) unless $self->author;
103 $self->license_from($file) unless $self->license;
104 $self->abstract_from($file) unless $self->abstract;
109 my $provides = ( $self->{values}{provides} ||= {} );
110 %$provides = (%$provides, @_) if @_;
116 return $self unless $self->is_admin;
118 unless (-e 'MANIFEST') {
119 warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
123 # Avoid spurious warnings as we are not checking manifest here.
125 local $SIG{__WARN__} = sub {1};
126 require ExtUtils::Manifest;
127 local *ExtUtils::Manifest::manicheck = sub { return };
129 require Module::Build;
130 my $build = Module::Build->new(
131 dist_name => $self->name,
132 dist_version => $self->version,
133 license => $self->license,
135 $self->provides(%{ $build->find_dist_packages || {} });
141 my $features = ( $self->{values}{features} ||= [] );
145 if ( @_ == 1 and ref( $_[0] ) ) {
146 # The user used ->feature like ->features by passing in the second
147 # argument as a reference. Accomodate for that.
157 ref($_) ? ( ref($_) eq 'HASH' ) ? %$_
169 while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
170 $self->feature( $name, @$mods );
172 return $self->{values}->{features}
173 ? @{ $self->{values}->{features} }
180 push @{ $self->{values}{no_index}{$type} }, @_ if $type;
181 return $self->{values}{no_index};
186 $self->include_deps( 'YAML', 0 );
189 my $data = YAML::LoadFile('META.yml');
191 # Call methods explicitly in case user has already set some values.
192 while ( my ( $key, $value ) = each %$data ) {
193 next unless $self->can($key);
194 if ( ref $value eq 'HASH' ) {
195 while ( my ( $module, $version ) = each %$value ) {
196 $self->can($key)->($self, $module => $version );
200 $self->can($key)->($self, $value);
208 return $self unless $self->is_admin;
209 $self->admin->write_meta;
214 my ( $self, $file ) = @_;
215 require ExtUtils::MM_Unix;
216 $self->version( ExtUtils::MM_Unix->parse_version($file) );
220 my ( $self, $file ) = @_;
221 require ExtUtils::MM_Unix;
224 { DISTNAME => $self->name },
226 )->parse_abstract($file)
231 my ( $self, $file ) = @_;
234 open FH, "< $file" or die "Cannot open $file.pod: $!";
235 do { local $/; <FH> };
238 sub perl_version_from {
239 my ( $self, $file ) = @_;
242 $self->_slurp($file) =~ m/
253 $self->perl_version($1);
256 warn "Cannot determine perl version info from $file\n";
262 my ( $self, $file ) = @_;
263 my $content = $self->_slurp($file);
265 =head \d \s+ (?:authors?)\b \s*
268 =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
269 .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
272 my $author = $1 || $2;
273 $author =~ s{E<lt>}{<}g;
274 $author =~ s{E<gt>}{>}g;
275 $self->author($author);
278 warn "Cannot determine author info from $file\n";
283 my ( $self, $file ) = @_;
286 $self->_slurp($file) =~ m/
289 (?:licen[cs]e|licensing|copyright|legal)\b
297 my $license_text = $1;
299 'under the same (?:terms|license) as perl itself' => 'perl',
300 'GNU public license' => 'gpl',
301 'GNU lesser public license' => 'gpl',
302 'BSD license' => 'bsd',
303 'Artistic license' => 'artistic',
307 'Artistic' => 'artistic',
310 while ( my ( $pattern, $license ) = splice( @phrases, 0, 2 ) ) {
311 $pattern =~ s{\s+}{\\s+}g;
312 if ( $license_text =~ /\b$pattern\b/i ) {
313 $self->license($license);
319 warn "Cannot determine license info from $file\n";