Pinto/Action/Doc.pm

filter: Statementstmt 93.3% 70 / 75 Branchbran 56.2% 9 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 1 totaltotal 87.3% 90 / 103 CC 9 SCAR 13.7
CC
9
Cov
87%
_build_where
8.3
execute
4.0
BEGIN
1.0
CRAP 3.9
« App/Pinto/Command/doc.pm ↑ Summary
1 # ABSTRACT: Generate html docs from the dists in a stack
2  
3 package Pinto::Action::Doc;
4 {
5 2 $Pinto::Action::Doc::VERSION = '0.004';
6 }
7  
8 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use MooseX::Types::Moose qw(HashRef Str Bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use Pinto::Constants qw(:color);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Pinto::Types qw(AuthorID StackName StackDefault StackObject);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Pinto::Util qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Pinto::ArchiveUnpacker;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Pod::ProjectDocs;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #------------------------------------------------------------------------------
20  
21 2 extends qw( Pinto::Action );
22  
23 #------------------------------------------------------------------------------
24  
25 2 has stack => (
26 is => 'ro',
27 isa => StackName | StackDefault | StackObject,
28 default => undef,
29 );
30  
31 2 has pinned => (
32 is => 'ro',
33 isa => Bool,
34 );
35  
36 2 has author => (
37 is => 'ro',
38 isa => AuthorID,
39 coerce => 1,
40 );
41  
42 2 has packages => (
43 is => 'ro',
44 isa => Str,
45 );
46  
47 2 has distributions => (
48 is => 'ro',
49 isa => Str,
50 );
51  
52 2 has local => (
53 is => 'ro',
54 isa => Bool,
55 );
56  
57 2 has out => (
58 is => 'ro',
59 isa => Str,
60 required => 1,
61 );
62  
63 2 has title => (
64 is => 'ro',
65 isa => Str,
66 default => "MyProject's Libraries",
67 );
68  
69 2 has desc => (
70 is => 'ro',
71 isa => Str,
72 default => 'manuals and libraries',
73 );
74  
75 2 has charset => (
76 is => 'ro',
77 isa => Str,
78 default => 'UTF-8',
79 );
80  
81 2 has noindex => (
82 is => 'ro',
83 isa => Bool,
84 default => 0,
85 );
86  
87 2 has forcegen => (
88 is => 'ro',
89 isa => Bool,
90 default => 0,
91 );
92  
93 2 has lang => (
94 is => 'ro',
95 isa => Str,
96 default => 'en',
97 );
98  
99 2 has where => (
100 is => 'ro',
101 isa => HashRef,
102 builder => '_build_where',
103 lazy => 1,
104 );
105  
106 #------------------------------------------------------------------------------
107  
108 1 ▶sub _build_where {
Subroutine _build_where: called CC=6 SCAR=21.2
109 1 my ($self) = @_;
110  
111 1 my $where = {};
112 1 my $stack = $self->repo->get_stack( $self->stack );
113 1 $where = { revision => $stack->head->id };
114  
115 1 ▶ if ( my $pkg_name = $self->packages ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg_name = $self->packages) 0 1 1
116 0 $where->{'package.name'} = { like => "%$pkg_name%" };
117 }
118  
119 1 ▶ if ( my $dist_name = $self->distributions ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dist_name = $self->distributions) 0 1 1
120 0 $where->{'distribution.archive'} = { like => "%$dist_name%" };
121 }
122  
123 1 ▶ if ( my $author = $self->author ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $author = $self->author) 0 1 1
124 0 $where->{'distribution.author'} = uc $author;
125 }
126  
127 1 ▶ if ( my $pinned = $self->pinned ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pinned = $self->pinned) 0 1 1
128 0 $where->{is_pinned} = 1;
129 }
130
131 1 ▶ if ( $self->local ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->local) 0 1 1
132 0 $where->{'distribution.source'} = 'LOCAL';
133 }
134  
135 1 return $where;
136 }
137  
138 #------------------------------------------------------------------------------
139  
140 1 ▶sub execute {
Subroutine execute: called CC=4 SCAR=13.9
Pod undocumented
141 1 my ($self) = @_;
142  
143 1 my $where = $self->where;
144 1 my $attrs = {
145 prefetch => [qw(revision package distribution)],
146 group_by => 'distribution.archive',
147 };
148 1 my $rs = $self->repo->db->schema->search_registration( $where, $attrs );
149  
150 1 my @dirs;
151 my @unpackers;
152 1 ▶ while ( my $reg = $rs->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reg = $rs->next) 1 1 2
153 1 my $unpacker = Pinto::ArchiveUnpacker->new(
154 archive => $reg->distribution->native_path,
155 );
156
157 # keep it in scope so it doesn't get cleaned up too soon
158 1 push @unpackers, $unpacker;
159
160 1 my $temp_dir = $unpacker->unpack;
161 1 ▶ push @dirs, "$temp_dir/lib" if -e "$temp_dir/lib";
Branch: 1 branch
BranchTrueFalseTotal
if -e "$temp_dir/lib" 1 0 1
162 1 ▶ push @dirs, "$temp_dir/bin" if -e "$temp_dir/bin";
Branch: 1 branch
BranchTrueFalseTotal
if -e "$temp_dir/bin" 0 1 1
163 }
164  
165 1 my $pd = Pod::ProjectDocs->new(
166 outroot => $self->out,
167 libroot => [ @dirs ],
168 title => $self->title,
169 desc => $self->desc,
170 charset => $self->charset,
171 index => !$self->noindex,
172 lang => $self->lang,
173 forcegen => $self->forcegen,
174 );
175 1 $pd->gen;
176  
177 1 return $self->result;
178 }
179  
180 #------------------------------------------------------------------------------
181  
182 2 __PACKAGE__->meta->make_immutable;
183  
184 #------------------------------------------------------------------------------
185  
186 2 1;
187  
188 __END__
« App/Pinto/Command/doc.pm ↑ Summary