| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use FindBin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | use lib | ||||||||||||||||||||||||||||
| 8 | 2 | ▶ | "$FindBin::Bin/../lib", | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Plerd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Plerd::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Plerd::Init; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Path::Class::Dir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Text::Wrap qw(wrap); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 2 | Readonly my $DEFAULT_INIT_PATH => 'plerd'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | my $webmention_enabled = 0; | |||||||||||||||||||||||||||
| 25 | 2 | my $process_webmentions = 0; | |||||||||||||||||||||||||||
| 26 | 2 | my $rebuild_webmentions = 0; | |||||||||||||||||||||||||||
| 27 | 2 | my $config_file; | |||||||||||||||||||||||||||
| 28 | my $init_path; | ||||||||||||||||||||||||||||
| 29 | 2 | GetOptions( | |||||||||||||||||||||||||||
| 30 | 'send-webmentions' => \$webmention_enabled, | ||||||||||||||||||||||||||||
| 31 | 'process-webmentions' => \$process_webmentions, | ||||||||||||||||||||||||||||
| 32 | 'rebuild-webmentions' => \$rebuild_webmentions, | ||||||||||||||||||||||||||||
| 33 | 'config=s' => \$config_file, | ||||||||||||||||||||||||||||
| 34 | 'init:s' => \$init_path, | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | if ($process_webmentions or $rebuild_webmentions) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$process_webmentions or $rebuild_webmentions
MC/DC0%0/2
$process_webmentions or $rebuild_webmentions
$process_webmentions
$rebuild_webmentions
Truth table33%1/3
A or B
A= $process_webmentionsB= $rebuild_webmentions
| |||||||||||||||||||||||||||||
| 38 | 0 | die "Plerd ended its experimental Webmention receipt support in version " | |||||||||||||||||||||||||||
| 39 | . "1.900. Please re-run this command without those " | ||||||||||||||||||||||||||||
| 40 | . "options. (Or use an older version of Plerd.)\n"; | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | if ( defined $init_path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 2 | my $is_using_default = 0; | |||||||||||||||||||||||||||
| 45 | 2 | ▶ | unless ( length $init_path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 1 | $init_path = Path::Class::Dir->new( | |||||||||||||||||||||||||||
| 47 | cwd, | ||||||||||||||||||||||||||||
| 48 | $DEFAULT_INIT_PATH, | ||||||||||||||||||||||||||||
| 49 | )->stringify; | ||||||||||||||||||||||||||||
| 50 | 1 | $is_using_default = 1; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 2 | my $messages = Plerd::Init::initialize( $init_path, $is_using_default ); | |||||||||||||||||||||||||||
| 53 | 2 | print wrap( q{}, q{}, @$messages ); | |||||||||||||||||||||||||||
| 54 | 2 | print "\n"; | |||||||||||||||||||||||||||
| 55 | 2 | exit; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my $config_ref = Plerd::Util::read_config_file( $config_file ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | foreach (qw( base_uri image ) ) { | |||||||||||||||||||||||||||
| 61 | 0 | my $value = $config_ref->{ $_ }; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | next unless defined $value && length $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and length $value
MC/DC0%0/2
defined $value and length $value
defined $value
length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | unless ( ref $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | $config_ref->{ $_ } = URI->new ( $value ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $plerd = Plerd->new( $config_ref ); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $plerd->publish_all; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ( $webmention_enabled ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | print "Sending webmentions for all posts!\n"; | |||||||||||||||||||||||||||
| 74 | 0 | for my $post ( @{ $plerd->posts } ) { | |||||||||||||||||||||||||||
| 75 | 0 | print $post->source_file . "...\n"; | |||||||||||||||||||||||||||
| 76 | 0 | my $report = $post->send_webmentions; | |||||||||||||||||||||||||||
| 77 | 0 | print "$report->{attempts} attempts, " | |||||||||||||||||||||||||||
| 78 | . "$report->{sent} sent, " | ||||||||||||||||||||||||||||
| 79 | . "$report->{delivered} delivered.\n"; | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 NAME | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | plerdall - Publish an entire Plerd blog from source | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | In /path/to/plerd/conf/plerd.conf: | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | base_uri: http://blog.example.com path: /home/me/Dropbox/plerd title: | ||||||||||||||||||||||||||||
| 92 | My Lovely Blog | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | And then, on the command line, while in the top-level plerd directory: | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | bin/plerdall | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Oh, you don't have a Plerd blog at all yet? Then you can try this first: | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | bin/plerdall --init=/home/me/Dropbox/plerd | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Run in its default mode, this program directs Plerd to completely | ||||||||||||||||||||||||||||
| 105 | publish a blog, once, based configuration. If the blog's already been | ||||||||||||||||||||||||||||
| 106 | published, then it'll get wholly and freshly republished. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | This program can perform other one-off Plerd-related tasks, as well, as | ||||||||||||||||||||||||||||
| 109 | directed by command-line options provided to it. See L<"OPTIONS">, | ||||||||||||||||||||||||||||
| 110 | below. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | For instructions on installing and using Plerd, please see the README | ||||||||||||||||||||||||||||
| 113 | file that should have accompanied this distribution. It is also | ||||||||||||||||||||||||||||
| 114 | available online at L<https://github.com/jmacdotorg/plerd#plerd>. | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head2 config | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | bin/plerdall --config=/path/to/plerd.conf | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Specify the location of a valid Plerd config file. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | If not specified here, then this program will seek a config file in these | ||||||||||||||||||||||||||||
| 125 | locations, and in this order: | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =over | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =item * | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | C<plerd.conf>, in the current working directory | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =item * | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | C<conf/plerd.conf>, in the current working directory | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =item * | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | C<.plerd>, in your home directory | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =back | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | Consult the config file generated by C<plerdall --init> to learn more | ||||||||||||||||||||||||||||
| 144 | about the config file format. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head2 init | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | bin/plerdall --init | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | bin/plerdall --init=/path/to/new/plerd/directory | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | This command sets up a new working directory for a Plerd-powered blog. | ||||||||||||||||||||||||||||
| 153 | It will contain default templates, workspaces, and config files. | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | If given a path, it will try to create the directory if one doesn't | ||||||||||||||||||||||||||||
| 156 | already exist there. If the path already exists, plerdall will check | ||||||||||||||||||||||||||||
| 157 | that it is an empty directory. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | If not given a path, plerdall will default to C<./plerd>, and then | ||||||||||||||||||||||||||||
| 160 | proceed as above. | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | This program will print either error text or a welcoming success message | ||||||||||||||||||||||||||||
| 163 | with followup suggestions to STDOUT, and then exit. It will not perform | ||||||||||||||||||||||||||||
| 164 | any blog publication beyond this initial setup. | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head2 send-webmentions | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | bin/plerdall --send-webmentions | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | After publishing all the blog's posts, Plerd will then | ||||||||||||||||||||||||||||
| 171 | direct every post to scan itself for hyperlinks and attempt to send | ||||||||||||||||||||||||||||
| 172 | webmentions to each one. | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =over | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =item * | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | L<Plerd> | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =back | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Jason McIntosh <jmac@jmac.org> | ||||||||||||||||||||||||||||