2 package Module::Install::Metadata;
4 use Module::Install::Base;
5 @ISA = qw{Module::Install::Base};
12 name module_name abstract author version license
13 distribution_type perl_version tests
17 build_requires requires recommends bundles
21 sub Meta_ScalarKeys { @scalar_keys }
22 sub Meta_TupleKeys { @tuple_keys }
24 foreach my $key (@scalar_keys) {
27 return $self->{values}{$key} if defined wantarray and !@_;
28 $self->{values}{$key} = shift;
33 foreach my $key (@tuple_keys) {
36 return $self->{values}{$key} unless @_;
40 my $module = shift or last;
41 my $version = shift || 0;
42 if ( $module eq 'perl' ) {
43 $version =~ s{^(\d+)\.(\d+)\.(\d+)}
44 {$1 + $2/1_000 + $3/1_000_000}e;
45 $self->perl_version($version);
48 my $rv = [ $module, $version ];
51 push @{ $self->{values}{$key} }, @rv;
58 return $self->{'values'}{'sign'} if defined wantarray and !@_;
59 $self->{'values'}{'sign'} = ( @_ ? $_[0] : 1 );
66 warn "You MUST provide an explicit true/false value to dynamic_config, skipping\n";
69 $self->{'values'}{'dynamic_config'} = $_[0] ? 1 : 0;
74 my ( $self, $file ) = @_;
76 unless ( defined($file) ) {
77 my $name = $self->name
78 or die "all_from called with no args without setting name() first";
79 $file = join('/', 'lib', split(/-/, $name)) . '.pm';
80 $file =~ s{.*/}{} unless -e $file;
81 die "all_from: cannot find $file from $name" unless -e $file;
84 $self->version_from($file) unless $self->version;
85 $self->perl_version_from($file) unless $self->perl_version;
87 # The remaining probes read from POD sections; if the file
88 # has an accompanying .pod, use that instead
90 if ( $pod =~ s/\.pm$/.pod/i and -e $pod ) {
94 $self->author_from($file) unless $self->author;
95 $self->license_from($file) unless $self->license;
96 $self->abstract_from($file) unless $self->abstract;
101 my $provides = ( $self->{values}{provides} ||= {} );
102 %$provides = (%$provides, @_) if @_;
108 return $self unless $self->is_admin;
110 unless (-e 'MANIFEST') {
111 warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
115 # Avoid spurious warnings as we are not checking manifest here.
117 local $SIG{__WARN__} = sub {1};
118 require ExtUtils::Manifest;
119 local *ExtUtils::Manifest::manicheck = sub { return };
121 require Module::Build;
122 my $build = Module::Build->new(
123 dist_name => $self->{name},
124 dist_version => $self->{version},
125 license => $self->{license},
127 $self->provides(%{ $build->find_dist_packages || {} });
133 my $features = ( $self->{values}{features} ||= [] );
137 if ( @_ == 1 and ref( $_[0] ) ) {
138 # The user used ->feature like ->features by passing in the second
139 # argument as a reference. Accomodate for that.
149 ref($_) ? ( ref($_) eq 'HASH' ) ? %$_
161 while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
162 $self->feature( $name, @$mods );
164 return $self->{values}->{features}
165 ? @{ $self->{values}->{features} }
172 push @{ $self->{values}{no_index}{$type} }, @_ if $type;
173 return $self->{values}{no_index};
178 $self->include_deps( 'YAML', 0 );
181 my $data = YAML::LoadFile('META.yml');
183 # Call methods explicitly in case user has already set some values.
184 while ( my ( $key, $value ) = each %$data ) {
185 next unless $self->can($key);
186 if ( ref $value eq 'HASH' ) {
187 while ( my ( $module, $version ) = each %$value ) {
188 $self->can($key)->($self, $module => $version );
192 $self->can($key)->($self, $value);
200 return $self unless $self->is_admin;
201 $self->admin->write_meta;
206 my ( $self, $file ) = @_;
207 require ExtUtils::MM_Unix;
208 $self->version( ExtUtils::MM_Unix->parse_version($file) );
212 my ( $self, $file ) = @_;
213 require ExtUtils::MM_Unix;
216 { DISTNAME => $self->name },
218 )->parse_abstract($file)
223 my ( $self, $file ) = @_;
226 open FH, "< $file" or die "Cannot open $file.pod: $!";
227 do { local $/; <FH> };
230 sub perl_version_from {
231 my ( $self, $file ) = @_;
234 $self->_slurp($file) =~ m/
243 $self->perl_version($1);
246 warn "Cannot determine perl version info from $file\n";
252 my ( $self, $file ) = @_;
253 my $content = $self->_slurp($file);
255 =head \d \s+ (?:authors?)\b \s*
258 =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
259 .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
262 my $author = $1 || $2;
263 $author =~ s{E<lt>}{<}g;
264 $author =~ s{E<gt>}{>}g;
265 $self->author($author);
268 warn "Cannot determine author info from $file\n";
273 my ( $self, $file ) = @_;
276 $self->_slurp($file) =~ m/
278 (?:licen[cs]e|licensing|copyright|legal)\b
285 my $license_text = $1;
287 'under the same (?:terms|license) as perl itself' => 'perl',
288 'GNU public license' => 'gpl',
289 'GNU lesser public license' => 'gpl',
290 'BSD license' => 'bsd',
291 'Artistic license' => 'artistic',
295 'Artistic' => 'artistic',
297 while ( my ( $pattern, $license ) = splice( @phrases, 0, 2 ) ) {
298 $pattern =~ s{\s+}{\\s+}g;
299 if ( $license_text =~ /\b$pattern\b/i ) {
300 $self->license($license);
306 warn "Cannot determine license info from $file\n";