our
$VERSION
=
'1.0.21'
;
sub
import
{ Template::Liquid::register_tag(
'case'
) }
sub
new {
my
(
$class
,
$args
) =
@_
;
raise Template::Liquid::Error {
type
=>
'Context'
,
template
=>
$args
->{template},
message
=>
'Missing template argument'
,
fatal
=> 1
}
if
!
defined
$args
->{
'template'
};
raise Template::Liquid::Error {
type
=>
'Context'
,
template
=>
$args
->{template},
message
=>
'Missing parent argument'
,
fatal
=> 1
}
if
!
defined
$args
->{
'parent'
};
raise Template::Liquid::Error {
type
=>
'Syntax'
,
template
=>
$args
->{template},
message
=>
'Missing argument list in '
.
$args
->{
'markup'
},
fatal
=> 1
}
if
!
defined
$args
->{
'attrs'
};
if
(
$args
->{
'attrs'
} !~ m[\S$]o) {
raise Template::Liquid::Error {
type
=>
'Syntax'
,
template
=>
$args
->{template},
message
=>
'Bad argument list in '
.
$args
->{
'markup'
},
fatal
=> 1
};
}
my
$s
=
bless
{
name
=>
$args
->{
'tag_name'
} .
'-'
.
$args
->{
'attrs'
},
blocks
=> [],
tag_name
=>
$args
->{
'tag_name'
},
template
=>
$args
->{
'template'
},
parent
=>
$args
->{
'parent'
},
markup
=>
$args
->{
'markup'
},
value
=>
$args
->{
'attrs'
},
first_block
=> 0,
end_tag
=>
'end'
.
$args
->{
'tag_name'
},
conditional_tag
=>
qr[^(?:else|when)$]
o
},
$class
;
return
$s
;
}
sub
push_block {
my
(
$s
,
$args
) =
@_
;
raise Template::Liquid::Error {
type
=>
'Context'
,
template
=>
$s
->{template},
message
=>
'Missing template argument'
,
fatal
=> 1
}
if
!
defined
$args
->{
'template'
};
raise Template::Liquid::Error {
type
=>
'Context'
,
template
=>
$s
->{template},
message
=>
'Missing parent argument'
,
fatal
=> 1
}
if
!
defined
$args
->{
'parent'
};
raise Template::Liquid::Error {
type
=>
'Syntax'
,
template
=>
$s
->{template},
message
=>
'Missing argument list in '
.
$args
->{
'markup'
},
fatal
=> 1
}
if
!
defined
$args
->{
'attrs'
} &&
$args
->{
'tag_name'
} eq
'when'
;
if
(
$args
->{
'tag_name'
} eq
'when'
) {
$args
->{
'attrs'
} =
join
' or '
,
map
{
sprintf
'%s == %s'
,
$args
->{
'parent'
}{
'value'
},
$_
}
grep
{
defined
$_
}
$args
->{
'attrs'
} =~ m[(${Template::Liquid::Utility::Expression})
(?:\s+or\s+|\s*\,\s*)?]oxmg;
}
my
$block
= Template::Liquid::Block->new(
{
tag_name
=>
$args
->{
'tag_name'
},
end_tag
=>
'end'
.
$args
->{
'tag_name'
},
attrs
=>
$args
->{
'attrs'
},
template
=>
$args
->{
'template'
},
parent
=>
$s
}
);
${
$s
->{
'blocks'
}[-1]}{
'nodelist'
} =
$s
->{
'nodelist'
}
if
scalar
@{
$s
->{
'blocks'
}};
$s
->{
'nodelist'
} = [];
push
@{
$s
->{
'blocks'
}},
$block
;
shift
@{
$s
->{
'blocks'
}}
if
$s
->{
'first_block'
}++ == 0;
return
$block
;
}
1;