| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Markdown::Compiler::Source; |
|
2
|
18
|
|
|
18
|
|
113
|
use Moo; |
|
|
18
|
|
|
|
|
36
|
|
|
|
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
|
|
526
|
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
|
|
|
|
887
|
if ( ! $self->has_metadata ) { |
|
54
|
|
|
|
|
|
|
return { |
|
55
|
65
|
|
|
|
|
1087
|
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
|
|
|
|
|
14
|
my @source = split /\n/, $self->source; |
|
74
|
2
|
|
|
|
|
5
|
my $is_first_line = 1; |
|
75
|
2
|
|
|
|
|
5
|
my $is_metadata_section = 1; |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
9
|
my $parsed = { |
|
78
|
|
|
|
|
|
|
metadata => '', |
|
79
|
|
|
|
|
|
|
metatype => $self->default_metatype, |
|
80
|
|
|
|
|
|
|
body => '', |
|
81
|
|
|
|
|
|
|
}; |
|
82
|
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
12
|
foreach my $line ( split( /\n/, $self->source )) { |
|
84
|
12
|
|
|
|
|
19
|
$line = "$line\n"; |
|
85
|
|
|
|
|
|
|
|
|
86
|
12
|
|
|
|
|
165
|
print "Looking at line: $line"; |
|
87
|
|
|
|
|
|
|
# First line, see if we have an alternative metatype. |
|
88
|
12
|
100
|
|
|
|
43
|
if ( $is_first_line ) { |
|
89
|
2
|
50
|
|
|
|
7
|
if ( $line =~ /^---\s+(\S+)\s?$/) { |
|
90
|
0
|
|
|
|
|
0
|
$parsed->{metatype} = $1; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
2
|
|
|
|
|
4
|
$is_first_line = 0; |
|
93
|
2
|
|
|
|
|
5
|
next; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Now each line from the second line, until we close |
|
97
|
|
|
|
|
|
|
# the metadata section. |
|
98
|
10
|
100
|
|
|
|
17
|
if ( $is_metadata_section ) { |
|
99
|
6
|
100
|
|
|
|
23
|
if ( $line =~ /^---\s*$/ ) { |
|
100
|
2
|
|
|
|
|
4
|
$is_metadata_section = 0; # No longer processing metadata. |
|
101
|
2
|
|
|
|
|
4
|
next; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
# Still processing metadata, add line and then move to the next |
|
104
|
|
|
|
|
|
|
# line. |
|
105
|
4
|
|
|
|
|
32
|
$parsed->{metadata} .= $line; |
|
106
|
4
|
|
|
|
|
7
|
next; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Now we are in the lines after the metadata section of the file. |
|
110
|
4
|
|
|
|
|
10
|
$parsed->{body} .= $line; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
2
|
|
|
|
|
21
|
return $parsed; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _build_has_metadata { |
|
117
|
67
|
|
|
67
|
|
495
|
my ( $self ) = @_; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Get the first three chars from the source. |
|
120
|
67
|
|
|
|
|
231
|
my $marker = substr($self->source,0,3); |
|
121
|
|
|
|
|
|
|
|
|
122
|
67
|
50
|
|
|
|
164
|
return 0 unless $marker; |
|
123
|
67
|
100
|
|
|
|
176
|
return 0 unless length($marker) == 3; |
|
124
|
52
|
100
|
|
|
|
213
|
return 0 unless $marker eq '---'; |
|
125
|
|
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
9
|
return 1; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |