CPANDB.pm

filter: Statementstmt 30.5% 26 / 85 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 47.0% 8 / 17 Podpod 0.0% 0 / 8 totaltotal 26.3% 34 / 129 SCAR 47.9
CC
16
Cov
26%
import
42.0
xgmml
20.0
graph
12.0
CRAP 120.8
« CPANDB/Distribution.pm ↑ Summary CPANDB/Author.pm »
1 package CPANDB;
2  
3 1 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use IO::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use DateTime 0.55 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Params::Util 1.00 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use ORLite 1.51 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use ORLite::Mirror 1.20 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = '0.18';
13 1 our @LOCATION = (
14 locale => 'C',
15 time_zone => 'UTC',
16 );
17  
18 sub import {
19 0 ▶ my $class = shift;
Subroutine import: not called CC=6 SCAR=37.4
20 0 ▶ my $params = Params::Util::_HASH(shift) || {};
Condition0%0/2
&Params::Util::_HASH(shift()) || {}
l!l
00
MC/DC0%0/1
&Params::Util::_HASH(shift()) || {}
&Params::Util::_HASH(shift())
Truth table0%0/2
A
A= &Params::Util::_HASH(shift())
Aresult
11
00
21  
22 # Pass through any params from above
23 0 ▶ $params->{url} ||= 'http://svn.ali.as/db/cpandb.bz2';
Condition0%0/2
$params->{"url"} ||= "http://svn.ali.as/db/cpandb.bz2"
l!l
00
MC/DC0%0/1
$params->{"url"} ||= "http://svn.ali.as/db/cpandb.bz2"
$params->{"url"}
Truth table0%0/2
A
A= $params->{"url"}
Aresult
11
00
24 0 ▶ $params->{maxage} ||= 24 * 60 * 60; # One day
Condition0%0/2
$params->{"maxage"} ||= 86400
l!l
00
MC/DC0%0/1
$params->{"maxage"} ||= 86400
$params->{"maxage"}
Truth table0%0/2
A
A= $params->{"maxage"}
Aresult
11
00
25  
26 # Always turn on string eval debugging if Perl is new enough
27 0 ▶ if ( $^V > 5.008008 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^V > "5.008008") 0 0 0
28 0 $^P = $^P | 0x800;
29 }
30  
31 # Prevent double-initialisation
32 0 ▶ $class->can('orlite') or
Branch: 1 branch
BranchTrueFalseTotal
$class->can("orlite") or "ORLite::Mirror"->import($params) 0 0 0
33 ORLite::Mirror->import( $params );
34  
35 0 return 1;
36 }
37  
38 sub latest {
39 0 ▶ my $class = shift;
Subroutine latest: not called CC=2 SCAR=17.9
Pod undocumented
40  
41 # Find the distribution most recently uploaded
42 0 my @latest = CPANDB::Distribution->select(
43 'ORDER BY uploaded DESC LIMIT 1',
44 );
45 0 ▶ unless ( @latest == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@latest == 1) 0 0 0
46 0 die "Unexpected number of uploads";
47 }
48  
49 # When was it?
50 0 return $latest[0]->uploaded;
51 }
52  
53 sub latest_datetime {
54 0 ▶ my $class = shift;
Subroutine latest_datetime: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my @latest = split /\D+/, $class->latest;
56 0 return DateTime->new(
57 year => $latest[0],
58 month => $latest[1],
59 day => $latest[2],
60 @LOCATION,
61 );
62 }
63  
64 sub age {
65 0 ▶ my $class = shift;
Subroutine age: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my $latest = $class->latest_datetime;
67 0 my $today = DateTime->today( @LOCATION );
68 0 my $duration = $today - $latest;
69 0 return $duration->in_units('days');
70 }
71  
72 sub distribution {
73 0 ▶ my $self = shift;
Subroutine distribution: not called CC=2 SCAR=17.9
Pod undocumented
74 0 my @dist = CPANDB::Distribution->select(
75 'where distribution = ?', $_[0],
76 );
77 0 ▶ unless ( @dist ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@dist) 0 0 0
78 0 die("Distribution '$_[0]' does not exist");
79 }
80 0 return $dist[0];
81 }
82  
83 sub graph {
84 0 ▶ require Graph;
Subroutine graph: not called CC=3 SCAR=24.8
Pod undocumented
85 0 require Graph::Directed;
86 0 my $class = shift;
87 0 my $graph = Graph::Directed->new;
88 0 foreach my $vertex ( CPANDB::Distribution->select ) {
89 0 $graph->add_vertex( $vertex->distribution );
90 }
91 0 foreach my $edge ( CPANDB::Dependency->select ) {
92 0 $graph->add_edge( $edge->distribution => $edge->dependency );
93 }
94 0 return $graph;
95 }
96  
97 sub easy {
98 0 ▶ require Graph::Easy;
Subroutine easy: not called CC=3 SCAR=24.8
Pod undocumented
99 0 my $class = shift;
100 0 my $graph = Graph::Easy->new;
101 0 foreach my $vertex ( CPANDB::Distribution->select ) {
102 0 $graph->add_vertex( $vertex->distribution );
103 }
104 0 foreach my $edge ( CPANDB::Dependency->select ) {
105 0 $graph->add_edge( $edge->distribution => $edge->dependency );
106 }
107 0 return $graph;
108 }
109  
110 sub xgmml {
111 0 ▶ require Graph::XGMML;
Subroutine xgmml: not called CC=4 SCAR=30.0
Pod undocumented
112 0 my $class = shift;
113 0 ▶ my @param = ( @_ == 1 ) ? ( OUTPUT => IO::File->new( shift, 'w' ) ) : ( @_ );
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
114 0 my $graph = Graph::XGMML->new( directed => 1, @param );
115 0 foreach my $vertex ( CPANDB::Distribution->select ) {
116 0 $graph->add_vertex( $vertex->distribution );
117 }
118 0 foreach my $edge ( CPANDB::Dependency->select ) {
119 0 $graph->add_edge( $edge->distribution => $edge->dependency );
120 }
121 0 $graph->end;
122 0 return 1;
123 }
124  
125 sub csv {
126 0 ▶ my $class = shift;
Subroutine csv: not called CC=2 SCAR=17.9
Pod undocumented
127 0 my $file = shift;
128 0 my $csv = IO::File->new($file, 'w');
129 0 foreach my $edge ( CPANDB::Dependency->select ) {
130 0 $csv->print( $edge->distribution . "\t" . $edge->dependency . "\n" );
131 }
132 0 $csv->close;
133 }
134  
135 1 1;
« CPANDB/Distribution.pm ↑ Summary CPANDB/Author.pm »