File Coverage

blib/lib/App/Critique/Command/init.pm
Criterion Covered Total %
statement 12 44 27.2
branch 0 8 0.0
condition 0 12 0.0
subroutine 4 6 66.6
pod 2 2 100.0
total 18 72 25.0


line stmt bran cond sub pod time code
1             package App::Critique::Command::init;
2              
3 1     1   2083 use strict;
  1         3  
  1         26  
4 1     1   5 use warnings;
  1         2  
  1         39  
5              
6             our $VERSION = '0.05';
7             our $AUTHORITY = 'cpan:STEVAN';
8              
9 1     1   5 use App::Critique::Session;
  1         2  
  1         18  
10              
11 1     1   5 use App::Critique -command;
  1         1  
  1         6  
12              
13             sub opt_spec {
14 0     0 1   my ($class) = @_;
15             return (
16 0           [ 'perl-critic-profile=s', 'path to a Perl::Critic profile to use (default let Perl::Critic decide)' ],
17             [ 'perl-critic-theme=s', 'Perl::Critic theme expression to use' ],
18             [ 'perl-critic-policy=s', 'singular Perl::Critic policy to use (overrides -theme and -policy)' ],
19             [],
20             [ 'force', 'force overwriting of existing session file' ],
21             [],
22             $class->SUPER::opt_spec,
23             )
24             }
25              
26             sub execute {
27 0     0 1   my ($self, $opt, $args) = @_;
28              
29 0 0         if ( $opt->verbose ) {
30 0           info(HR_LIGHT);
31 0           info('Attempting to initialize session file using the following options:');
32 0           info(HR_LIGHT);
33 0   0       info(' --perl-critic-profile = %s', $opt->perl_critic_profile // '[...]');
34 0   0       info(' --perl-critic-theme = %s', $opt->perl_critic_theme // '[...]');
35 0   0       info(' --perl-critic-policy = %s', $opt->perl_critic_policy // '[...]');
36             }
37             else {
38 0           info('Attempting to initialize session file ...');
39             }
40              
41 0           my $session = App::Critique::Session->new(
42             perl_critic_profile => $opt->perl_critic_profile,
43             perl_critic_theme => $opt->perl_critic_theme,
44             perl_critic_policy => $opt->perl_critic_policy,
45             git_work_tree => $opt->git_work_tree,
46             );
47              
48 0 0         if ( $opt->verbose ) {
49 0           info(HR_LIGHT);
50 0           info('Successuflly created session with the following configuration:');
51 0           info(HR_LIGHT);
52 0   0       info(' perl_critic_profile = %s', $session->perl_critic_profile // '[...]');
53 0   0       info(' perl_critic_theme = %s', $session->perl_critic_theme // '[...]');
54 0   0       info(' perl_critic_policy = %s', $session->perl_critic_policy // '[...]');
55 0           info(' git_work_tree = %s', $session->git_work_tree );
56 0           info(' git_work_tree_root = %s', $session->git_work_tree_root );
57 0           info(' git_branch = %s', $session->git_branch );
58 0           info(' git_HEAD_sha = %s', $session->git_head_sha );
59 0           info(HR_LIGHT);
60             }
61             else {
62 0           info('Successuflly created session.');
63             }
64              
65 0 0         if ( $session->session_file_exists ) {
66 0           my $session_file_path = $session->session_file_path;
67 0 0         if ( $opt->force ) {
68 0           warning('Overwriting session file (%s) with --force option.', $session_file_path);
69             }
70             else {
71 0           error(
72             'Unable to overwrite session file (%s) without --force option.',
73             $session_file_path
74             );
75             }
76             }
77              
78 0           $self->cautiously_store_session( $session, $opt, $args );
79              
80 0           info('Session file (%s) initialized successfully.', $session->session_file_path);
81             }
82              
83             1;
84              
85             =pod
86              
87             =head1 NAME
88              
89             App::Critique::Command::init - Initialize critique session file
90              
91             =head1 VERSION
92              
93             version 0.05
94              
95             =head1 DESCRIPTION
96              
97             This command will create a critique session file in your F<~/.critique>
98             directory (including creating the F<~/.critique> directory if needed).
99             This file will be used to store information about the critque session,
100             such as the set of files you wish to critique and your progress in
101             processing the set.
102              
103             The specific file path for the critique session will be based on the
104             information provided through the command line options, and will look
105             something like this:
106              
107             ~/.critique/<git-repo>/<git-branch>/session.json
108              
109             The value of C<git-repo> will be surmised from the C<git-work-tree>
110             which itself defaults to finding the root of the C<git> working directory
111             via your current working directory.
112              
113             The value of C<git-branch> comes directly from the command line option,
114             or will default itself to the currently active C<git> branch.
115              
116             You must also supply L<Perl::Critic> informaton must be specified, either
117             as a L<Perl::Critic> profile config (ex: F<perlcriticrc>) with additional
118             L<Perl::Critic> 'theme' expression added. Alternatively you can just
119             specify a single L<Perl::Critic::Policy> to use during the critique
120             session. If no L<Perl::Critic> specific options are detected, then we will
121             do whatever is the default for L<Perl::Critic>, which currently is to
122             use all the available policies with their default configuration.
123              
124             =head1 AUTHOR
125              
126             Stevan Little <stevan@cpan.org>
127              
128             =head1 COPYRIGHT AND LICENSE
129              
130             This software is copyright (c) 2016 by Stevan Little.
131              
132             This is free software; you can redistribute it and/or modify it under
133             the same terms as the Perl 5 programming language system itself.
134              
135             =cut
136              
137             __END__
138              
139             # ABSTRACT: Initialize critique session file
140