line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Yats.pm |
3
|
|
|
|
|
|
|
# Last Modification: 2002/01/07 (hdias@esb.ucp.pt) |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright (c) 2001 Henrique Dias. All rights reserved. |
6
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or modify |
7
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Text::Yats; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require 5; |
14
|
5
|
|
|
5
|
|
2969
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
340
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
require Exporter; |
17
|
5
|
|
|
5
|
|
29
|
use vars qw($VERSION @ISA @EXPORT); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
6245
|
|
18
|
|
|
|
|
|
|
@ISA = qw(Exporter DynaLoader); |
19
|
|
|
|
|
|
|
$VERSION = '0.03'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
16
|
|
|
16
|
1
|
150
|
my $proto = shift; |
23
|
16
|
|
66
|
|
|
55
|
my $class = ref($proto) || $proto; |
24
|
16
|
|
|
|
|
175
|
my $self = { |
25
|
|
|
|
|
|
|
section => [], |
26
|
|
|
|
|
|
|
level => 0, |
27
|
|
|
|
|
|
|
file => "", |
28
|
|
|
|
|
|
|
text => "", |
29
|
|
|
|
|
|
|
base => '\\d+', |
30
|
|
|
|
|
|
|
pattern => '\\d+', |
31
|
|
|
|
|
|
|
@_, |
32
|
|
|
|
|
|
|
}; |
33
|
16
|
|
|
|
|
37
|
bless ($self, $class); |
34
|
|
|
|
|
|
|
|
35
|
16
|
100
|
|
|
|
90
|
$self->{text} = &get_text($self->{'file'}) if($self->{file}); |
36
|
16
|
100
|
|
|
|
50
|
my $sections = ($self->{level} > 0) ? $self->wrapper() : []; |
37
|
16
|
100
|
|
|
|
22
|
if($#{$sections} > 0) { |
|
16
|
|
|
|
|
45
|
|
38
|
4
|
|
|
|
|
8
|
$self->{level}--; |
39
|
4
|
|
|
|
|
13
|
$self->{pattern} .= '\\.' . $self->{base}; |
40
|
4
|
|
|
|
|
7
|
for(0 .. $#{$sections}) { |
|
4
|
|
|
|
|
16
|
|
41
|
12
|
|
|
|
|
51
|
$self->{section}->[$_] = $self->new( |
42
|
|
|
|
|
|
|
'level' => $self->{level}, |
43
|
|
|
|
|
|
|
'pattern' => $self->{pattern}, |
44
|
|
|
|
|
|
|
'text' => $sections->[$_]); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
16
|
|
|
|
|
53
|
return($self); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
14
|
|
|
14
|
1
|
102
|
sub section { $_[0]->{'section'}; } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub replace { |
53
|
9
|
|
|
9
|
1
|
22
|
my $self = shift; |
54
|
9
|
|
|
|
|
32
|
my $param = {@_}; |
55
|
|
|
|
|
|
|
|
56
|
9
|
|
|
|
|
16
|
my $text = ""; |
57
|
9
|
|
|
|
|
12
|
my $max = 0; |
58
|
9
|
|
|
|
|
10
|
my $i = 0; |
59
|
9
|
|
|
|
|
13
|
my $pattern = '\$(\w+) *).)+)\)-->'; |
60
|
9
|
|
|
|
|
12
|
LOOP: while(1) { |
61
|
20
|
|
|
|
|
35
|
my $tmp = $self->{text}; |
62
|
20
|
|
|
|
|
158
|
while($tmp =~ s/$pattern/\$$1/o) { |
63
|
1
|
|
|
|
|
3
|
$self->{text} = $tmp; |
64
|
1
|
|
|
|
|
79
|
$param->{$1} = [eval($2)]; |
65
|
|
|
|
|
|
|
} |
66
|
20
|
|
|
|
|
26
|
for(keys(%{$param})) { |
|
20
|
|
|
|
|
60
|
|
67
|
54
|
100
|
|
|
|
150
|
$param->{$_} = &make_array($param->{$param->{$_}->{array}},$param->{$_}->{match},$param->{$_}->{value}) |
68
|
|
|
|
|
|
|
if(ref($param->{$_}) eq "HASH"); |
69
|
54
|
100
|
|
|
|
103
|
if(ref($param->{$_}) eq "ARRAY") { |
70
|
42
|
|
|
|
|
39
|
my $maxtmp = $#{$param->{$_}}; |
|
42
|
|
|
|
|
108
|
|
71
|
42
|
100
|
|
|
|
85
|
$max = $maxtmp unless($maxtmp <= $max); |
72
|
42
|
100
|
66
|
|
|
187
|
if(($i <= $maxtmp) && ($param->{$_}->[$i] ne "")) { $tmp =~ s/\$$_\b/$param->{$_}->[$i]/g; } |
|
32
|
|
|
|
|
438
|
|
73
|
10
|
|
|
|
|
131
|
else { $tmp =~ s/ ?\$$_\b//g; } |
74
|
12
|
|
|
|
|
192
|
} else { $tmp =~ s/\$$_\b/$param->{$_}/g; } |
75
|
|
|
|
|
|
|
} |
76
|
20
|
|
|
|
|
46
|
$text .= $tmp; |
77
|
20
|
100
|
|
|
|
53
|
last LOOP if($i == $max); |
78
|
11
|
|
|
|
|
16
|
$i++; |
79
|
|
|
|
|
|
|
} |
80
|
9
|
|
|
|
|
44
|
return($text); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub make_array { |
84
|
5
|
|
|
5
|
0
|
11
|
my ($array, $match, $value) = @_; |
85
|
|
|
|
|
|
|
|
86
|
5
|
|
|
|
|
10
|
my @matched = (); |
87
|
5
|
|
|
|
|
7
|
$#matched = $#{$array}; |
|
5
|
|
|
|
|
23
|
|
88
|
5
|
|
|
|
|
10
|
my %keys = (); |
89
|
5
|
100
|
|
|
|
16
|
if(ref($match) eq "ARRAY") { @keys{@{$match}} = (); } |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
90
|
4
|
|
|
|
|
12
|
else { $keys{$match} = ""; } |
91
|
5
|
|
|
|
|
8
|
for my $j (0 .. $#{$array}) { |
|
5
|
|
|
|
|
17
|
|
92
|
16
|
100
|
|
|
|
48
|
$matched[$j] = (exists($keys{$array->[$j]})) ? $value : ""; |
93
|
|
|
|
|
|
|
} |
94
|
5
|
|
|
|
|
32
|
return(\@matched); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub text { |
98
|
3
|
|
|
3
|
1
|
7
|
my $self = shift; |
99
|
3
|
|
|
|
|
9
|
return($self->{text}); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub wrapper { |
103
|
6
|
|
|
6
|
0
|
13
|
my $self = shift; |
104
|
6
|
|
|
|
|
16
|
my $pattern = '\n*'; |
105
|
6
|
|
|
|
|
92
|
my $re = qr/$pattern/; |
106
|
6
|
|
|
|
|
64
|
my @sections = split(/$re/, $self->{text}); |
107
|
6
|
|
|
|
|
25
|
return(\@sections); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub get_text { |
111
|
4
|
|
|
4
|
0
|
12
|
my $filename = shift; |
112
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
18
|
local $/ = undef; |
114
|
4
|
|
|
|
|
12
|
local *FILE; |
115
|
4
|
50
|
|
|
|
215
|
open (FILE, "<$filename") || die "Can't open $filename: $!\n"; |
116
|
4
|
|
|
|
|
125
|
my $text = ; |
117
|
4
|
|
|
|
|
41
|
close(FILE); |
118
|
4
|
|
|
|
|
25
|
return($text); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
__END__ |