| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Statocles::App::Basic; |
|
2
|
|
|
|
|
|
|
our $VERSION = '0.086'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: Build Markdown and collateral files |
|
4
|
|
|
|
|
|
|
|
|
5
|
20
|
|
|
20
|
|
26356
|
use Statocles::Base 'Class'; |
|
|
20
|
|
|
|
|
45
|
|
|
|
20
|
|
|
|
|
182
|
|
|
6
|
20
|
|
|
20
|
|
140919
|
use Statocles::Util qw( run_editor ); |
|
|
20
|
|
|
|
|
51
|
|
|
|
20
|
|
|
|
|
11408
|
|
|
7
|
|
|
|
|
|
|
with 'Statocles::App::Role::Store'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#pod =attr store |
|
10
|
|
|
|
|
|
|
#pod |
|
11
|
|
|
|
|
|
|
#pod The L<store path|Statocles::Store> containing this app's documents and files. |
|
12
|
|
|
|
|
|
|
#pod Required. |
|
13
|
|
|
|
|
|
|
#pod |
|
14
|
|
|
|
|
|
|
#pod =cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#pod =method command |
|
17
|
|
|
|
|
|
|
#pod |
|
18
|
|
|
|
|
|
|
#pod my $exitval = $app->command( $app_name, @args ); |
|
19
|
|
|
|
|
|
|
#pod |
|
20
|
|
|
|
|
|
|
#pod Run a command on this app. Commands allow creating, editing, listing, and |
|
21
|
|
|
|
|
|
|
#pod viewing pages. |
|
22
|
|
|
|
|
|
|
#pod |
|
23
|
|
|
|
|
|
|
#pod =cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $USAGE_INFO = <<'ENDHELP'; |
|
26
|
|
|
|
|
|
|
Usage: |
|
27
|
|
|
|
|
|
|
$name help -- This help file |
|
28
|
|
|
|
|
|
|
$name edit <path> -- Edit a page, creating it if necessary |
|
29
|
|
|
|
|
|
|
ENDHELP |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub command { |
|
32
|
6
|
|
|
6
|
1
|
67550
|
my ( $self, $name, @argv ) = @_; |
|
33
|
|
|
|
|
|
|
|
|
34
|
6
|
100
|
|
|
|
29
|
if ( !$argv[0] ) { |
|
35
|
1
|
|
|
|
|
49
|
say STDERR "ERROR: Missing command"; |
|
36
|
1
|
|
|
|
|
104
|
say STDERR eval "qq{$USAGE_INFO}"; |
|
37
|
1
|
|
|
|
|
7
|
return 1; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
5
|
100
|
|
|
|
21
|
if ( $argv[0] eq 'help' ) { |
|
41
|
2
|
|
|
|
|
172
|
say eval "qq{$USAGE_INFO}"; |
|
42
|
2
|
|
|
|
|
17
|
return 0; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
3
|
100
|
|
|
|
11
|
if ( $argv[0] eq 'edit' ) { |
|
46
|
2
|
|
|
|
|
19
|
$argv[1] =~ s{^/}{}; |
|
47
|
2
|
100
|
|
|
|
28
|
my $path = Path::Tiny->new( |
|
48
|
|
|
|
|
|
|
$argv[1] =~ /[.](?:markdown|md)$/ ? $argv[1] : "$argv[1]/index.markdown", |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
83
|
my %doc; |
|
52
|
|
|
|
|
|
|
# Read post content on STDIN |
|
53
|
2
|
50
|
|
|
|
12
|
if ( !-t *STDIN ) { |
|
54
|
2
|
|
|
|
|
6
|
my $content = do { local $/; <STDIN> }; |
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
44
|
|
|
55
|
2
|
|
|
|
|
31
|
%doc = ( |
|
56
|
|
|
|
|
|
|
%doc, |
|
57
|
|
|
|
|
|
|
$self->store->parse_frontmatter( "<STDIN>", $content ), |
|
58
|
|
|
|
|
|
|
); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Re-open STDIN as the TTY so that the editor (vim) can use it |
|
61
|
|
|
|
|
|
|
# XXX Is this also a problem on Windows? |
|
62
|
2
|
50
|
|
|
|
21
|
if ( -e '/dev/tty' ) { |
|
63
|
2
|
|
|
|
|
8
|
close STDIN; |
|
64
|
2
|
|
|
|
|
28
|
open STDIN, '/dev/tty'; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
2
|
50
|
33
|
|
|
18
|
if ( !$self->store->has_file( $path ) || keys %doc ) { |
|
69
|
2
|
|
50
|
|
|
171
|
$doc{title} ||= ''; |
|
70
|
2
|
|
50
|
|
|
14
|
$doc{content} ||= "Markdown content goes here.\n"; |
|
71
|
2
|
|
|
|
|
17
|
$self->store->write_document( $path => \%doc ); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
2
|
|
|
|
|
23
|
my $full_path = $self->store->path->child( $path ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
2
|
100
|
|
|
|
112
|
if ( !run_editor( $full_path ) ) { |
|
76
|
1
|
|
|
|
|
6
|
say "New page at: $full_path"; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
else { |
|
81
|
1
|
|
|
|
|
46
|
say STDERR qq{ERROR: Unknown command "$argv[0]"}; |
|
82
|
1
|
|
|
|
|
113
|
say STDERR eval "qq{$USAGE_INFO}"; |
|
83
|
1
|
|
|
|
|
9
|
return 1; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
2
|
|
|
|
|
73
|
return 0; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=encoding UTF-8 |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Statocles::App::Basic - Build Markdown and collateral files |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 VERSION |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
version 0.086 |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $app = Statocles::App::Basic->new( |
|
108
|
|
|
|
|
|
|
url_root => '/', |
|
109
|
|
|
|
|
|
|
store => 'share/root', |
|
110
|
|
|
|
|
|
|
); |
|
111
|
|
|
|
|
|
|
my @pages = $app->pages; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This application builds basic pages based on L<Markdown documents|Statocles::Document> and |
|
116
|
|
|
|
|
|
|
other files. Use this to have basic informational pages like "About Us" and "Contact Us". |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 store |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The L<store path|Statocles::Store> containing this app's documents and files. |
|
123
|
|
|
|
|
|
|
Required. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 METHODS |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 command |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $exitval = $app->command( $app_name, @args ); |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Run a command on this app. Commands allow creating, editing, listing, and |
|
132
|
|
|
|
|
|
|
viewing pages. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Doug Bell <preaction@cpan.org> |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Doug Bell. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
143
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |