Local/Plugin/MailRc.pm

filter: Statementstmt 92.7% 77 / 83 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.2% 16 / 19 Podpod 100% 3 / 3 totaltotal 87.8% 108 / 123 CC 14 SCAR 19.5
CC
14
Cov
88%
index
14.6
__ANON__
2.0
initialise
2.0
CRAP 7.0
« Local/Distribution/Role/FromURI.pm ↑ Summary Local/Plugin/Duplicates.pm »
1 package CPAN::Local::Plugin::MailRc;
2 {
3 2 $CPAN::Local::Plugin::MailRc::VERSION = '0.010';
4 }
5  
6 # ABSTRACT: Update 01mailrc.txt
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use CPAN::Index::API::File::MailRc;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use CPAN::DistnameInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use IO::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Path::Class qw(file dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Path::Class::URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Regexp::Common qw(URI);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use Compress::Zlib qw(gzopen Z_STREAM_END), '$gzerrno';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use MooseX::CoercePerAttribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 extends 'CPAN::Local::Plugin';
25 2 with qw(CPAN::Local::Role::Initialise CPAN::Local::Role::Index);
26  
27 2 has 'root' =>
28 (
29 is => 'ro',
30 isa => 'Str',
31 required => 1,
32 );
33  
34 has 'source' =>
35 (
36 is => 'ro',
37 isa => 'ArrayRef[Str]',
38 traits => [qw(Array CoercePerAttribute)],
39 handles => { sources => 'elements' },
40 0 ▶ coerce => { Str => sub { [$_] } }
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 2 );
42  
43 2 has 'no_update' =>
44 (
45 is => 'ro',
46 isa => 'Bool',
47 );
48  
49 sub initialise
50 0 ▶{
Subroutine initialise: not called CC=1 SCAR=6.9
Pod documented
51 0 my $self = shift;
52  
53 0 dir($self->root)->mkpath;
54  
55 0 my $mailrc = CPAN::Index::API::File::MailRc->new(
56 repo_path => $self->root,
57 );
58  
59 0 $mailrc->write_to_tarball;
60 }
61  
62 sub index
63 1 ▶{
Subroutine index: called CC=14 SCAR=26.8
Pod documented
64 1 my ($self, @distros) = @_;
65  
66 1 ▶ return if $self->no_update;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_update 0 1 1
67  
68 1 my ( @authors, %seen_authors, %authors_in_repo );
69  
70 # extract all author ids form the local 02packages.details file
71 1 $authors_in_repo{$_}++ for map {
72 3 CPAN::DistnameInfo->new($_->{distribution})->cpanid
73 } CPAN::Index::API::File::PackagesDetails->read_from_repo_path($self->root)->packages;
74  
75 # also check the newly injected distros
76 1 $authors_in_repo{$_->{authorid}}++ for @distros;
77  
78 1 foreach my $source ( $self->sources )
79 {
80 # convert a local path to a 'file://' uri for LWP::Simple::get()
81 # (this whole business can be handled better by IO::All)
82 2 ▶ my $source_uri = $source =~ /$RE{URI}/ ? URI->new($source) : file($source)->uri;
Branch: 1 branch
BranchTrueFalseTotal
$source =~ /$CPAN::Local::Plugin::MailRc::RE{'URI'}/ ? : 0 2 2
83  
84 2 my $content = LWP::Simple::get($source_uri->as_string);
85  
86 # handle tarballs
87 2 ▶ if ($source_uri->path =~ /\.tar\.gz$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_uri->path =~ /\.tar\.gz$/) 1 1 2
88 1 my $io = IO::String->new($content);
89 1 ▶ my $gz = gzopen($io, 'rb') or croak "Cannot read gzipped mailrc: $gzerrno";
Branch: 1 branch
BranchTrueFalseTotal
my $gz = &gzopen($io, "rb") or croak("Cannot read gzipped mailrc: $CPAN::Local::Plugin::MailRc::gzerrno") 1 0 1
90  
91 1 my ($buffer, $unzipped_content);
92  
93 1 ▶ $unzipped_content .= $buffer while $gz->gzread($buffer) > 0 ;
Branch: 1 branch
BranchTrueFalseTotal
$gz->gzread($buffer) > 0 and do { $unzipped_content .= $buffer } 1 1 2
94  
95 1 ▶ croak "Error reading from mailrc: $gzerrno" . ($gzerrno+0) . "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Local::Plugin::MailRc::gzerrno != Z_STREAM_END() 0 1 1
96 if $gzerrno != Z_STREAM_END;
97  
98 1 ▶ $gz->gzclose and croak "Error closing mailrc";
Branch: 1 branch
BranchTrueFalseTotal
$gz->gzclose and croak("Error closing mailrc") 0 1 1
99  
100 1 $content = $unzipped_content;
101 }
102  
103 2 my $mailrc = CPAN::Index::API::File::MailRc->read_from_string($content);
104  
105 2 foreach my $author ( $mailrc->authors )
106 {
107 4 ▶ next if $seen_authors{$author->{authorid}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_authors{$author->{"authorid"}}++ 0 4 4
108 4 ▶ next unless $authors_in_repo{$author->{authorid}};
Branch: 1 branch
BranchTrueFalseTotal
unless $authors_in_repo{$author->{"authorid"}} 1 3 4
109 3 push @authors, $author;
110 }
111 }
112  
113 1 my $combined_mailrc = CPAN::Index::API::File::MailRc->new(
114 authors => \@authors,
115 repo_path => $self->root,
116 );
117 1 $combined_mailrc->write_to_tarball;
118 }
119  
120 0 ▶sub requires_distribution_roles { qw(Metadata) }
Subroutine requires_distribution_roles: not called CC=1 SCAR=6.9
Pod documented
121  
122 2 __PACKAGE__->meta->make_immutable;
123  
124  
125  
126 __END__
« Local/Distribution/Role/FromURI.pm ↑ Summary Local/Plugin/Duplicates.pm »