line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Amuse::Compile::FileName; |
2
|
|
|
|
|
|
|
|
3
|
58
|
|
|
58
|
|
1412
|
use strict; |
|
58
|
|
|
|
|
138
|
|
|
58
|
|
|
|
|
1609
|
|
4
|
58
|
|
|
58
|
|
285
|
use warnings; |
|
58
|
|
|
|
|
131
|
|
|
58
|
|
|
|
|
1264
|
|
5
|
58
|
|
|
58
|
|
288
|
use File::Basename (); |
|
58
|
|
|
|
|
130
|
|
|
58
|
|
|
|
|
32177
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Text::Amuse::Compile::FileName - Parser for filenames passed to the compiler. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 METHODS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head2 new($filename) |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
The constructor only accept a filename. It can have the form: |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my-filename:0,2,3 |
18
|
|
|
|
|
|
|
my-filename |
19
|
|
|
|
|
|
|
/path/to/filename.muse |
20
|
|
|
|
|
|
|
../path/to/filename.muse |
21
|
|
|
|
|
|
|
../path/to/filename.muse:1,4,5 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
I.e., relative or absolute paths with extensions, or bare filenames |
24
|
|
|
|
|
|
|
without extension, with an optional range of fragments (for partial |
25
|
|
|
|
|
|
|
output). |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 path |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 name |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 suffix |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 filename |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 full_path |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 fragments |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 fragments_specification |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 name_with_ext_and_fragments |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 name_with_fragments |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 text_amuse_constructor |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
52
|
426
|
|
|
426
|
1
|
5305
|
my ($class, $filename) = @_; |
53
|
426
|
50
|
|
|
|
1483
|
die "Missing filename" unless defined $filename; |
54
|
426
|
|
|
|
|
2233
|
my $fragment_definition = qr/(?: [0-9] | [1-9][0-9]+ | pre | post )/x; |
55
|
426
|
|
|
|
|
5284
|
my $fragment = qr/\: $fragment_definition |
56
|
|
|
|
|
|
|
(?: , $fragment_definition )* |
57
|
|
|
|
|
|
|
/x; |
58
|
426
|
|
|
|
|
1500
|
my $ext = qr{\.muse}; |
59
|
426
|
|
|
|
|
893
|
my @fragments; |
60
|
426
|
100
|
|
|
|
4257
|
if ($filename =~ m/($ext)?($fragment)\z/) { |
61
|
18
|
|
|
|
|
62
|
my $fragment_path = $2; |
62
|
18
|
|
|
|
|
244
|
$filename =~ s/$fragment\z//; |
63
|
18
|
|
|
|
|
76
|
$fragment_path =~ s/\A\://; |
64
|
18
|
|
|
|
|
316
|
@fragments = split(/,/, $fragment_path); |
65
|
|
|
|
|
|
|
} |
66
|
426
|
|
|
|
|
16120
|
my ($name, $path, $suffix) = File::Basename::fileparse($filename, $ext); |
67
|
426
|
100
|
|
|
|
3315
|
my $self = { |
68
|
|
|
|
|
|
|
name => $name, |
69
|
|
|
|
|
|
|
path => $path, |
70
|
|
|
|
|
|
|
suffix => '.muse', |
71
|
|
|
|
|
|
|
fragments => (scalar(@fragments) ? \@fragments : undef), |
72
|
|
|
|
|
|
|
}; |
73
|
426
|
|
|
|
|
2391
|
bless $self, $class; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
1277
|
|
|
1277
|
1
|
4329
|
sub name { shift->{name} }; |
77
|
663
|
|
|
663
|
1
|
2829
|
sub path { shift->{path} }; |
78
|
1248
|
|
|
1248
|
1
|
10695
|
sub suffix { shift->{suffix} }; |
79
|
354
|
100
|
|
354
|
1
|
587
|
sub fragments { return @{ shift->{fragments} || [] } } |
|
354
|
|
|
|
|
2532
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub fragments_specification { |
82
|
20
|
|
|
20
|
1
|
32
|
my $self = shift; |
83
|
20
|
|
|
|
|
35
|
my $out = ''; |
84
|
20
|
100
|
|
|
|
32
|
if (my @fragments = $self->fragments) { |
85
|
8
|
|
|
|
|
23
|
$out = ':' . join(',', @fragments); |
86
|
|
|
|
|
|
|
} |
87
|
20
|
|
|
|
|
74
|
return $out; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub name_with_fragments { |
91
|
10
|
|
|
10
|
1
|
19
|
my $self = shift; |
92
|
10
|
|
|
|
|
14
|
return $self->name . $self->fragments_specification; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub name_with_ext_and_fragments { |
96
|
10
|
|
|
10
|
1
|
15
|
my $self = shift; |
97
|
10
|
|
|
|
|
17
|
return $self->name . $self->suffix . $self->fragments_specification; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub filename { |
101
|
948
|
|
|
948
|
1
|
1598
|
my $self = shift; |
102
|
948
|
|
|
|
|
2213
|
return $self->name . $self->suffix; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub full_path { |
106
|
334
|
|
|
334
|
1
|
883
|
my $self = shift; |
107
|
334
|
|
|
|
|
1146
|
return $self->path . $self->filename; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub text_amuse_constructor { |
111
|
334
|
|
|
334
|
1
|
753
|
my $self = shift; |
112
|
334
|
|
|
|
|
1003
|
my %constructor = (file => $self->filename); |
113
|
334
|
100
|
|
|
|
1182
|
if (my @fragments = $self->fragments) { |
114
|
18
|
|
|
|
|
68
|
$constructor{partial} = \@fragments; |
115
|
|
|
|
|
|
|
} |
116
|
334
|
|
|
|
|
1665
|
return %constructor; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |