HiD/App/Command/init.pm

filter: Statementstmt 100% 54 / 54 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 97.1% 69 / 71 CC 5 SCAR 8.5
CC
5
Cov
97%
_run
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.3
« HiD/Page.pm ↑ Summary HiD/App/Command.pm »
1 # ABSTRACT: initialize a new site
2  
3  
4 package HiD::App::Command::init;
5 5 our $AUTHORITY = 'cpan:GENEHACK';
6 5 $HiD::App::Command::init::VERSION = '1.96';
7 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 extends 'HiD::App::Command';
9 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 ▶use 5.014; # strict, unicode_strings
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use warnings qw/ FATAL utf8 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use open qw/ :std :utf8 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use charnames qw/ :full /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 ▶use YAML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 5 has blog => (
22 is => 'ro' ,
23 isa => 'Bool' ,
24 traits => [ 'Getopt' ] ,
25 cmd_aliases => 'b' ,
26 documentation => 'include blog-specific features when creating site' ,
27 );
28  
29  
30 5 has github => (
31 is => 'ro' ,
32 isa => 'Bool' ,
33 traits => [ 'Getopt' ] ,
34 cmd_aliases => 'g' ,
35 documentation => 'create site ready for publishing on GitHub' ,
36 );
37  
38  
39 5 has title => (
40 is => 'ro' ,
41 isa => 'Str' ,
42 traits => [ 'Getopt' ] ,
43 cmd_aliases => 't' ,
44 documentation => 'title for your new site' ,
45 default => 'My Great New Site' ,
46 );
47  
48 sub _run {
49 3 ▶ my( $self , $opts , $args ) = @_;
Subroutine _run: called CC=5 SCAR=16.2
50  
51 3 ▶ die "TODO: github support" if $self->github;
Branch: 1 branch
BranchTrueFalseTotal
if $self->github 0 3 3
52  
53 3 for ( qw/ includes layouts site / ) {
54 9 ▶ mkdir "_$_" unless -e "_$_"
Branch: 1 branch
BranchTrueFalseTotal
unless -e "_$_" 9 0 9
55 }
56  
57 3 open( my $fh , '>' , '_layouts/default.html' );
58 3 print $fh <<EOF;
59 [% content %]
60 EOF
61 3 close $fh;
62  
63 3 ▶ $self->_init_blog if $self->blog;
Branch: 1 branch
BranchTrueFalseTotal
if $self->blog 1 2 3
64  
65 3 my $yaml = YAML::Tiny->new({ title => $self->title });
66 3 $yaml->write( '_config.yml' );
67  
68 3 say "Enjoy your new site!";
69 }
70  
71 sub _init_blog {
72 {
73 1 open( my $fh , '>' , '_layouts/post.html' );
74 1 print $fh <<EOF;
75 ---
76 layout: default
77 ---
78 [% page.title %]
79 [% content %]
80 EOF
81 1 close( $fh );
82 }
83 {
84 1 ▶ mkdir "_posts";
Subroutine _init_blog: called CC=1 SCAR=0.0
85 1 open( my $fh , '>' , '_posts/1999-09-09-first-post.markdown' );
86 1 print $fh <<EOF;
87 ---
88 layout: post
89 title: My First Post
90 ---
91 this is the first post in my new blog!
92 EOF
93 1 close( $fh );
94 }
95 }
96  
97 5 __PACKAGE__->meta->make_immutable;
98 5 1;
99  
100 __END__
101  
102 =pod
103  
104 =encoding UTF-8
105  
106 =head1 NAME
107  
108 HiD::App::Command::init - initialize a new site
109  
110 =head1 SYNOPSIS
111  
112 $ ../bin/hid init
113 Enjoy your new site!
114  
115 $ ls
116 _config.yml _includes/ _layouts/ _site/
117  
118 $ cat _config.yml
119 ---
120 title: My Great New Site
121  
122 =head1 DESCRIPTION
123  
124 Generates a directory structure and basic config for a Hid site.
125  
126 =head1 ATTRIBUTES
127  
128 =head2 blog
129  
130 If enabled, this will add in additional site features useful for bloggers.
131  
132 # FIXME doesn't actually do anything currently.
133  
134 =head2 github
135  
136 If enabled, will set the site up to be hosted on and published through GitHub.
137  
138 # FIXME doesn't actually do anything currently.
139  
140 =head2 title
141  
142 Provide a title for the site being created.
143  
144 =head1 SEE ALSO
145  
146 See L<HiD::App::Command> for additional command line options supported by all
147 sub commands.
148  
149 =head1 VERSION
150  
151 version 1.96
152  
153 =head1 AUTHOR
154  
155 John SJ Anderson <genehack@genehack.org>
156  
157 =head1 COPYRIGHT AND LICENSE
158  
159 This software is copyright (c) 2015 by John SJ Anderson.
160  
161 This is free software; you can redistribute it and/or modify it under
162 the same terms as the Perl 5 programming language system itself.
163  
164 =cut
« HiD/Page.pm ↑ Summary HiD/App/Command.pm »