Text :: Haml을 Template Toolkit에 통합하는 cpan 모듈을 만들려고합니다. Haml은 흥미로운 템플릿 언어이지만 다소 제한적이라고 생각합니다. 루프 나 조건문을 사용하면 더 많은 고급 작업을 수행 할 수 있습니다. 그러나 나는 아주 단순한 버전의 작업을 할 수없는 듯합니다. 다음은 내 논리가 작동하는지 확인하기 위해 작동하는 일부 테스트 스크립트입니다.Haml 용 Template :: Plugin :: Filter 만들기 시도
는 여기
#!/usr/bin/perl
# test0.pl
use strict;
use warnings;
use Template;
my $tt = Template->new;
my $vars = {};
my $output = \do{my $i};
$tt->process(\*DATA, $vars, $output);
print $$output;
__DATA__
[% USE Haml %]
[% FILTER Haml %]
#profile
[% END %]
를 사용하도록 Template::Plugin::Filter 문서
use strict;
use warnings;
package Template::Plugin::Haml;
use Template::Plugin::Filter;
use parent 'Template::Plugin::Filter';
sub filter {
my ($self, $text) = @_;
# thes aren't actually the problem
# my $haml = Text::Haml->new;
# my $html = $haml->render($text);
# return $html;
return $text;
}
1;
일부 코드를 사용하여 필터 모듈에서 내 시도이다 그러나 나는 Use of uninitialized value in print at test0.pl line 15, <DATA> line 1.
내가 무엇을이 오류를 알고이 경고를 얻을 의미 ...하지만 왜 필터가 이것을 일으키는 지 잘 모르겠습니다. 어떤 도움을 주시면 감사하겠습니다.
다음은 내 논리의 다른 부분이 작동하는 몇 가지 테스트 스크립트로, 문제를 해결하기 위해 잘못된 코드를 찾지 않았습니다. 그렇지 않으면 그들은 문제에 대한 정말 필요하지 않습니다
이이 텍스트 :: HAML
#!/usr/bin/perl
# test2.pl
use 5.010;
use strict;
use warnings;
use Text::Haml;
my $text = '#profile';
my $haml = Text::Haml->new;
my $html = $haml->render($text);
say $html; # <div id='profile'></div>
UPDATE 1을 사용하는 방법을 우리에게 보여줍니다 템플릿 :: 툴킷
#!/usr/bin/perl
# test1.pl - show how to use tt
use strict;
use warnings;
use Template;
my $tt = Template->new;
my $vars = {};
my $output = \do{my $i};
$tt->process(\*DATA, $vars, $output);
print $$output; # #profile
__DATA__
#profile
을 사용하는 방법을 보여줍니다
나는 markdown 플러그인과 거의 동일하며 Textile Plugin과 거의 동일하다. TT 초기화시
[Template::Provider] creating cache of unlimited slots for [ . ]
[Template::Service] process(GLOB(0x1719608), HASH(0x16f1650))
[Template::Context] template(GLOB(0x1719608))
[Template::Context] asking providers for [GLOB(0x1719608)] []
[Template::Provider] _load(GLOB(0x1719608), <no alias>)
[Template::Provider] _compile(HASH(0x1a947a0), <no compfile>)
[Template::Parser] compiled main template document block:
sub {
my $context = shift || die "template sub called without context\n";
my $stash = $context->stash;
my $output = '';
my $_tt_error;
eval { BLOCK: {
#line 1 "input file handle"
$output .= $context->debugging('msg', { 'line' => '1', 'text' => 'USE Haml', 'file' => 'input file handle' }); ## DEBUG ##
#line 1 "input file handle"
# USE
$stash->set('Haml',
$context->plugin('Haml'));
#line 2 "input file handle"
$output .= $context->debugging('msg', { 'line' => '2', 'text' => 'FILTER haml', 'file' => 'input file handle' }); ## DEBUG ##
#line 4 "input file handle"
# FILTER
$output .= do {
my $output = '';
my $_tt_filter = $context->filter('haml')
|| $context->throw($context->error);
$output .= "#profile";
#line 4 "input file handle"
$output .= $context->debugging('msg', { 'line' => '4', 'text' => 'END', 'file' => 'input file handle' }); ## DEBUG ##
&$_tt_filter($output);
};
} };
if ([email protected]) {
$_tt_error = $context->catch([email protected], \$output);
die $_tt_error unless $_tt_error->type eq 'return';
}
return $output;
}
[Template::Service] PROCESS: Template::Document=HASH(0x1c69ba0)
[Template::Context] process([ Template::Document=HASH(0x1c69ba0) ], <no params>, <unlocalized>)
[Template::Context] template(Template::Document=HASH(0x1c69ba0))
[Template::Context] plugin(Haml, [ ])
[Template::Plugins] fetch(Haml, <no args>, Template::Context=HASH(0x1972040))
[Template::Plugins] loading Template/Plugin/Haml.pm (PLUGIN_BASE)
[Template::Plugins] calling Template::Plugin::Haml->load()
[Template::Plugins] Haml => Template::Plugin::Haml
[Template::Filters] store(haml, ARRAY(0x1c1f4d8))
[Template::Context] filter(haml, [ ]<no alias>)
[Template::Filters] fetch(haml, <no args>, Template::Context=HASH(0x1972040))
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in string eq at /usr/share/perl5/vendor_perl/Text/Haml.pm line 452, <DATA> line 1.
Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/vendor_perl/Text/Haml.pm line 674, <DATA> line 1.
Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/vendor_perl/Text/Haml.pm line 683, <DATA> line 1.
## input file handle line 1 : [% USE Haml %] ##
## input file handle line 2 : [% FILTER haml %] ##
<div id='profile'></div>
<>## input file handle line 4 : [% END %] ##</>
'Use Template :: Plugin :: Filter'는 중복되어'use parent ...'자체가 괜찮습니다. – singingfish
나는 다소 그렇게 생각 했었습니다. – xenoterracide
글쎄, 워드 프로세서가 잘못된 것처럼 보입니다. IRC 채널의 지원을 받아 보겠습니다 (irc.perl.org btw의 #tt). – singingfish