App-CPANtoRPM
view release on metacpan or search on metacpan
lib/App/CPANtoRPM.pm view on Meta::CPAN
@OUTPUT = @out;
}
} elsif ($type eq 'function') {
my($coderef,@args) = @$method;
my @out = &$coderef(@args);
chomp(@out);
@OUTPUT = @out;
}
if (&$testfunc(@args)) {
$self->_log_indent(-1);
return 1;
}
}
if (@print) {
$self->_log_message('NONE',@print);
}
$self->_log_message('WARN','All methods for this task failed',
'Please make sure one of the above methods works.');
$self->_log_indent(-1);
return 0;
}
############################################################################
# Read in an opts file
#
sub _opt_file {
my($self,$file) = @_;
if (! -r $file) {
$self->_log_message('ERR',"Options file not readable: $file");
}
my $succ;
if ($file =~ /\.(yml|yaml)$/i) {
$succ = $self->_multiple_methods
( [ sub { 1; } ],
[ 'module', 'YAML::XS', [],
"my \@tmp = YAML::XS::LoadFile('$file'); " .
"\$OUTPUT = \$tmp[0]" ],
[ 'module', 'YAML::Tiny', [],
"my \@tmp = YAML::Tiny::LoadFile('$file'); " .
"\$OUTPUT = \$tmp[0]" ],
[ 'module', 'YAML', [],
"my \@tmp = YAML::LoadFile('$file'); " .
"\$OUTPUT = \$tmp[0]" ],
[ 'module', 'YAML::Syck', [],
"my \@tmp = YAML::Syck::LoadFile('$file'); " .
"\$OUTPUT = \$tmp[0]" ],
);
} elsif ($file =~ /\.json$/i) {
$succ = $self->_multiple_methods
( [ sub { 1; } ],
[ 'module', 'JSON::XS', ['decode_json'],
"my \$fh; " .
"open \$fh,'<:utf8','$file'; " .
"my \$json_text = do { local \$/; <\$fh> }; " .
"\$OUTPUT = decode_json(\$json_text);" ],
[ 'module', 'JSON', ['from_json'],
"my \$fh; " .
"open \$fh,'<:utf8','$file'; " .
"my \$json_text = do { local \$/; <\$fh> }; " .
"\$OUTPUT = from_json(\$json_text);" ],
[ 'module', 'JSON::PP', ['decode_json'],
"my \$fh; " .
"open \$fh,'<:utf8','$file'; " .
"my \$json_text = do { local \$/; <\$fh> }; " .
"\$OUTPUT = decode_json(\$json_text);" ],
[ 'module', 'JSON::DWIW', ['from_json'],
"my \$fh; " .
"open \$fh,'<:utf8','$file'; " .
"my \$json_text = do { local \$/; <\$fh> }; " .
"\$OUTPUT = from_json(\$json_text);" ],
);
} else {
$self->_log_message('ERR',"Options file must be YAML or JSON: $file");
}
if (! $succ) {
$self->_log_message('ERR',"Unable to read options file: $file");
}
return () if (! exists $OUTPUT->{$$self{'package'}});
my @opts;
foreach my $line (@{ $OUTPUT->{$$self{'package'}} }) {
if ($line =~ /^(.+?)(?:\s+|=)(.+?)\s*$/) {
push(@opts,$1,$2);
} else {
push(@opts,$line);
}
}
return @opts;
}
###############################################################################
# This either renames or copies a file.
#
sub _backup_file {
my($self,$file1,$file2,$copy) = @_;
if ($copy) {
if (-d $file2) {
my @f = split(/\//,$file1);
my $f = pop(@f);
$file2 = "$file2/$f";
}
if (-f $file2) {
if (! unlink $file2) {
lib/App/CPANtoRPM.pm view on Meta::CPAN
if (@tmp == $n) {
$f = '';
} elsif (@tmp < $n) {
$n = @tmp;
$f = $pod;
}
}
if ($f) {
($name,$summary,$description) = $self->_get_meta_pod($f);
$mainpod = $f;
last POD;
}
#
# We weren't able to determine the main POD file.
#
$self->_log_message
('WARN',"Automatic detection of main POD file failed.");
last POD;
}
if ($mainpod) {
$package{'files'}{'mainpod'} = [ $mainpod,$name,$summary,$description ];
}
}
# This will extract the information froma single META file.
sub _get_meta_meta {
my($self,$type,$filehash) = @_;
my $meta;
my @tmp = keys %$filehash;
if (@tmp != 1) {
my $tmp = $tmp[0];
$self->_log_message
('WARN',
"Multiple '$tmp' files exist (with different cases).",
"This is not supported, so they will be ignored.");
return;
}
my $file = "$package{DIR}/$tmp[0]";
$OUTPUT = '';
$self->_log_message('INFO',"Reading META file: $tmp[0]");
my $succ;
if ($type eq 'json') {
$succ = $self->_multiple_methods
( [ sub { 1; } ],
[ 'module', 'Parse::CPAN::Meta', '1.41', [],
"\$OUTPUT = Parse::CPAN::Meta->load_file('$file')" ],
[ 'module', 'JSON', ['from_json'],
"my \$fh; " .
"open \$fh,'<:utf8','$file'; " .
"my \$json_text = do { local \$/; <\$fh> }; " .
"\$OUTPUT = from_json(\$json_text);" ],
[ 'module', 'JSON::XS', ['decode_json'],
"my \$fh; " .
"open \$fh,'<:utf8','$file'; " .
"my \$json_text = do { local \$/; <\$fh> }; " .
"\$OUTPUT = decode_json(\$json_text);" ],
[ 'module', 'JSON::PP', ['decode_json'],
"my \$fh; " .
"open \$fh,'<:utf8','$file'; " .
"my \$json_text = do { local \$/; <\$fh> }; " .
"\$OUTPUT = decode_json(\$json_text);" ],
[ 'module', 'JSON::DWIW', ['from_json'],
"my \$fh; " .
"open \$fh,'<:utf8','$file'; " .
"my \$json_text = do { local \$/; <\$fh> }; " .
"\$OUTPUT = from_json(\$json_text);" ],
);
} else {
$succ = $self->_multiple_methods
( [ sub { 1; } ],
# [ 'module', 'Parse::CPAN::Meta', [],
# "\$OUTPUT = Parse::CPAN::Meta::LoadFile('$file')" ],
# [ 'module', 'CPAN::Meta::YAML', [],
# "my \$fh; " .
# "open \$fh,'<:utf8','$file'; " .
# "my \$yaml_text = do { local \$/; <\$fh> }; " .
# "my \$tmp = CPAN::Meta::YAML->read_string(\$yaml_text);" .
# "\$OUTPUT = \$tmp->[0]" ],
[ 'module', 'YAML', [],
"my \@tmp = YAML::LoadFile('$file'); " .
"\$OUTPUT = \$tmp[0]" ],
[ 'module', 'YAML::Syck', [],
"my \@tmp = YAML::Syck::LoadFile('$file'); " .
"\$OUTPUT = \$tmp[0]" ],
[ 'module', 'YAML::XS', [],
"my \@tmp = YAML::XS::LoadFile('$file'); " .
"\$OUTPUT = \$tmp[0]" ],
[ 'module', 'YAML::Tiny', [],
"my \@tmp = YAML::Tiny::LoadFile('$file'); " .
"\$OUTPUT = \$tmp[0]" ],
);
}
if (! $succ) {
$self->_log_message('WARN',"Unable to read META file: $tmp[0]");
return;
}
if (! $OUTPUT) {
$self->_log_message('ERR',"META file empty or corrupt: $tmp[0]");
return;
}
# Now get the meta information:
foreach my $f (qw(name version keywords abstract description author provides)) {
$self->_get_meta_field($f,"m_$f");
}
# License information is stored in multiple places:
# license => VALUE
( run in 0.546 second using v1.01-cache-2.11-cpan-6aa56a78535 )