| 1 | package Statocles; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 61 | our $VERSION = '0.099'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: A static site generator | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 61 | ▶ | use Statocles::Base 'Class'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 61 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 61 | ▶ | use Getopt::Long qw( GetOptionsFromArray :config pass_through bundling no_auto_abbrev ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 61 | ▶ | use Pod::Usage::Return qw( pod2usage ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 61 | ▶ | use Beam::Wire; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 61 | ▶ | use Mojo::Loader qw( load_class ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 61 | my @VERBOSE = ( "warn", "info", "debug", "trace" ); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | #pod =attr site | ||||||||||||||||||||||||||||||||||||||||||
| 15 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 16 | #pod The L<site|Statocles::Site> we're working with. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 18 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 61 | has site => ( | |||||||||||||||||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | isa => InstanceOf['Statocles::Site'], | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | #pod =method run | ||||||||||||||||||||||||||||||||||||||||||
| 26 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 27 | #pod my $exitval = $cmd->run( @argv ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 29 | #pod Run the command given in @argv. See L<statocles> for a list of commands and | ||||||||||||||||||||||||||||||||||||||||||
| 30 | #pod options. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 32 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 40 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=14 SCAR=26.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 40 | my ( $class, @argv ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 40 | my %opt = ( | |||||||||||||||||||||||||||||||||||||||||
| 38 | config => 'site.yml', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | site => 'site', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | verbose => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 40 | GetOptionsFromArray( \@argv, \%opt, | |||||||||||||||||||||||||||||||||||||||||
| 43 | 'config:s', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 'site:s', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 'help|h', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 'version', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 'verbose|v+', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 'include|I:s@', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 'lib|l', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 40 | ▶ | return pod2usage(0) if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 36 | ▶ | if ( $opt{version} || ( $opt{verbose} && !@argv ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$opt{"version"} or $opt{"verbose"} and not @argv
$opt{"verbose"} and not @argv
MC/DC100%3/3
$opt{"version"} or $opt{"verbose"} and not @argv
$opt{"version"}
$opt{"verbose"}
not @argv
Truth table100%4/4
A or B and not(C)
A= $opt{"version"}B= $opt{"verbose"}C= not @argv
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | say "Statocles version $Statocles::VERSION (Perl $^V)"; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | say "Locale: " . POSIX::setlocale( POSIX::LC_CTYPE ); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 34 | ▶ | if ( $opt{lib} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | unshift @{ $opt{include} }, 'lib'; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 34 | ▶ | if ( $opt{include} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | unshift @INC, @{ $opt{include} }; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 34 | my $method = shift @argv; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 34 | ▶ | return pod2usage("ERROR: Missing command") unless $method; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # Create site does not require a config file | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 33 | ▶ | if ( $method eq 'create' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 7 | require Statocles::Command::create; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | return Statocles::Command::create->new->run( @argv ); | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 26 | my ( $exit, $site ) = _load_site( %opt ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 26 | ▶ | if ( $exit ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 10 | return $exit; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 16 | ▶ | if ( $opt{verbose} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $site->log->handle( \*STDOUT ); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $site->log->level( $VERBOSE[ $opt{verbose} ] ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | my $cmd_class = 'Statocles::Command::' . $method; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 16 | my $error = load_class( $cmd_class ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 16 | ▶ | if ( $error ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | ▶ | if ( my $app = $site->apps->{ $method } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | if ( !$app->can( 'command' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | say STDERR sprintf 'ERROR: Application "%s" has no commands', $method; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | return $app->command( $method, @argv ); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | return pod2usage("ERROR: Unknown command or app '$method'"); | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 12 | my $cmd = $cmd_class->new( site => $site ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 12 | return $cmd->run( @argv ); | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 26 | ▶ | sub _load_site { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_site: called CC=17 SCAR=30.3
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 26 | my ( %opt ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 26 | ▶ | if ( !-e $opt{config} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | warn sprintf qq{ERROR: Could not find config file "\%s"\n}, $opt{config}; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 24 | my $wire = eval { Beam::Wire->new( file => $opt{config} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 24 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | ▶ | if ( blessed $@ && $@->isa( 'Beam::Wire::Exception::Config' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($@) and $@->isa("Beam::Wire::Exception::Config")
MC/DC0%0/2
builtin::blessed($@) and $@->isa("Beam::Wire::Exception::Config")
builtin::blessed($@)
$@->isa("Beam::Wire::Exception::Config")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("Beam::Wire::Exception::Config")
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | my $remedy; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | if ( $@ =~ /found character that cannot start any token/ || $@ =~ /YAML_PARSE_ERR_NONSPACE_INDENTATION/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$@ =~ /found character that cannot start any token/ or $@ =~ /YAML_PARSE_ERR_NONSPACE_INDENTATION/
MC/DC50%1/2
$@ =~ /found character that cannot start any token/ or $@ =~ /YAML_PARSE_ERR_NONSPACE_INDENTATION/
$@ =~ /found character that cannot start any token/
$@ =~ /YAML_PARSE_ERR_NONSPACE_INDENTATION/
Truth table66%2/3
A or B
A= $@ =~ /found character that cannot start any token/B= $@ =~ /YAML_PARSE_ERR_NONSPACE_INDENTATION/
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | $remedy = "Check that you are not using tabs for indentation. "; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | ▶ | elsif ( $@ =~ /did not find expected key/ || $@ =~ /YAML_PARSE_ERR_INCONSISTENT_INDENTATION/ ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$@ =~ /did not find expected key/ or $@ =~ /YAML_PARSE_ERR_INCONSISTENT_INDENTATION/
MC/DC0%0/2
$@ =~ /did not find expected key/ or $@ =~ /YAML_PARSE_ERR_INCONSISTENT_INDENTATION/
$@ =~ /did not find expected key/
$@ =~ /YAML_PARSE_ERR_INCONSISTENT_INDENTATION/
Truth table33%1/3
A or B
A= $@ =~ /did not find expected key/B= $@ =~ /YAML_PARSE_ERR_INCONSISTENT_INDENTATION/
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | $remedy = "Check your indentation. "; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | ▶ | elsif ( $@ =~ /Syck parser/ && $@ =~ /syntax error/ ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$@ =~ /Syck parser/ and $@ =~ /syntax error/
MC/DC0%0/2
$@ =~ /Syck parser/ and $@ =~ /syntax error/
$@ =~ /Syck parser/
$@ =~ /syntax error/
Truth table0%0/3
A and B
A= $@ =~ /Syck parser/B= $@ =~ /syntax error/
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $remedy = "Check your indentation. "; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | ▶ | my $more_info = ( !$opt{verbose} ? qq{run with the "--verbose" option or } : "" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | . "check Statocles::Help::Error"; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | warn sprintf qq{ERROR: Could not load config file "%s". %sFor more information, %s.%s}, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | $opt{config}, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | $remedy, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | $more_info, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | ▶ | ( $opt{verbose} ? "\n\nRaw error: $@" : "" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | die $@; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 20 | my $site = eval { $wire->get( $opt{site} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 20 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | ▶ | if ( blessed $@ && $@->isa( 'Beam::Wire::Exception::NotFound' ) && $@->name eq $opt{site} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
builtin::blessed($@) and $@->isa("Beam::Wire::Exception::NotFound") and $@->name eq $opt{"site"}
builtin::blessed($@) and $@->isa("Beam::Wire::Exception::NotFound")
MC/DC66%2/3
builtin::blessed($@) and $@->isa("Beam::Wire::Exception::NotFound") and $@->name eq $opt{"site"}
builtin::blessed($@)
$@->isa("Beam::Wire::Exception::NotFound")
$@->name eq $opt{"site"}
Truth table75%3/4
A and B and C
A= builtin::blessed($@)B= $@->isa("Beam::Wire::Exception::NotFound")C= $@->name eq $opt{"site"}
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | warn sprintf qq{ERROR: Could not find site named "%s" in config file "%s"\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | $opt{site}, $opt{config}; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | warn sprintf qq{ERROR: Could not create site object "%s" in config file "%s": %s\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | $opt{site}, $opt{config}, $@; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 16 | return ( 0, $site ); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 103 | ▶ | sub log { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 103 | my ( $invocant, $level, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 61 | ▶ | use Mojo::Log; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 103 | ▶ | state $log = Mojo::Log->new( level => $ENV{MOJO_LOG_LEVEL} // 'info' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"MOJO_LOG_LEVEL"} // "info"
MC/DC0%0/1
$ENV{"MOJO_LOG_LEVEL"} // "info"
$ENV{"MOJO_LOG_LEVEL"}
Truth table50%1/2
A
A= $ENV{"MOJO_LOG_LEVEL"}
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 103 | ▶ | if ( $level && @args ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$level and @args
MC/DC0%0/2
$level and @args
$level
@args
Truth table33%1/3
A and B
A= $levelB= @args
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 103 | return $log->$level( @args ); | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return $log; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 61 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | __END__ | ||||||||||||||||||||||||||||||||||||||||||