line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Markdown::Compiler::Source; |
2
|
18
|
|
|
18
|
|
130
|
use Moo; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
87
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has source => ( |
5
|
|
|
|
|
|
|
is => 'ro', |
6
|
|
|
|
|
|
|
required => 1, |
7
|
|
|
|
|
|
|
); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has default_metatype => ( |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
default => sub { 'YAML' }, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has body => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
lazy => 1, |
17
|
|
|
|
|
|
|
init_arg => undef, |
18
|
|
|
|
|
|
|
default => sub { shift->parsed->{body} }, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has metadata => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
lazy => 1, |
24
|
|
|
|
|
|
|
init_arg => undef, |
25
|
|
|
|
|
|
|
default => sub { shift->parsed->{metadata} }, |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has metatype => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
lazy => 1, |
32
|
|
|
|
|
|
|
init_arg => undef, |
33
|
|
|
|
|
|
|
default => sub { shift->parsed->{metatype} }, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has has_metadata => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
lazy => 1, |
39
|
|
|
|
|
|
|
builder => '_build_has_metadata', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has parsed => ( |
43
|
|
|
|
|
|
|
is => 'ro', |
44
|
|
|
|
|
|
|
lazy => 1, |
45
|
|
|
|
|
|
|
builder => '_build_parsed' |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _build_parsed { |
49
|
67
|
|
|
67
|
|
548
|
my ( $self ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# If we do not have any metadata, act as if we have a |
52
|
|
|
|
|
|
|
# blank file of the default type. |
53
|
67
|
100
|
|
|
|
969
|
if ( ! $self->has_metadata ) { |
54
|
|
|
|
|
|
|
return { |
55
|
65
|
|
|
|
|
1188
|
metadata => '', |
56
|
|
|
|
|
|
|
metatype => $self->default_metatype, |
57
|
|
|
|
|
|
|
body => $self->source, |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# File spec: |
62
|
|
|
|
|
|
|
# Named metadata: |
63
|
|
|
|
|
|
|
# --- [Name] |
64
|
|
|
|
|
|
|
# metadata..... |
65
|
|
|
|
|
|
|
# --- |
66
|
|
|
|
|
|
|
# body...... |
67
|
|
|
|
|
|
|
# Unamed/Default metadata: |
68
|
|
|
|
|
|
|
# --- |
69
|
|
|
|
|
|
|
# metadata..... |
70
|
|
|
|
|
|
|
# --- |
71
|
|
|
|
|
|
|
# body...... |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
25
|
my @source = split /\n/, $self->source; |
74
|
2
|
|
|
|
|
5
|
my $is_first_line = 1; |
75
|
2
|
|
|
|
|
6
|
my $is_metadata_section = 1; |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
13
|
my $parsed = { |
78
|
|
|
|
|
|
|
metadata => '', |
79
|
|
|
|
|
|
|
metatype => $self->default_metatype, |
80
|
|
|
|
|
|
|
body => '', |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
13
|
foreach my $line ( split( /\n/, $self->source )) { |
84
|
12
|
|
|
|
|
16
|
$line = "$line\n"; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# First line, see if we have an alternative metatype. |
87
|
12
|
100
|
|
|
|
23
|
if ( $is_first_line ) { |
88
|
2
|
50
|
|
|
|
7
|
if ( $line =~ /^---\s+(\S+)\s?$/) { |
89
|
0
|
|
|
|
|
0
|
$parsed->{metatype} = $1; |
90
|
|
|
|
|
|
|
} |
91
|
2
|
|
|
|
|
5
|
$is_first_line = 0; |
92
|
2
|
|
|
|
|
9
|
next; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Now each line from the second line, until we close |
96
|
|
|
|
|
|
|
# the metadata section. |
97
|
10
|
100
|
|
|
|
18
|
if ( $is_metadata_section ) { |
98
|
6
|
100
|
|
|
|
18
|
if ( $line =~ /^---\s*$/ ) { |
99
|
2
|
|
|
|
|
4
|
$is_metadata_section = 0; # No longer processing metadata. |
100
|
2
|
|
|
|
|
5
|
next; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
# Still processing metadata, add line and then move to the next |
103
|
|
|
|
|
|
|
# line. |
104
|
4
|
|
|
|
|
8
|
$parsed->{metadata} .= $line; |
105
|
4
|
|
|
|
|
7
|
next; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Now we are in the lines after the metadata section of the file. |
109
|
4
|
|
|
|
|
8
|
$parsed->{body} .= $line; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
17
|
return $parsed; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _build_has_metadata { |
116
|
67
|
|
|
67
|
|
531
|
my ( $self ) = @_; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Get the first three chars from the source. |
119
|
67
|
|
|
|
|
240
|
my $marker = substr($self->source,0,3); |
120
|
|
|
|
|
|
|
|
121
|
67
|
50
|
|
|
|
183
|
return 0 unless $marker; |
122
|
67
|
100
|
|
|
|
199
|
return 0 unless length($marker) == 3; |
123
|
52
|
100
|
|
|
|
236
|
return 0 unless $marker eq '---'; |
124
|
|
|
|
|
|
|
|
125
|
2
|
|
|
|
|
9
|
return 1; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |