| 1 | package App::CPANfile2OPML; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Module::CPANfile; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use XML::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Path::Class; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use File::Path::Expand; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use constant ALL_PHASES => [qw(configure build test runtime develop)]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = "0.01"; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 1 | my ($class) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | bless {}, $class; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub convert_file { | ||||||||||||||||||||||||||
|
Subroutine
convert_file: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 2 | my ($self, $file, $target_phases) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | unless ($target_phases && @$target_phases) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$target_phases and @$target_phases
MC/DC50%1/2
$target_phases and @$target_phases
$target_phases
@$target_phases
Truth table66%2/3
A and B
A= $target_phasesB= @$target_phases
| |||||||||||||||||||||||||||||
| 26 | 1 | $target_phases = ALL_PHASES; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | my $title = $self->_title($file, $target_phases); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | my $cpanfile = Module::CPANfile->load($file); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | my @folders; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | for my $phase_name (@$target_phases) { | |||||||||||||||||||||||||||
| 36 | 6 | my $folder = $self->_phase_to_folder($cpanfile, $phase_name); | |||||||||||||||||||||||||||
| 37 | 6 | ▶ | next unless $folder; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 3 | push @folders, $folder; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | my $opml = { | |||||||||||||||||||||||||||
| 42 | opml => { | ||||||||||||||||||||||||||||
| 43 | version => '2.0', | ||||||||||||||||||||||||||||
| 44 | head => { | ||||||||||||||||||||||||||||
| 45 | title => [$title], | ||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||
| 47 | body => { | ||||||||||||||||||||||||||||
| 48 | outline => \@folders, | ||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | my $header = XMLout($opml, RootName => '', XmlDecl => '<?xml version="1.0" encoding="utf-8"?>'); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | ▶ | sub _title { | ||||||||||||||||||||||||||
|
Subroutine
_title: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 2 | my ($self, $file, $target_phases) = @_; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | my $application = Path::Class::file(Cwd::realpath($file))->parent->basename; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | my $phases = join ', ', @$target_phases; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | "$application/cpanfile($phases)"; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 6 | ▶ | sub _phase_to_folder { | ||||||||||||||||||||||||||
|
Subroutine
_phase_to_folder: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 67 | 6 | my ($self, $cpanfile, $phase_name) = @_; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 6 | my @packages = $self->_collect_packages($cpanfile, $phase_name); | |||||||||||||||||||||||||||
| 70 | 6 | ▶ | return unless @packages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | my @outlines = map { | ||||||||||||||||||||||||||||
| 73 | 3 | $self->_package_name_to_outline($_); | |||||||||||||||||||||||||||
| 74 | } @packages; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | return { | ||||||||||||||||||||||||||||
| 77 | 3 | title => $phase_name, | |||||||||||||||||||||||||||
| 78 | outline => \@outlines, | ||||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 6 | ▶ | sub _collect_packages { | ||||||||||||||||||||||||||
|
Subroutine
_collect_packages: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 83 | 6 | my ($self, $cpanfile, $phase) = @_; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # TODO: Better access to retrieve CPAN::Meta::Requirements | ||||||||||||||||||||||||||||
| 86 | 6 | my $requirements = $cpanfile->prereqs->{prereqs}->{$phase}; | |||||||||||||||||||||||||||
| 87 | 6 | ▶ | return unless $requirements; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | my @package_names = $requirements->{requires}->required_modules; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 3 | return @package_names; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 7 | ▶ | sub _package_name_to_outline { | ||||||||||||||||||||||||||
|
Subroutine
_package_name_to_outline: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 95 | 7 | my ($self, $package_name) = @_; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 7 | my $distribution_name = $package_name; | |||||||||||||||||||||||||||
| 98 | 7 | $distribution_name =~ s/(::)/-/g; | |||||||||||||||||||||||||||
| 99 | return { | ||||||||||||||||||||||||||||
| 100 | 7 | title => $package_name, | |||||||||||||||||||||||||||
| 101 | htmlUrl => "https://metacpan.org/pod/$package_name", | ||||||||||||||||||||||||||||
| 102 | xmlUrl => "https://metacpan.org/feed/distribution/$distribution_name", | ||||||||||||||||||||||||||||
| 103 | }; | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 2 | 1; | |||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||