Source/Dist.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Source.pm ↑ Summary Source/Package.pm »
1 package CPAN::Source::Dist;
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(Class::Accessor::Fast::XS);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 __PACKAGE__->mk_accessors(qw(
6 name
7 version_name
8 package_name
9 version
10 maturity
11 filename
12 cpanid
13 extension
14 pathname
15 source_path
16 _parent
17 ));
18 use JSON::XS;
19 use YAML::XS;
20 use URI;
21 use overload '""' => \&to_string;
22  
23 # CPAN::DistnameInfo compatible
24 sub dist { $_[0]->name; }
25  
26 sub distvname { $_[0]->version_name; }
27  
28 sub fetch_source_file {
29 my ($self,$file) = @_;
30 return unless $self->source_path;
31 my $uri = URI->new( $self->source_path . '/' . $file );
32 return $self->_parent->http_get( $uri );
33 }
34  
35 sub fetch_meta {
36 my $self = shift;
37 my $yaml = $self->fetch_source_file( 'META.yml' );
38 return YAML::XS::Load( $yaml );
39 }
40  
41 sub fetch_readme {
42 my $self = shift;
43 return $self->fetch_source_file( 'README' );
44 }
45  
46 sub fetch_changes {
47 my $self = shift;
48 return $self->fetch_source_file( 'Changes' )
49 || $self->fetch_source_file( 'Changelog' )
50 || $self->fetch_source_file( 'CHANGELOG' );
51 }
52  
53 sub fetch_todo {
54 my $self = shift;
55 return $self->fetch_source_file( 'TODO' )
56 || $self->fetch_source_file( 'Todo' );
57 }
58  
59 sub fetch_tarball {
60 # TODO:
61 }
62  
63 sub data {
64 my $self = shift;
65 return {
66 name => $self->name,
67 version_name => $self->version_name,
68 version => $self->version,
69 maturity => $self->maturity,
70 filename => $self->filename,
71 cpanid => $self->cpanid,
72 extension => $self->extension,
73 pathname => $self->pathname,
74 source_path => $self->source_path,
75 };
76 }
77  
78 sub to_string {
79 return encode_json( $_[0]->data );
80 }
81  
82 1;
« Source.pm ↑ Summary Source/Package.pm »