Website/Command/Init.pm

filter: Statementstmt 44.4% 24 / 54 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 53.8% 7 / 13 Podpod 25.0% 1 / 4 totaltotal 38.5% 32 / 83 CC 7 SCAR 19.0
CC
7
Cov
36%
_create_config_dir
20.0
validate
6.0
_create_config_file
6.0
CRAP 6.7
« Website/Command/Build.pm ↑ Summary Website/Command/Install.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package App::PM::Website::Command::Init;
5 {
6 2 $App::PM::Website::Command::Init::VERSION = '0.131611';
7 }
8 2 ▶use base 'App::PM::Website::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use YAML::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use File::Path 2.07 qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #ABSTRACT: create skeleton config/pm-website.yaml
15  
16 sub options
17 0 ▶{
Subroutine options: not called CC=1 SCAR=6.9
Pod undocumented
18 0 my ($class, $app) = @_;
19  
20 return (
21 0 [ 'username' => 'pm.org username',
22 { default => 'USERNAME' }
23 ],
24 [ 'groupname' => 'long city name of monger group',
25 { default => 'GROUPNAME' }
26 ],
27 );
28 return
29 0 }
30  
31 sub validate
32 0 ▶{
Subroutine validate: not called CC=2 SCAR=17.9
Pod undocumented
33 0 my ($self, $opt, $args ) = @_;
34 0 ▶ die $self->usage_error( "no arguments allowed") if @$args;
Branch: 1 branch
BranchTrueFalseTotal
if @$args 0 0 0
35  
36 0 return 1;
37 }
38  
39 sub _create_config_dir
40 0 ▶{
Subroutine _create_config_dir: not called CC=4 SCAR=30.0
41 0 my ( $self, $opt, $config_file) = @_;
42 # get path from $config_file, check that path exists as directory
43 {
44 #TODO: use File::Basename, File::Dirname
45 0 my ( $volume, $directories, $file )
46 = File::Spec->splitpath($config_file);
47 0 my $config_dir = File::Spec->catpath( $volume, $directories );
48 0 ▶ if ( !-d $config_dir )
Branch: 1 branch
BranchTrueFalseTotal
if (not -d $config_dir) 0 0 0
49 {
50 0 ▶ die "config_dir: $config_dir exists and is not a dir"
Branch: 1 branch
BranchTrueFalseTotal
if -e $config_dir 0 0 0
51 if -e $config_dir;
52 print "creating config directory: $config_dir\n"
53 0 ▶ if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 0 0 0
54 0 make_path($config_dir);
55 }
56 }
57 }
58  
59 sub _create_config_file
60 0 ▶{
Subroutine _create_config_file: not called CC=2 SCAR=17.9
61 0 my ( $self, $opt, $config_file ) = @_;
62 0 ▶ open my $config_fh, '>', $config_file
Branch: 1 branch
BranchTrueFalseTotal
open my $config_fh, ">", $config_file or die "failed to open config_file:$config_file for writing: $!" 0 0 0
63 or die "failed to open config_file:$config_file for writing: $!";
64 0 my $groupname = $opt->groupname;
65 0 my $username = $opt->username;
66 0 my $yaml = <<"EOYAML";
67 ---
68 config:
69 website:
70 certificate: cacert.pem
71 machine: groups.pm.org
72 url: https://groups.pm.org/groups/$groupname/
73 username: $username
74 template_dir:
75 build_dir:
76 location:
77 default:
78 address:
79 name:
80 url:
81 presenter:
82 default:
83 cpan: cpan username
84 description:
85 github: github username
86 name:
87 url:
88 meetings:
89 - event_date: 2012/06/14
90 location: default
91 open_call: 1
92 presentations:
93 - abstract: 'our first talk will be about #winning'
94 presenter: default
95 title: first
96 - abstract: our first talk will be about App::PM::Website
97 presenter: default
98 title: second talk
99 EOYAML
100 0 print $config_fh $yaml;
101 0 close $config_fh;
102 0 print "creating new config file: $config_file\n";
103 }
104  
105 sub validate_config
106 0 ▶{
Subroutine validate_config: not called CC=2 SCAR=17.9
Pod undocumented
107 0 my ( $self, $opt, $args ) = @_;
108 0 my $config_file = $opt->{config_file};
109 0 ▶ if ( !-e $config_file )
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $config_file) { } 0 0 0
110 {
111 0 $self->_create_config_dir( $opt, $config_file );
112 0 $self->_create_config_file( $opt, $config_file );
113 }
114 else
115 {
116 0 print "config file already exists: $config_file\n";
117 }
118 }
119  
120 sub execute
121 0 ▶{
Subroutine execute: not called CC=1 SCAR=6.9
Pod documented
122 0 my( $self, $opt, $args ) = @_;
123  
124 $self->{config}
125 0 }
126  
127 2 __PACKAGE__
128  
129 __END__
« Website/Command/Build.pm ↑ Summary Website/Command/Install.pm »