| 1 | package Riji::CLI::Publish; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use feature ':5.10'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Errno qw(:POSIX); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Path::Tiny qw/path tempdir/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use File::Copy::Recursive qw/dircopy/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Wallflower::Util qw/links_from/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Wallflower; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Riji; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=20 SCAR=31.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | my $app = Riji->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | my $conf = $app->config; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | my $blog = $app->model('Blog'); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | my $repo = $blog->repo; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | my $force = grep {$_ eq '--force'} @argv; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # `git symbolic-ref --short` is available after git 1.7.10, so care older version. | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | my $current_branch = $repo->run(qw/symbolic-ref HEAD/); | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | $current_branch =~ s!refs/heads/!!; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | my $publish_branch = $blog->branch; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | unless ($force){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | my $force_announce = "or you can use --force option\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | ▶ | if ($publish_branch ne $current_branch) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | die "You need at publish branch [$publish_branch], so `git checkout $publish_branch` beforehand $force_announce"; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | ▶ | if ( my $untracked = $repo->run(qw/ls-files --others --exclude-standard --/, $blog->entry_dir) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | die "Unknown local files:\n$untracked\n\ngit add them, update .gitignore $force_announce"; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | ▶ | if (my $uncommited = $repo->run(qw/diff HEAD --name-only --/, $blog->entry_dir) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | die "Found uncommited changes:\n$uncommited\n\ncommit them beforehand $force_announce"; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | say "start scanning"; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | my $dir = $conf->{publish_dir} // 'blog'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{"publish_dir"} // "blog"
MC/DC0%0/1
$conf->{"publish_dir"} // "blog"
$conf->{"publish_dir"}
Truth table50%1/2
A
A= $conf->{"publish_dir"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | unless (mkdir $dir or $! == EEXIST ){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
mkdir $dir or $! == 17
MC/DC0%0/2
mkdir $dir or $! == 17
mkdir $dir
$! == 17
Truth table33%1/3
A or B
A= mkdir $dirB= $! == 17
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | printf "can't create $dir: $!\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | my $work_dir = tempdir(CLEANUP => 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | my $site_url = $blog->site_url; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | my $mount_path = $site_url->path; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | $mount_path = '' if $mount_path eq '/'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | my $wallflower = Wallflower->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | application => $app->to_psgi, | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | destination => $work_dir . '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | url => $site_url, | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | my $host_reg = quotemeta $site_url->host; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | ▶ | my @queue = ($mount_path || '/'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$mount_path || '/'
MC/DC0%0/1
$mount_path || '/'
$mount_path
Truth table50%1/2
A
A= $mount_path
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | ▶ | while (@queue) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 241 | my $url = URI->new( shift @queue ); | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 241 | ▶ | next if $seen{ $url->path }++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 60 | ▶ | next if $url->scheme && ! eval { $url->host and $url->host =~ /(?:localhost|$host_reg)/ }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$url->scheme and not eval {
do {
$url->host and $url->host =~ /(?:localhost|$host_reg)/
}
}
$url->host && $url->host =~ /(?:localhost|$host_reg)/
MC/DC100%2/2
$url->scheme and not eval {
do {
$url->host and $url->host =~ /(?:localhost|$host_reg)/
}
}
$url->scheme
not eval {
do {
$url->host and $url->host =~ /(?:localhost|$host_reg)/
}
}
MC/DC50%1/2
$url->host && $url->host =~ /(?:localhost|$host_reg)/
$url->host
$url->host =~ /(?:localhost|$host_reg)/
Truth table100%3/3
A and not(B)
A= $url->schemeB= not eval {
do {
$url->host and $url->host =~ /(?:localhost|$host_reg)/
}
}
Truth table66%2/3
A && B
A= $url->hostB= $url->host =~ /(?:localhost|$host_reg)/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # get the response | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 36 | my $response = $wallflower->get($url); | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 36 | my ( $status, $headers, $file ) = @$response; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # tell the world | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 36 | ▶ | printf "$status %s %s\n", $url->path, $file && "[${\-s $file}]"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$file && "[${\(-s $file);}]"
MC/DC0%0/1
$file && "[${\(-s $file);}]"
$file
Truth table50%1/2
A
A= $file
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # obtain links to resources | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 36 | ▶ | if ( $status eq '200' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 36 | push @queue, links_from( $response => $url ); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 36 | ▶ | if ($file && $file =~ /\.(?:js|css|html|xml)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$file and $file =~ /\.(?:js|css|html|xml)$/
MC/DC0%0/2
$file and $file =~ /\.(?:js|css|html|xml)$/
$file
$file =~ /\.(?:js|css|html|xml)$/
Truth table33%1/3
A and B
A= $fileB= $file =~ /\.(?:js|css|html|xml)$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 36 | $file = path($file); | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 36 | my $content = $file->slurp_utf8; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 36 | $file->spew_utf8($content); | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 6 | my $copy_from = $work_dir; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 6 | ▶ | if ($mount_path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $mount_path =~ s!^/+!!; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $copy_from = path $work_dir, $mount_path; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | dircopy $copy_from.'', $dir; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | say "done."; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||