Indexer/Reporter/AsYAML.pm

filter: Statementstmt 60.0% 36 / 60 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 12 / 16 Podpod 100% 2 / 2 totaltotal 55.5% 50 / 90 CC 8 SCAR 32.5
CC
8
Cov
50%
__ANON__
72.0
get_reporter
2.0
__ANON__
2.0
CRAP 25.8
« Indexer/Queue.pm ↑ Summary Indexer.pm »
1 package MyCPAN::Indexer::Reporter::AsYAML;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use parent qw(MyCPAN::Indexer::Reporter::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw($VERSION $logger);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = '1.282';
8  
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use YAML::Syck qw(Dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 $logger = Log::Log4perl->get_logger( 'Reporter' );
19 }
20  
21 =encoding utf8
22  
23 =head1 NAME
24  
25 MyCPAN::Indexer::Reporter::AsYAML - Save the result as a YAML file
26  
27 =head1 SYNOPSIS
28  
29 Use this in backpan_indexer.pl by specifying it as the reporter class:
30  
31 # in backpan_indexer.config
32 reporter_class MyCPAN::Indexer::Reporter::AsYAML
33  
34 =head1 DESCRIPTION
35  
36 This class takes the result of examining a distribution and saves it.
37  
38 =head2 Methods
39  
40 =over 4
41  
42 =item get_reporter( $Notes )
43  
44 C<get_reporter> sets the C<reporter> key in the C<$Notes> hash reference. The
45 value is a code reference that takes the information collected about a distribution
46 and dumps it as a YAML file.
47  
48 See L<MyCPAN::Indexer::Tutorial> for details about what C<get_reporter> expects
49 and should do.
50  
51 =cut
52  
53 sub get_reporter
54 0 ▶ {
Subroutine get_reporter: not called CC=1 SCAR=6.9
Pod documented
55 #TRACE( sub { get_caller_info } );
56  
57 0 my( $self ) = @_;
58  
59 0 ▶ my $reporter = sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
60 0 my( $info ) = @_;
61  
62 0 ▶ unless( defined $info )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info) 0 0 0
63 {
64 0 $logger->error( "info is undefined!" );
65 0 return;
66 }
67  
68 0 my $out_path = $self->get_report_path( $info );
69 0 my $dir = dirname( $out_path );
70 0 ▶ unless( -d $dir )
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
71 {
72 0 ▶ make_path( $dir ) or
Branch: 1 branch
BranchTrueFalseTotal
make_path($dir) or $MyCPAN::Indexer::Reporter::AsYAML::logger->fatal("Could not create directory ${dir}: $!") 0 0 0
73 $logger->fatal( "Could not create directory $dir: $!" );
74 }
75  
76 0 ▶ open my($fh), ">:utf8", $out_path or
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:utf8", $out_path or $MyCPAN::Indexer::Reporter::AsYAML::logger->fatal("Could not open ${out_path}: $!") 0 0 0
77 $logger->fatal( "Could not open $out_path: $!" );
78  
79 {
80 # now that indexer is a component, it has references to all the other
81 # objects, making for a big dump. We don't want the keys starting
82 # with _
83 # Storable doesn't work because it can't handle the CODE refs
84 0 my $clone = clone( $info ); # hack until we get an info class
85 0 my $dist = $clone->{dist_info}{dist_basename};
86  
87 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 $logger->warn( "Error writing to YAML output for $dist: @_" );
89 0 };
90  
91 0 foreach my $key ( keys %$clone ) {
92 0 ▶ delete $clone->{$key} if $key =~ /^_/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^_/ 0 0 0
93 }
94  
95 0 print $fh Dump( $clone );
96 }
97 0 ▶ $logger->error( "$out_path is missing!" ) unless -e $out_path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $out_path 0 0 0
98  
99 0 1;
100 0 };
101  
102 0 $self->set_note( 'reporter', $reporter );
103 0 1;
104 }
105  
106 =item get_report_file_extension
107  
108 Returns the extension for reports from this reporter. Since we're making
109 YAML files, that's C<yml>.
110  
111 =cut
112  
113 0 ▶sub get_report_file_extension { 'yml' }
Subroutine get_report_file_extension: not called CC=1 SCAR=6.9
Pod documented
114  
115 =back
116  
117 =head1 TO DO
118  
119 =head1 SOURCE AVAILABILITY
120  
121 This code is in Github:
122  
123 git://github.com/briandfoy/mycpan-indexer.git
124  
125 =head1 AUTHOR
126  
127 brian d foy, C<< <bdfoy@cpan.org> >>
128  
129 =head1 COPYRIGHT AND LICENSE
130  
131 Copyright © 2008-2018, brian d foy <bdfoy@cpan.org>. All rights reserved.
132  
133 You may redistribute this under the terms of the Artistic License 2.0.
134  
135 =cut
136  
137 1 1;
« Indexer/Queue.pm ↑ Summary Indexer.pm »