File Coverage

blib/lib/Pinto/ModlistWriter.pm
Criterion Covered Total %
statement 36 36 100.0
branch 2 4 50.0
condition 1 2 50.0
subroutine 9 9 100.0
pod 0 2 0.0
total 48 53 90.5


line stmt bran cond sub pod time code
1             # ABSTRACT: Generates a stub 03modlist.data.gz file
2              
3             package Pinto::ModlistWriter;
4              
5 51     51   394 use Moose;
  51         110  
  51         504  
6 51     51   340779 use MooseX::StrictConstructor;
  51         132  
  51         477  
7 51     51   166334 use MooseX::MarkAsMethods ( autoclean => 1 );
  51         141  
  51         485  
8              
9 51     51   179509 use IO::Zlib;
  51         118  
  51         473  
10 51     51   2913 use HTTP::Date qw(time2str);
  51         116  
  51         3734  
11              
12 51     51   298 use Pinto::Types qw(File);
  51         105  
  51         491  
13 51     51   304758 use Pinto::Util qw(debug throw);
  51         123  
  51         18756  
14              
15             #------------------------------------------------------------------------------
16              
17             our $VERSION = '0.13'; # VERSION
18              
19             #------------------------------------------------------------------------------
20              
21             has stack => (
22             is => 'ro',
23             isa => 'Pinto::Schema::Result::Stack',
24             required => 1,
25             );
26              
27             has modlist_file => (
28             is => 'ro',
29             isa => File,
30             default => sub { $_[0]->stack->modules_dir->file('03modlist.data.gz') },
31             lazy => 1,
32             );
33              
34             #------------------------------------------------------------------------------
35              
36             sub write_modlist {
37 137     137 0 408 my ($self) = @_;
38              
39 137         4112 my $stack = $self->stack;
40 137         3565 my $modlist_file = $self->modlist_file;
41              
42 137         1160 debug("Writing module list for stack $stack at $modlist_file");
43              
44 137 50       767 my $fh = IO::Zlib->new( $modlist_file->stringify, 'wb' ) or throw $!;
45 137         281783 print {$fh} $self->modlist_data;
  137         733  
46 137 50       27932 close $fh or throw $!;
47              
48 137         49033 return $self;
49             }
50              
51             #------------------------------------------------------------------------------
52              
53             sub modlist_data {
54 137     137 0 441 my ($self) = @_;
55              
56 137         626 my $writer = ref $self;
57 137   50     3104 my $version = $self->VERSION || 'UNKNOWN';
58 137         641 my $package = 'CPAN::Modulelist';
59 137         955 my $date = time2str(time);
60              
61 137         5225 return <<"END_MODLIST";
62             File: 03modlist.data
63             Description: This a placeholder for CPAN.pm
64             Modcount: 0
65             Written-By: $writer version $version
66             Date: $date
67              
68             package $package;
69              
70             sub data { {} }
71              
72             1;
73             END_MODLIST
74              
75             }
76              
77             #------------------------------------------------------------------------------
78              
79             __PACKAGE__->meta->make_immutable;
80              
81             #------------------------------------------------------------------------------
82              
83             1;
84              
85             __END__
86              
87             =pod
88              
89             =encoding UTF-8
90              
91             =for :stopwords Jeffrey Ryan Thalhammer
92              
93             =head1 NAME
94              
95             Pinto::ModlistWriter - Generates a stub 03modlist.data.gz file
96              
97             =head1 VERSION
98              
99             version 0.13
100              
101             =head1 AUTHOR
102              
103             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
104              
105             =head1 COPYRIGHT AND LICENSE
106              
107             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
108              
109             This is free software; you can redistribute it and/or modify it under
110             the same terms as the Perl 5 programming language system itself.
111              
112             =cut