- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
# save all blocks to %blocks. Replace first block with <block blockname />
sub _parse_block {
my $tag = $_[1];
last unless $_[0]=~s#($tag->[0]block +([^ /]*?) *$tag->[1])((.*?)$tag->[0]/?block$tag->[1])#
my($opentag,$source,$bname,$bcode, $retval) = ($1,$3, $2, $4, '');
if( $bcode =~m|$tag->[0]block +[^ /]*? *$tag->[1]|){
_parse_block($source, $tag);
$retval = $opentag.$source;
}else{
$retval = "$tag->[0]block $bname /$tag->[1]" unless exists $blocks{$bname};
$bcode=~s%$tag->[0](:? |/)*parent(:? |/)*$tag->[1]%$blocks{$bname}%g;
$blocks{$bname} = $bcode;
}
$retval;
#seg;
}
foreach my $tag( @{$self->{tag_symbols}} ){
_parse_block($code,$tag) while(1);
}
#if <blockmode> turned on, delete all data that not in blocks until </blockmode> or end of code
foreach my $tag( @{$self->{tag_symbols}} ){
$code=~s%$tag->[0] *blocks?(?:mode?)? *$tag->[1](.*?)(?:(?:$tag->[0] *\/ *blocks?(?:mode?)? *$tag->[1])|(';#end of code))%
$_ = $1; my $end_of_code = $2;
my $retval;
$retval .= $1 while( m/($tag->[0]block +[^ ]*? *\/.*?$tag->[1])/g );
$retval.$end_of_code;
%esg;
#
}
# replace <block blockname /> with a code block
foreach my $tag( @{$self->{tag_symbols}} ){
while($code=~s|$tag->[0]block +([A-zА-я0-9_-]*?) */.*?$tag->[1]|$blocks{$1}|eg){};
};
Кусок шаблонизатора. Парсинг вложенных тегов регулярками.