/
usr
/
local
/
share
/
man
/
man3
/
/usr/local/share/man/man3
mkdir
upload
Name
Size
Mode
Actions
App::Prove.3pm
10508
0444
edit
dl
rm
App::Prove::State.3pm
6005
0444
edit
dl
rm
App::Prove::State::Result.3pm
5619
0444
edit
dl
rm
App::Prove::State::Result::Test.3pm
5051
0444
edit
dl
rm
AppConfig.3pm
35289
0444
edit
dl
rm
AppConfig::Args.3pm
7992
0444
edit
dl
rm
AppConfig::CGI.3pm
6609
0444
edit
dl
rm
AppConfig::File.3pm
12614
0444
edit
dl
rm
AppConfig::Getopt.3pm
7444
0444
edit
dl
rm
AppConfig::State.3pm
24972
0444
edit
dl
rm
AppConfig::Sys.3pm
6695
0444
edit
dl
rm
Archive::Tar.3pm
44061
0444
edit
dl
rm
Archive::Tar::File.3pm
11083
0444
edit
dl
rm
Archive::Zip.3pm
69985
0444
edit
dl
rm
Archive::Zip::FAQ.3pm
18437
0444
edit
dl
rm
Archive::Zip::MemberRead.3pm
6734
0444
edit
dl
rm
Archive::Zip::Tree.3pm
2875
0444
edit
dl
rm
B::COW.3pm
5163
0444
edit
dl
rm
Canary::Stability.3pm
3727
0444
edit
dl
rm
CDB_File.3pm
14318
0444
edit
dl
rm
common::sense.3pm
0
0444
edit
dl
rm
Compress::Raw::Bzip2.3pm
13463
0444
edit
dl
rm
Compress::Raw::Zlib.3pm
42082
0444
edit
dl
rm
Compress::Zlib.3pm
38719
0444
edit
dl
rm
CPAN::Meta.3pm
15923
0444
edit
dl
rm
CPAN::Meta::Converter.3pm
6594
0444
edit
dl
rm
CPAN::Meta::Feature.3pm
4322
0444
edit
dl
rm
CPAN::Meta::History.3pm
7855
0444
edit
dl
rm
CPAN::Meta::History::Meta_1_0.3pm
9973
0444
edit
dl
rm
CPAN::Meta::History::Meta_1_1.3pm
12410
0444
edit
dl
rm
CPAN::Meta::History::Meta_1_2.3pm
22224
0444
edit
dl
rm
CPAN::Meta::History::Meta_1_3.3pm
23974
0444
edit
dl
rm
CPAN::Meta::History::Meta_1_4.3pm
24565
0444
edit
dl
rm
CPAN::Meta::Merge.3pm
5285
0444
edit
dl
rm
CPAN::Meta::Prereqs.3pm
7380
0444
edit
dl
rm
CPAN::Meta::Requirements.3pm
12308
0444
edit
dl
rm
CPAN::Meta::Spec.3pm
45592
0444
edit
dl
rm
CPAN::Meta::Validator.3pm
4215
0444
edit
dl
rm
CPAN::Meta::YAML.3pm
4230
0444
edit
dl
rm
Crypt::OpenSSL::Random.3pm
5634
0444
edit
dl
rm
Curses.3pm
37580
0444
edit
dl
rm
Curses::UI.3pm
15619
0444
edit
dl
rm
Curses::UI::Buttonbox.3pm
8908
0444
edit
dl
rm
Curses::UI::Calendar.3pm
8203
0444
edit
dl
rm
Curses::UI::Checkbox.3pm
6509
0444
edit
dl
rm
Curses::UI::Color.3pm
5903
0444
edit
dl
rm
Curses::UI::Common.3pm
6498
0444
edit
dl
rm
Curses::UI::Container.3pm
9041
0444
edit
dl
rm
Curses::UI::Dialog::Basic.3pm
5213
0444
edit
dl
rm
Curses::UI::Dialog::Calendar.3pm
4761
0444
edit
dl
rm
Curses::UI::Dialog::Dirbrowser.3pm
5369
0444
edit
dl
rm
Curses::UI::Dialog::Error.3pm
4307
0444
edit
dl
rm
Curses::UI::Dialog::Filebrowser.3pm
6889
0444
edit
dl
rm
Curses::UI::Dialog::Progress.3pm
5774
0444
edit
dl
rm
Curses::UI::Dialog::Question.3pm
5277
0444
edit
dl
rm
Curses::UI::Dialog::Status.3pm
4765
0444
edit
dl
rm
Curses::UI::Label.3pm
7333
0444
edit
dl
rm
Curses::UI::Listbox.3pm
11988
0444
edit
dl
rm
Curses::UI::Menubar.3pm
8110
0444
edit
dl
rm
Curses::UI::Notebook.3pm
9140
0444
edit
dl
rm
Curses::UI::PasswordEntry.3pm
3743
0444
edit
dl
rm
Curses::UI::Popupmenu.3pm
7431
0444
edit
dl
rm
Curses::UI::Progressbar.3pm
5891
0444
edit
dl
rm
Curses::UI::Radiobuttonbox.3pm
4069
0444
edit
dl
rm
Curses::UI::Searchable.3pm
6668
0444
edit
dl
rm
Curses::UI::TextEditor.3pm
14171
0444
edit
dl
rm
Curses::UI::TextEntry.3pm
3623
0444
edit
dl
rm
Curses::UI::TextViewer.3pm
3670
0444
edit
dl
rm
Curses::UI::Tutorial.3pm
8555
0444
edit
dl
rm
Curses::UI::Widget.3pm
25675
0444
edit
dl
rm
Curses::UI::Window.3pm
5084
0444
edit
dl
rm
Cwd.3pm
7183
0444
edit
dl
rm
Date::Format.3pm
7291
0444
edit
dl
rm
Date::Language.3pm
3809
0444
edit
dl
rm
Date::Language::Bulgarian.3pm
3675
0444
edit
dl
rm
Date::Language::Hungarian.3pm
3091
0444
edit
dl
rm
Date::Parse.3pm
5402
0444
edit
dl
rm
Digest::SHA.3pm
25759
0444
edit
dl
rm
Expect.3pm
60229
0444
edit
dl
rm
ExtUtils::CBuilder.3pm
11923
0444
edit
dl
rm
ExtUtils::CBuilder::Platform::Windows.3pm
3117
0444
edit
dl
rm
ExtUtils::Command.3pm
5942
0444
edit
dl
rm
ExtUtils::Command::MM.3pm
5723
0444
edit
dl
rm
ExtUtils::Liblist.3pm
12679
0444
edit
dl
rm
ExtUtils::MakeMaker.3pm
79357
0444
edit
dl
rm
ExtUtils::MakeMaker::Config.3pm
2587
0444
edit
dl
rm
ExtUtils::MakeMaker::FAQ.3pm
26829
0444
edit
dl
rm
ExtUtils::MakeMaker::Locale.3pm
11168
0444
edit
dl
rm
ExtUtils::MakeMaker::Tutorial.3pm
8389
0444
edit
dl
rm
ExtUtils::Manifest.3pm
11961
0444
edit
dl
rm
ExtUtils::Mkbootstrap.3pm
3459
0444
edit
dl
rm
ExtUtils::Mksymlists.3pm
6699
0444
edit
dl
rm
ExtUtils::MM.3pm
2829
0444
edit
dl
rm
ExtUtils::MM_AIX.3pm
3044
0444
edit
dl
rm
ExtUtils::MM_Any.3pm
31129
0444
edit
dl
rm
ExtUtils::MM_BeOS.3pm
2798
0444
edit
dl
rm
ExtUtils::MM_Cygwin.3pm
3569
0444
edit
dl
rm
ExtUtils::MM_Darwin.3pm
2688
0444
edit
dl
rm
ExtUtils::MM_DOS.3pm
3021
0444
edit
dl
rm
ExtUtils::MM_MacOS.3pm
2987
0444
edit
dl
rm
ExtUtils::MM_NW5.3pm
3200
0444
edit
dl
rm
ExtUtils::MM_OS2.3pm
2886
0444
edit
dl
rm
ExtUtils::MM_QNX.3pm
2942
0444
edit
dl
rm
ExtUtils::MM_Unix.3pm
21419
0444
edit
dl
rm
ExtUtils::MM_UWIN.3pm
3051
0444
edit
dl
rm
ExtUtils::MM_VMS.3pm
14900
0444
edit
dl
rm
ExtUtils::MM_VOS.3pm
2926
0444
edit
dl
rm
ExtUtils::MM_Win32.3pm
5919
0444
edit
dl
rm
ExtUtils::MM_Win95.3pm
3276
0444
edit
dl
rm
ExtUtils::MY.3pm
2764
0444
edit
dl
rm
ExtUtils::testlib.3pm
2690
0444
edit
dl
rm
File::GlobMapper.3pm
11447
0444
edit
dl
rm
File::HomeDir.3pm
18212
0444
edit
dl
rm
File::HomeDir::Darwin.3pm
3232
0444
edit
dl
rm
File::HomeDir::Darwin::Carbon.3pm
3517
0444
edit
dl
rm
File::HomeDir::Darwin::Cocoa.3pm
3446
0444
edit
dl
rm
File::HomeDir::Driver.3pm
3101
0444
edit
dl
rm
File::HomeDir::FreeDesktop.3pm
3487
0444
edit
dl
rm
File::HomeDir::MacOS9.3pm
3499
0444
edit
dl
rm
File::HomeDir::Test.3pm
3534
0444
edit
dl
rm
File::HomeDir::Unix.3pm
3638
0444
edit
dl
rm
File::HomeDir::Windows.3pm
4891
0444
edit
dl
rm
File::Path.3pm
31030
0444
edit
dl
rm
File::Slurp.3pm
23626
0444
edit
dl
rm
File::Spec.3pm
13784
0444
edit
dl
rm
File::Spec::AmigaOS.3pm
2826
0444
edit
dl
rm
File::Spec::Cygwin.3pm
3957
0444
edit
dl
rm
File::Spec::Epoc.3pm
3251
0444
edit
dl
rm
File::Spec::Functions.3pm
3799
0444
edit
dl
rm
File::Spec::Mac.3pm
18664
0444
edit
dl
rm
File::Spec::OS2.3pm
3118
0444
edit
dl
rm
File::Spec::Unix.3pm
9837
0444
edit
dl
rm
File::Spec::VMS.3pm
6389
0444
edit
dl
rm
File::Spec::Win32.3pm
6451
0444
edit
dl
rm
File::Temp.3pm
36799
0444
edit
dl
rm
File::Which.3pm
9746
0444
edit
dl
rm
Getopt::Long.3pm
52647
0444
edit
dl
rm
HDB.3pm
10947
0444
edit
dl
rm
HDB::CMDS.3pm
18894
0444
edit
dl
rm
HDB::Encode.3pm
7863
0444
edit
dl
rm
HDB::Object.3pm
10057
0444
edit
dl
rm
HTML::AsSubs.3pm
8586
0444
edit
dl
rm
HTML::Element.3pm
70793
0444
edit
dl
rm
HTML::Element::traverse.3pm
15984
0444
edit
dl
rm
HTML::Form.3pm
28158
0444
edit
dl
rm
HTML::Parse.3pm
8277
0444
edit
dl
rm
HTML::Tree.3pm
9982
0444
edit
dl
rm
HTML::Tree::AboutObjects.3pm
37918
0444
edit
dl
rm
HTML::Tree::AboutTrees.3pm
58534
0444
edit
dl
rm
HTML::Tree::Scanning.3pm
34385
0444
edit
dl
rm
HTML::TreeBuilder.3pm
30138
0444
edit
dl
rm
HTTP::Tiny.3pm
27709
0444
edit
dl
rm
IO::AtomicFile.3pm
5381
0444
edit
dl
rm
IO::Compress::Base.3pm
3506
0444
edit
dl
rm
IO::Compress::Bzip2.3pm
23260
0444
edit
dl
rm
IO::Compress::Deflate.3pm
26768
0444
edit
dl
rm
IO::Compress::FAQ.3pm
26718
0444
edit
dl
rm
IO::Compress::Gzip.3pm
34489
0444
edit
dl
rm
IO::Compress::RawDeflate.3pm
27134
0444
edit
dl
rm
IO::Compress::Zip.3pm
40870
0444
edit
dl
rm
IO::InnerFile.3pm
6035
0444
edit
dl
rm
IO::Lines.3pm
3783
0444
edit
dl
rm
IO::Pty.3pm
8579
0444
edit
dl
rm
IO::Scalar.3pm
10679
0444
edit
dl
rm
IO::ScalarArray.3pm
10528
0444
edit
dl
rm
IO::Stringy.3pm
4049
0444
edit
dl
rm
IO::Tty.3pm
8348
0444
edit
dl
rm
IO::Tty::Constant.3pm
10012
0444
edit
dl
rm
IO::Uncompress::AnyInflate.3pm
32800
0444
edit
dl
rm
IO::Uncompress::AnyUncompress.3pm
30767
0444
edit
dl
rm
IO::Uncompress::Base.3pm
3518
0444
edit
dl
rm
IO::Uncompress::Bunzip2.3pm
29171
0444
edit
dl
rm
IO::Uncompress::Gunzip.3pm
31719
0444
edit
dl
rm
IO::Uncompress::Inflate.3pm
29915
0444
edit
dl
rm
IO::Uncompress::RawInflate.3pm
29563
0444
edit
dl
rm
IO::Uncompress::Unzip.3pm
31279
0444
edit
dl
rm
IO::Wrap.3pm
10664
0444
edit
dl
rm
IO::WrapTie.3pm
14987
0444
edit
dl
rm
JSON::PP.3pm
50080
0444
edit
dl
rm
JSON::PP::Boolean.3pm
2667
0444
edit
dl
rm
JSON::Syck.3pm
8094
0444
edit
dl
rm
JSON::XS.3pm
89037
0444
edit
dl
rm
JSON::XS::Boolean.3pm
2857
0444
edit
dl
rm
lib::core::only.3pm
5647
0444
edit
dl
rm
local::lib.3pm
31390
0444
edit
dl
rm
LWP.3pm
28506
0444
edit
dl
rm
LWP::Authen::Ntlm.3pm
7489
0444
edit
dl
rm
LWP::ConnCache.3pm
9967
0444
edit
dl
rm
LWP::Debug.3pm
5608
0444
edit
dl
rm
LWP::MemberMixin.3pm
4821
0444
edit
dl
rm
LWP::Protocol.3pm
8350
0444
edit
dl
rm
LWP::Protocol::https.3pm
5684
0444
edit
dl
rm
LWP::RobotUA.3pm
9022
0444
edit
dl
rm
LWP::Simple.3pm
9016
0444
edit
dl
rm
LWP::UserAgent.3pm
48156
0444
edit
dl
rm
lwpcook.3pm
14838
0444
edit
dl
rm
lwptut.3pm
32441
0444
edit
dl
rm
Module::Build.3pm
44563
0444
edit
dl
rm
Module::Build::API.3pm
89267
0444
edit
dl
rm
Module::Build::Authoring.3pm
17363
0444
edit
dl
rm
Module::Build::Base.3pm
5157
0444
edit
dl
rm
Module::Build::Bundling.3pm
9999
0444
edit
dl
rm
Module::Build::Compat.3pm
10885
0444
edit
dl
rm
Module::Build::ConfigData.3pm
7388
0444
edit
dl
rm
Module::Build::Cookbook.3pm
25946
0444
edit
dl
rm
Module::Build::Notes.3pm
4690
0444
edit
dl
rm
Module::Build::Platform::aix.3pm
4472
0444
edit
dl
rm
Module::Build::Platform::cygwin.3pm
4505
0444
edit
dl
rm
Module::Build::Platform::darwin.3pm
4491
0444
edit
dl
rm
Module::Build::Platform::Default.3pm
4490
0444
edit
dl
rm
Module::Build::Platform::MacOS.3pm
5398
0444
edit
dl
rm
Module::Build::Platform::os2.3pm
4474
0444
edit
dl
rm
Module::Build::Platform::Unix.3pm
4481
0444
edit
dl
rm
Module::Build::Platform::VMS.3pm
7885
0444
edit
dl
rm
Module::Build::Platform::VOS.3pm
4477
0444
edit
dl
rm
Module::Build::Platform::Windows.3pm
4529
0444
edit
dl
rm
Module::Build::PPMMaker.3pm
4886
0444
edit
dl
rm
Mozilla::CA.3pm
3571
0444
edit
dl
rm
Net::CIDR::Lite.3pm
9562
0444
edit
dl
rm
Net::Cmd.3pm
11545
0444
edit
dl
rm
Net::Config.3pm
8100
0444
edit
dl
rm
Net::Domain.3pm
3835
0444
edit
dl
rm
Net::FTP.3pm
27341
0444
edit
dl
rm
Net::FTP::dataconn.3pm
3979
0444
edit
dl
rm
Net::HTTP.3pm
16375
0444
edit
dl
rm
Net::HTTP::NB.3pm
5394
0444
edit
dl
rm
Net::HTTPS.3pm
5438
0444
edit
dl
rm
Net::IP.3pm
27697
0444
edit
dl
rm
Net::libnetFAQ.3pm
14746
0444
edit
dl
rm
Net::Netrc.3pm
6729
0444
edit
dl
rm
Net::NNTP.3pm
23193
0444
edit
dl
rm
Net::POP3.3pm
12259
0444
edit
dl
rm
Net::SMTP.3pm
18880
0444
edit
dl
rm
Net::SSLeay.3pm
349350
0444
edit
dl
rm
Net::SSLeay::Handle.3pm
9127
0444
edit
dl
rm
Net::Time.3pm
4524
0444
edit
dl
rm
ok.3pm
2851
0444
edit
dl
rm
Parse::CPAN::Meta.3pm
10187
0444
edit
dl
rm
POD2::DE::local::lib.3pm
22879
0444
edit
dl
rm
POD2::PT_BR::local::lib.3pm
22762
0444
edit
dl
rm
Socket.3pm
34078
0444
edit
dl
rm
Sub::Identify.3pm
5087
0444
edit
dl
rm
SUPER.3pm
7394
0444
edit
dl
rm
Switch.3pm
19014
0444
edit
dl
rm
TAP::Base.3pm
3401
0444
edit
dl
rm
TAP::Formatter::Base.3pm
6233
0444
edit
dl
rm
TAP::Formatter::Color.3pm
3717
0444
edit
dl
rm
TAP::Formatter::Console.3pm
2722
0444
edit
dl
rm
TAP::Formatter::Console::ParallelSession.3pm
3065
0444
edit
dl
rm
TAP::Formatter::Console::Session.3pm
2832
0444
edit
dl
rm
TAP::Formatter::File.3pm
2693
0444
edit
dl
rm
TAP::Formatter::File::Session.3pm
2847
0444
edit
dl
rm
TAP::Formatter::Session.3pm
3603
0444
edit
dl
rm
TAP::Harness.3pm
21300
0444
edit
dl
rm
TAP::Harness::Beyond.3pm
19118
0444
edit
dl
rm
TAP::Harness::Env.3pm
5467
0444
edit
dl
rm
TAP::Object.3pm
4497
0444
edit
dl
rm
TAP::Parser.3pm
42210
0444
edit
dl
rm
TAP::Parser::Aggregator.3pm
8023
0444
edit
dl
rm
TAP::Parser::Grammar.3pm
8647
0444
edit
dl
rm
TAP::Parser::Iterator.3pm
4993
0444
edit
dl
rm
TAP::Parser::Iterator::Array.3pm
3771
0444
edit
dl
rm
TAP::Parser::Iterator::Process.3pm
4601
0444
edit
dl
rm
TAP::Parser::Iterator::Stream.3pm
3712
0444
edit
dl
rm
TAP::Parser::IteratorFactory.3pm
6904
0444
edit
dl
rm
TAP::Parser::Multiplexer.3pm
4646
0444
edit
dl
rm
TAP::Parser::Result.3pm
7512
0444
edit
dl
rm
TAP::Parser::Result::Bailout.3pm
3293
0444
edit
dl
rm
TAP::Parser::Result::Comment.3pm
3118
0444
edit
dl
rm
TAP::Parser::Result::Plan.3pm
4173
0444
edit
dl
rm
TAP::Parser::Result::Pragma.3pm
3073
0444
edit
dl
rm
TAP::Parser::Result::Test.3pm
7114
0444
edit
dl
rm
TAP::Parser::Result::Unknown.3pm
2973
0444
edit
dl
rm
TAP::Parser::Result::Version.3pm
3154
0444
edit
dl
rm
TAP::Parser::Result::YAML.3pm
3086
0444
edit
dl
rm
TAP::Parser::ResultFactory.3pm
5523
0444
edit
dl
rm
TAP::Parser::Scheduler.3pm
8113
0444
edit
dl
rm
TAP::Parser::Scheduler::Job.3pm
4301
0444
edit
dl
rm
TAP::Parser::Scheduler::Spinner.3pm
3346
0444
edit
dl
rm
TAP::Parser::Source.3pm
8170
0444
edit
dl
rm
TAP::Parser::SourceHandler.3pm
7559
0444
edit
dl
rm
TAP::Parser::SourceHandler::Executable.3pm
5297
0444
edit
dl
rm
TAP::Parser::SourceHandler::File.3pm
4567
0444
edit
dl
rm
TAP::Parser::SourceHandler::Handle.3pm
4425
0444
edit
dl
rm
TAP::Parser::SourceHandler::Perl.3pm
6262
0444
edit
dl
rm
TAP::Parser::SourceHandler::RawTAP.3pm
4434
0444
edit
dl
rm
TAP::Parser::YAMLish::Reader.3pm
3995
0444
edit
dl
rm
TAP::Parser::YAMLish::Writer.3pm
4879
0444
edit
dl
rm
Template.3pm
27909
0444
edit
dl
rm
Template::Base.3pm
8149
0444
edit
dl
rm
Template::Config.3pm
8687
0444
edit
dl
rm
Template::Constants.3pm
7815
0444
edit
dl
rm
Template::Context.3pm
26637
0444
edit
dl
rm
Template::Directive.3pm
4821
0444
edit
dl
rm
Template::Document.3pm
11829
0444
edit
dl
rm
Template::Exception.3pm
6763
0444
edit
dl
rm
Template::FAQ.3pm
14564
0444
edit
dl
rm
Template::Filters.3pm
9817
0444
edit
dl
rm
Template::Grammar.3pm
5039
0444
edit
dl
rm
Template::Iterator.3pm
11413
0444
edit
dl
rm
Template::Manual.3pm
6317
0444
edit
dl
rm
Template::Manual::Config.3pm
79504
0444
edit
dl
rm
Template::Manual::Credits.3pm
8246
0444
edit
dl
rm
Template::Manual::Directives.3pm
77293
0444
edit
dl
rm
Template::Manual::Filters.3pm
20810
0444
edit
dl
rm
Template::Manual::Internals.3pm
23433
0444
edit
dl
rm
Template::Manual::Intro.3pm
14092
0444
edit
dl
rm
Template::Manual::Plugins.3pm
13780
0444
edit
dl
rm
Template::Manual::Syntax.3pm
14549
0444
edit
dl
rm
Template::Manual::Variables.3pm
33110
0444
edit
dl
rm
Template::Manual::Views.3pm
25953
0444
edit
dl
rm
Template::Manual::VMethods.3pm
28195
0444
edit
dl
rm
Template::Modules.3pm
9827
0444
edit
dl
rm
Template::Namespace::Constants.3pm
6002
0444
edit
dl
rm
Template::Parser.3pm
9917
0444
edit
dl
rm
Template::Plugin.3pm
10937
0444
edit
dl
rm
Template::Plugin::Assert.3pm
5446
0444
edit
dl
rm
Template::Plugin::CGI.3pm
6188
0444
edit
dl
rm
Template::Plugin::Datafile.3pm
6601
0444
edit
dl
rm
Template::Plugin::Date.3pm
9538
0444
edit
dl
rm
Template::Plugin::Directory.3pm
11979
0444
edit
dl
rm
Template::Plugin::Dumper.3pm
6078
0444
edit
dl
rm
Template::Plugin::File.3pm
13009
0444
edit
dl
rm
Template::Plugin::Filter.3pm
12936
0444
edit
dl
rm
Template::Plugin::Format.3pm
4895
0444
edit
dl
rm
Template::Plugin::HTML.3pm
7823
0444
edit
dl
rm
Template::Plugin::Image.3pm
11950
0444
edit
dl
rm
Template::Plugin::Iterator.3pm
5061
0444
edit
dl
rm
Template::Plugin::Math.3pm
6623
0444
edit
dl
rm
Template::Plugin::Pod.3pm
4784
0444
edit
dl
rm
Template::Plugin::Procedural.3pm
5631
0444
edit
dl
rm
Template::Plugin::Scalar.3pm
5032
0444
edit
dl
rm
Template::Plugin::String.3pm
17263
0444
edit
dl
rm
Template::Plugin::Table.3pm
11145
0444
edit
dl
rm
Template::Plugin::URL.3pm
8080
0444
edit
dl
rm
Template::Plugin::View.3pm
5479
0444
edit
dl
rm
Template::Plugin::Wrap.3pm
6433
0444
edit
dl
rm
Template::Plugins.3pm
9733
0444
edit
dl
rm
Template::Provider.3pm
14678
0444
edit
dl
rm
Template::Service.3pm
14813
0444
edit
dl
rm
Template::Stash.3pm
11983
0444
edit
dl
rm
Template::Stash::Context.3pm
7130
0444
edit
dl
rm
Template::Stash::XS.3pm
6644
0444
edit
dl
rm
Template::Test.3pm
15524
0444
edit
dl
rm
Template::Toolkit.3pm
9227
0444
edit
dl
rm
Template::Tools.3pm
5001
0444
edit
dl
rm
Template::Tools::tpage.3pm
5806
0444
edit
dl
rm
Template::Tools::ttree.3pm
16567
0444
edit
dl
rm
Template::Tutorial.3pm
4566
0444
edit
dl
rm
Template::Tutorial::Datafile.3pm
19539
0444
edit
dl
rm
Template::Tutorial::Web.3pm
34118
0444
edit
dl
rm
Template::View.3pm
12618
0444
edit
dl
rm
Template::VMethods.3pm
4688
0444
edit
dl
rm
Term::ReadKey.3pm
13029
0444
edit
dl
rm
Test2.3pm
9556
0444
edit
dl
rm
Test2::API.3pm
30424
0444
edit
dl
rm
Test2::API::Breakage.3pm
4988
0444
edit
dl
rm
Test2::API::Context.3pm
17574
0444
edit
dl
rm
Test2::API::Instance.3pm
12404
0444
edit
dl
rm
Test2::API::Stack.3pm
6568
0444
edit
dl
rm
Test2::Event.3pm
9189
0444
edit
dl
rm
Test2::Event::Bail.3pm
3470
0444
edit
dl
rm
Test2::Event::Diag.3pm
3338
0444
edit
dl
rm
Test2::Event::Exception.3pm
3520
0444
edit
dl
rm
Test2::Event::Generic.3pm
7662
0444
edit
dl
rm
Test2::Event::Info.3pm
4261
0444
edit
dl
rm
Test2::Event::Note.3pm
3323
0444
edit
dl
rm
Test2::Event::Ok.3pm
4255
0444
edit
dl
rm
Test2::Event::Plan.3pm
3907
0444
edit
dl
rm
Test2::Event::Skip.3pm
3665
0444
edit
dl
rm
Test2::Event::Subtest.3pm
3573
0444
edit
dl
rm
Test2::Event::Waiting.3pm
3107
0444
edit
dl
rm
Test2::Formatter.3pm
5208
0444
edit
dl
rm
Test2::Formatter::TAP.3pm
9255
0444
edit
dl
rm
Test2::Hub.3pm
16755
0444
edit
dl
rm
Test2::Hub::Interceptor.3pm
2937
0444
edit
dl
rm
Test2::Hub::Interceptor::Terminator.3pm
2980
0444
edit
dl
rm
Test2::Hub::Subtest.3pm
3803
0444
edit
dl
rm
Test2::IPC.3pm
3324
0444
edit
dl
rm
Test2::IPC::Driver.3pm
9512
0444
edit
dl
rm
Test2::IPC::Driver::Files.3pm
3822
0444
edit
dl
rm
Test2::Transition.3pm
18406
0444
edit
dl
rm
Test2::Util.3pm
5123
0444
edit
dl
rm
Test2::Util::ExternalMeta.3pm
5594
0444
edit
dl
rm
Test2::Util::HashBase.3pm
7463
0444
edit
dl
rm
Test2::Util::Trace.3pm
5577
0444
edit
dl
rm
Test::Builder.3pm
26915
0444
edit
dl
rm
Test::Builder::Formatter.3pm
3656
0444
edit
dl
rm
Test::Builder::IO::Scalar.3pm
9740
0444
edit
dl
rm
Test::Builder::Module.3pm
5567
0444
edit
dl
rm
Test::Builder::Tester.3pm
11550
0444
edit
dl
rm
Test::Builder::Tester::Color.3pm
3131
0444
edit
dl
rm
Test::Builder::TodoDiag.3pm
3129
0444
edit
dl
rm
Test::Fatal.3pm
9303
0444
edit
dl
rm
Test::HACKING.3pm
9253
0444
edit
dl
rm
Test::Harness.3pm
11028
0444
edit
dl
rm
Test::LeakTrace.3pm
10022
0444
edit
dl
rm
Test::LeakTrace::JA.3pm
12328
0444
edit
dl
rm
Test::LeakTrace::Script.3pm
5140
0444
edit
dl
rm
Test::MockModule.3pm
10818
0444
edit
dl
rm
Test::More.3pm
43215
0444
edit
dl
rm
Test::More::UTF8.3pm
3602
0444
edit
dl
rm
Test::RequiresInternet.3pm
3944
0444
edit
dl
rm
Test::Simple.3pm
9119
0444
edit
dl
rm
Test::Tester.3pm
15781
0444
edit
dl
rm
Test::Tester::Capture.3pm
2902
0444
edit
dl
rm
Test::Tester::CaptureRunner.3pm
2673
0444
edit
dl
rm
Test::Tutorial.3pm
24261
0444
edit
dl
rm
Test::use::ok.3pm
3841
0444
edit
dl
rm
Test::Warnings.3pm
14231
0444
edit
dl
rm
Text::Glob.3pm
6106
0444
edit
dl
rm
Text::Template.3pm
65499
0444
edit
dl
rm
Text::Template::Preprocess.3pm
6270
0444
edit
dl
rm
Time::Zone.3pm
3413
0444
edit
dl
rm
TimeDate.3pm
2397
0444
edit
dl
rm
Try::Tiny.3pm
20343
0444
edit
dl
rm
Types::Serialiser.3pm
11473
0444
edit
dl
rm
Types::Serialiser::Error.3pm
2705
0444
edit
dl
rm
version.3pm
13937
0444
edit
dl
rm
version::Internals.3pm
30287
0444
edit
dl
rm
WWW::Mechanize.3pm
68196
0444
edit
dl
rm
WWW::Mechanize::Cookbook.3pm
7159
0444
edit
dl
rm
WWW::Mechanize::Examples.3pm
22490
0444
edit
dl
rm
WWW::Mechanize::FAQ.3pm
24359
0444
edit
dl
rm
WWW::Mechanize::Image.3pm
6490
0444
edit
dl
rm
WWW::Mechanize::Link.3pm
6518
0444
edit
dl
rm
XML::NamespaceSupport.3pm
13052
0444
edit
dl
rm
XML::Parser.3pm
26296
0444
edit
dl
rm
XML::Parser::Expat.3pm
26799
0444
edit
dl
rm
XML::Parser::Style::Debug.3pm
4408
0444
edit
dl
rm
XML::Parser::Style::Objects.3pm
4888
0444
edit
dl
rm
XML::Parser::Style::Stream.3pm
5925
0444
edit
dl
rm
XML::Parser::Style::Subs.3pm
4863
0444
edit
dl
rm
XML::Parser::Style::Tree.3pm
5529
0444
edit
dl
rm
XML::SAX.3pm
9229
0444
edit
dl
rm
XML::SAX::Base.3pm
13704
0444
edit
dl
rm
XML::SAX::BuildSAXBase.3pm
13700
0444
edit
dl
rm
XML::SAX::DocumentLocator.3pm
5239
0444
edit
dl
rm
XML::SAX::Exception.3pm
5622
0444
edit
dl
rm
XML::SAX::Expat.3pm
6404
0444
edit
dl
rm
XML::SAX::Intro.3pm
20220
0444
edit
dl
rm
XML::SAX::ParserFactory.3pm
7919
0444
edit
dl
rm
XML::SAX::PurePerl.3pm
6172
0444
edit
dl
rm
XML::SAX::PurePerl::Reader.3pm
4103
0444
edit
dl
rm
XML::Simple.3pm
65589
0444
edit
dl
rm
XML::Simple::FAQ.3pm
27223
0444
edit
dl
rm
YAML.3pm
29980
0444
edit
dl
rm
YAML::Any.3pm
7487
0444
edit
dl
rm
YAML::Dumper.3pm
4776
0444
edit
dl
rm
YAML::Dumper::Base.3pm
4642
0444
edit
dl
rm
YAML::Error.3pm
4681
0444
edit
dl
rm
YAML::Loader.3pm
4766
0444
edit
dl
rm
YAML::Loader::Base.3pm
4642
0444
edit
dl
rm
YAML::Marshall.3pm
4640
0444
edit
dl
rm
YAML::Node.3pm
6743
0444
edit
dl
rm
YAML::Syck.3pm
10806
0444
edit
dl
rm
YAML::Tag.3pm
4499
0444
edit
dl
rm
YAML::Types.3pm
4716
0444
edit
dl
rm
Edit:
/usr/local/share/man/man3/Template::Manual::Directives.3pm
(77293B)
.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Template::Manual::Directives 3" .TH Template::Manual::Directives 3 "2014-04-23" "perl v5.16.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Template::Manual::Directives \- Template directives .SH "Accessing and Updating Template Variables" .IX Header "Accessing and Updating Template Variables" .SS "\s-1GET\s0" .IX Subsection "GET" The \f(CW\*(C`GET\*(C'\fR directive retrieves and outputs the value of the named variable. .PP .Vb 1 \& [% GET foo %] .Ve .PP The \f(CW\*(C`GET\*(C'\fR keyword is optional. A variable can be specified in a directive tag by itself. .PP .Vb 1 \& [% foo %] .Ve .PP The variable can have an unlimited number of elements, each separated by a dot. Each element can have arguments specified within parentheses. .PP .Vb 4 \& [% foo %] \& [% bar.baz %] \& [% biz.baz(10) %] \& ...etc... .Ve .PP See Template::Manual::Variables for a full discussion on template variables. .PP You can also specify expressions using the logical (\f(CW\*(C`and\*(C'\fR, \f(CW\*(C`or\*(C'\fR, \f(CW\*(C`not\*(C'\fR, \f(CW\*(C`?\*(C'\fR, \f(CW\*(C`:\*(C'\fR) and mathematic operators (\f(CW\*(C`+\*(C'\fR, \f(CW\*(C`\-\*(C'\fR, \f(CW\*(C`*\*(C'\fR, \f(CW\*(C`/\*(C'\fR, \f(CW\*(C`%\*(C'\fR, \f(CW\*(C`mod\*(C'\fR, \f(CW\*(C`div\*(C'\fR). .PP .Vb 1 \& [% template.title or default.title %] \& \& [% score * 100 %] \& \& [% order.nitems ? checkout(order.total) : \*(Aqno items\*(Aq %] .Ve .PP The \f(CW\*(C`div\*(C'\fR operator returns the integer result of division. Both \f(CW\*(C`%\*(C'\fR and \&\f(CW\*(C`mod\*(C'\fR return the modulus (i.e. remainder) of division. .PP .Vb 3 \& [% 15 / 6 %] # 2.5 \& [% 15 div 6 %] # 2 \& [% 15 mod 6 %] # 3 .Ve .SS "\s-1CALL\s0" .IX Subsection "CALL" The \f(CW\*(C`CALL\*(C'\fR directive is similar to \f(CW\*(C`GET\*(C'\fR in evaluating the variable named, but doesn't print the result returned. This can be useful when a variable is bound to a sub-routine or object method which you want to call but aren't interested in the value returned. .PP .Vb 1 \& [% CALL dbi.disconnect %] \& \& [% CALL inc_page_counter(page_count) %] .Ve .SS "\s-1SET\s0" .IX Subsection "SET" The \f(CW\*(C`SET\*(C'\fR directive allows you to assign new values to existing variables or create new temporary variables. .PP .Vb 1 \& [% SET title = \*(AqHello World\*(Aq %] .Ve .PP The \f(CW\*(C`SET\*(C'\fR keyword is also optional. .PP .Vb 1 \& [% title = \*(AqHello World\*(Aq %] .Ve .PP Variables may be assigned the values of other variables, unquoted numbers (2.718), literal text ('single quotes') or quoted text (\*(L"double quotes\*(R"). In the latter case, any variable references within the text will be interpolated when the string is evaluated. Variables should be prefixed by \f(CW\*(C`$\*(C'\fR, using curly braces to explicitly scope the variable name where necessary. .PP .Vb 4 \& [% foo = \*(AqFoo\*(Aq %] # literal value \*(AqFoo\*(Aq \& [% bar = foo %] # value of variable \*(Aqfoo\*(Aq \& [% cost = \*(Aq$100\*(Aq %] # literal value \*(Aq$100\*(Aq \& [% item = "$bar: ${cost}.00" %] # value "Foo: $100.00" .Ve .PP Multiple variables may be assigned in the same directive and are evaluated in the order specified. Thus, the above could have been written: .PP .Vb 5 \& [% foo = \*(AqFoo\*(Aq \& bar = foo \& cost = \*(Aq$100\*(Aq \& item = "$bar: ${cost}.00" \& %] .Ve .PP Simple expressions can also be used, as per \f(CW\*(C`GET\*(C'\fR. .PP .Vb 7 \& [% ten = 10 \& twenty = 20 \& thirty = twenty + ten \& forty = 2 * twenty \& fifty = 100 div 2 \& six = twenty mod 7 \& %] .Ve .PP You can concatenate strings together using the \f(CW\*(Aq _ \*(Aq\fR operator. In Perl 5, the \f(CW\*(C`.\*(C'\fR is used for string concatenation, but in Perl 6, as in the Template Toolkit, the \f(CW\*(C`.\*(C'\fR will be used as the method calling operator and \f(CW\*(Aq _ \*(Aq\fR will be used for string concatenation. Note that the operator must be specified with surrounding whitespace which, as Larry says, is construed as a feature: .PP .Vb 1 \& [% copyright = \*(Aq(C) Copyright\*(Aq _ year _ \*(Aq \*(Aq _ author %] .Ve .PP You can, of course, achieve a similar effect with double quoted string interpolation. .PP .Vb 1 \& [% copyright = "(C) Copyright $year $author" %] .Ve .SS "\s-1DEFAULT\s0" .IX Subsection "DEFAULT" The \f(CW\*(C`DEFAULT\*(C'\fR directive is similar to \f(CW\*(C`SET\*(C'\fR but only updates variables that are currently undefined or have no \*(L"true\*(R" value (in the Perl sense). .PP .Vb 4 \& [% DEFAULT \& name = \*(AqJohn Doe\*(Aq \& id = \*(Aqjdoe\*(Aq \& %] .Ve .PP This can be particularly useful in common template components to ensure that some sensible default are provided for otherwise undefined variables. .PP .Vb 10 \& [% DEFAULT \& title = \*(AqHello World\*(Aq \& bgcol = \*(Aq#ffffff\*(Aq \& %] \& <html> \& <head> \& <title>[% title %]</title> \& </head> \& <body bgcolor="[% bgcol %]"> \& ...etc... .Ve .SH "Processing Template Files and Blocks" .IX Header "Processing Template Files and Blocks" .SS "\s-1INSERT\s0" .IX Subsection "INSERT" The \f(CW\*(C`INSERT\*(C'\fR directive is used to insert the contents of an external file at the current position. .PP .Vb 1 \& [% INSERT myfile %] .Ve .PP No attempt to parse or process the file is made. The contents, possibly including any embedded template directives, are inserted intact. .PP The filename specified should be relative to one of the \f(CW\*(C`INCLUDE_PATH\*(C'\fR directories. Absolute (i.e. starting with \f(CW\*(C`/\*(C'\fR) and relative (i.e. starting with \f(CW\*(C`.\*(C'\fR) filenames may be used if the \f(CW\*(C`ABSOLUTE\*(C'\fR and \&\f(CW\*(C`RELATIVE\*(C'\fR options are set, respectively. Both these options are disabled by default. .PP .Vb 3 \& my $template = Template\->new({ \& INCLUDE_PATH => \*(Aq/here:/there\*(Aq, \& }); \& \& $template\->process(\*(Aqmyfile\*(Aq); .Ve .PP \&\fImyfile\fR: .PP .Vb 3 \& [% INSERT foo %] # looks for /here/foo then /there/foo \& [% INSERT /etc/passwd %] # file error: ABSOLUTE not set \& [% INSERT ../secret %] # file error: RELATIVE not set .Ve .PP For convenience, the filename does not need to be quoted as long as it contains only alphanumeric characters, underscores, dots or forward slashes. Names containing any other characters should be quoted. .PP .Vb 2 \& [% INSERT misc/legalese.txt %] \& [% INSERT \*(Aqdos98/Program Files/stupid\*(Aq %] .Ve .PP To evaluate a variable to specify a filename, you should explicitly prefix it with a \f(CW\*(C`$\*(C'\fR or use double-quoted string interpolation. .PP .Vb 3 \& [% language = \*(Aqen\*(Aq \& legalese = \*(Aqmisc/legalese.txt\*(Aq \& %] \& \& [% INSERT $legalese %] # misc/legalese.txt \& [% INSERT "$language/$legalese" %] # en/misc/legalese.txt .Ve .PP Multiple files can be specified using \f(CW\*(C`+\*(C'\fR as a delimiter. All files should be unquoted names or quoted strings. Any variables should be interpolated into double-quoted strings. .PP .Vb 2 \& [% INSERT legalese.txt + warning.txt %] \& [% INSERT "$legalese" + warning.txt %] # requires quoting .Ve .SS "\s-1INCLUDE\s0" .IX Subsection "INCLUDE" The \f(CW\*(C`INCLUDE\*(C'\fR directive is used to process and include the output of another template file or block. .PP .Vb 1 \& [% INCLUDE header %] .Ve .PP If a \f(CW\*(C`BLOCK\*(C'\fR of the specified name is defined in the same file, or in a file from which the current template has been called (i.e. a parent template) then it will be used in preference to any file of the same name. .PP .Vb 1 \& [% INCLUDE table %] # uses BLOCK defined below \& \& [% BLOCK table %] \& <table> \& ... \& </table> \& [% END %] .Ve .PP If a \f(CW\*(C`BLOCK\*(C'\fR definition is not currently visible then the template name should be a file relative to one of the \f(CW\*(C`INCLUDE_PATH\*(C'\fR directories, or an absolute or relative file name if the \f(CW\*(C`ABSOLUTE\*(C'\fR/\f(CW\*(C`RELATIVE\*(C'\fR options are appropriately enabled. The \f(CW\*(C`INCLUDE\*(C'\fR directive automatically quotes the filename specified, as per \f(CW\*(C`INSERT\*(C'\fR described above. When a variable contains the name of the template for the \f(CW\*(C`INCLUDE\*(C'\fR directive, it should be explicitly prefixed by \f(CW\*(C`$\*(C'\fR or double-quoted .PP .Vb 4 \& [% myheader = \*(Aqmy/misc/header\*(Aq %] \& [% INCLUDE myheader %] # \*(Aqmyheader\*(Aq \& [% INCLUDE $myheader %] # \*(Aqmy/misc/header\*(Aq \& [% INCLUDE "$myheader" %] # \*(Aqmy/misc/header\*(Aq .Ve .PP Any template directives embedded within the file will be processed accordingly. All variables currently defined will be visible and accessible from within the included template. .PP .Vb 4 \& [% title = \*(AqHello World\*(Aq %] \& [% INCLUDE header %] \& <body> \& ... .Ve .PP \&\fIheader\fR: .PP .Vb 2 \& <html> \& <title>[% title %]</title> .Ve .PP output: .PP .Vb 4 \& <html> \& <title>Hello World</title> \& <body> \& ... .Ve .PP Local variable definitions may be specified after the template name, temporarily masking any existing variables. Insignificant whitespace is ignored within directives so you can add variable definitions on the same line, the next line or split across several line with comments interspersed, if you prefer. .PP .Vb 1 \& [% INCLUDE table %] \& \& [% INCLUDE table title="Active Projects" %] \& \& [% INCLUDE table \& title = "Active Projects" \& bgcolor = "#80ff00" # chartreuse \& border = 2 \& %] .Ve .PP The \f(CW\*(C`INCLUDE\*(C'\fR directive localises (i.e. copies) all variables before processing the template. Any changes made within the included template will not affect variables in the including template. .PP .Vb 1 \& [% foo = 10 %] \& \& foo is originally [% foo %] \& [% INCLUDE bar %] \& foo is still [% foo %] \& \& [% BLOCK bar %] \& foo was [% foo %] \& [% foo = 20 %] \& foo is now [% foo %] \& [% END %] .Ve .PP output: .PP .Vb 4 \& foo is originally 10 \& foo was 10 \& foo is now 20 \& foo is still 10 .Ve .PP Technical Note: the localisation of the stash (that is, the process by which variables are copied before an \f(CW\*(C`INCLUDE\*(C'\fR to prevent being overwritten) is only skin deep. The top-level variable namespace (hash) is copied, but no attempt is made to perform a deep-copy of other structures (hashes, arrays, objects, etc.) Therefore, a \f(CW\*(C`foo\*(C'\fR variable referencing a hash will be copied to create a new \f(CW\*(C`foo\*(C'\fR variable but which points to the same hash array. Thus, if you update compound variables (e.g. \f(CW\*(C`foo.bar\*(C'\fR) then you will change the original copy, regardless of any stash localisation. If you're not worried about preserving variable values, or you trust the templates you're including then you might prefer to use the \f(CW\*(C`PROCESS\*(C'\fR directive which is faster by virtue of not performing any localisation. .PP You can specify dotted variables as \*(L"local\*(R" variables to an \f(CW\*(C`INCLUDE\*(C'\fR directive. However, be aware that because of the localisation issues explained above (if you skipped the previous Technical Note above then you might want to go back and read it or skip this section too), the variables might not actually be \&\*(L"local\*(R". If the first element of the variable name already references a hash array then the variable update will affect the original variable. .PP .Vb 4 \& [% foo = { \& bar = \*(AqBaz\*(Aq \& } \& %] \& \& [% INCLUDE somefile foo.bar=\*(AqBoz\*(Aq %] \& \& [% foo.bar %] # Boz .Ve .PP This behaviour can be a little unpredictable (and may well be improved upon in a future version). If you know what you're doing with it and you're sure that the variables in question are defined (nor not) as you expect them to be, then you can rely on this feature to implement some powerful \*(L"global\*(R" data sharing techniques. Otherwise, you might prefer to steer well clear and always pass simple (undotted) variables as parameters to \f(CW\*(C`INCLUDE\*(C'\fR and other similar directives. .PP If you want to process several templates in one go then you can specify each of their names (quoted or unquoted names only, no unquoted \&\f(CW$variables\fR) joined together by \f(CW\*(C`+\*(C'\fR. The \f(CW\*(C`INCLUDE\*(C'\fR directive will then process them in order. .PP .Vb 3 \& [% INCLUDE html/header + "site/$header" + site/menu \& title = "My Groovy Web Site" \& %] .Ve .PP The variable stash is localised once and then the templates specified are processed in order, all within that same variable context. This makes it slightly faster than specifying several separate \f(CW\*(C`INCLUDE\*(C'\fR directives (because you only clone the variable stash once instead of n times), but not quite as \*(L"safe\*(R" because any variable changes in the first file will be visible in the second, third and so on. This might be what you want, of course, but then again, it might not. .SS "\s-1PROCESS\s0" .IX Subsection "PROCESS" The \s-1PROCESS\s0 directive is similar to \f(CW\*(C`INCLUDE\*(C'\fR but does not perform any localisation of variables before processing the template. Any changes made to variables within the included template will be visible in the including template. .PP .Vb 1 \& [% foo = 10 %] \& \& foo is [% foo %] \& [% PROCESS bar %] \& foo is [% foo %] \& \& [% BLOCK bar %] \& [% foo = 20 %] \& changed foo to [% foo %] \& [% END %] .Ve .PP output: .PP .Vb 3 \& foo is 10 \& changed foo to 20 \& foo is 20 .Ve .PP Parameters may be specified in the \f(CW\*(C`PROCESS\*(C'\fR directive, but these too will become visible changes to current variable values. .PP .Vb 6 \& [% foo = 10 %] \& foo is [% foo %] \& [% PROCESS bar \& foo = 20 \& %] \& foo is [% foo %] \& \& [% BLOCK bar %] \& this is bar, foo is [% foo %] \& [% END %] .Ve .PP output: .PP .Vb 3 \& foo is 10 \& this is bar, foo is 20 \& foo is 20 .Ve .PP The \f(CW\*(C`PROCESS\*(C'\fR directive is slightly faster than \f(CW\*(C`INCLUDE\*(C'\fR because it avoids the need to localise (i.e. copy) the variable stash before processing the template. As with \f(CW\*(C`INSERT\*(C'\fR and \f(CW\*(C`INCLUDE\*(C'\fR, the first parameter does not need to be quoted as long as it contains only alphanumeric characters, underscores, periods or forward slashes. A \f(CW\*(C`$\*(C'\fR prefix can be used to explicitly indicate a variable which should be interpolated to provide the template name: .PP .Vb 3 \& [% myheader = \*(Aqmy/misc/header\*(Aq %] \& [% PROCESS myheader %] # \*(Aqmyheader\*(Aq \& [% PROCESS $myheader %] # \*(Aqmy/misc/header\*(Aq .Ve .PP As with \f(CW\*(C`INCLUDE\*(C'\fR, multiple templates can be specified, delimited by \&\f(CW\*(C`+\*(C'\fR, and are processed in order. .PP .Vb 1 \& [% PROCESS html/header + my/header %] .Ve .SS "\s-1WRAPPER\s0" .IX Subsection "WRAPPER" It's not unusual to find yourself adding common headers and footers to pages or sub-sections within a page. Something like this: .PP .Vb 6 \& [% INCLUDE section/header \& title = \*(AqQuantum Mechanics\*(Aq \& %] \& Quantum mechanics is a very interesting subject wish \& should prove easy for the layman to fully comprehend. \& [% INCLUDE section/footer %] \& \& [% INCLUDE section/header \& title = \*(AqDesktop Nuclear Fusion for under $50\*(Aq \& %] \& This describes a simple device which generates significant \& sustainable electrical power from common tap water by process \& of nuclear fusion. \& [% INCLUDE section/footer %] .Ve .PP The individual template components being included might look like these: .PP section/header: .PP .Vb 2 \& <p> \& <h2>[% title %]</h2> .Ve .PP section/footer: .PP .Vb 1 \& </p> .Ve .PP The \f(CW\*(C`WRAPPER\*(C'\fR directive provides a way of simplifying this a little. It encloses a block up to a matching \f(CW\*(C`END\*(C'\fR directive, which is first processed to generate some output. This is then passed to the named template file or \&\f(CW\*(C`BLOCK\*(C'\fR as the \f(CW\*(C`content\*(C'\fR variable. .PP .Vb 6 \& [% WRAPPER section \& title = \*(AqQuantum Mechanics\*(Aq \& %] \& Quantum mechanics is a very interesting subject wish \& should prove easy for the layman to fully comprehend. \& [% END %] \& \& [% WRAPPER section \& title = \*(AqDesktop Nuclear Fusion for under $50\*(Aq \& %] \& This describes a simple device which generates significant \& sustainable electrical power from common tap water by process \& of nuclear fusion. \& [% END %] .Ve .PP The single 'section' template can then be defined as: .PP .Vb 4 \& <h2>[% title %]</h2> \& <p> \& [% content %] \& </p> .Ve .PP Like other block directives, it can be used in side-effect notation: .PP .Vb 1 \& [% INSERT legalese.txt WRAPPER big_bold_table %] .Ve .PP It's also possible to specify multiple templates to a \f(CW\*(C`WRAPPER\*(C'\fR directive. The specification order indicates outermost to innermost wrapper templates. For example, given the following template block definitions: .PP .Vb 2 \& [% BLOCK bold %]<b>[% content %]</b>[% END %] \& [% BLOCK italic %]<i>[% content %]</i>[% END %] .Ve .PP the directive .PP .Vb 1 \& [% WRAPPER bold+italic %]Hello World[% END %] .Ve .PP would generate the following output: .PP .Vb 1 \& <b><i>Hello World</i></b> .Ve .SS "\s-1BLOCK\s0" .IX Subsection "BLOCK" The \f(CW\*(C`BLOCK\*(C'\fR...\f(CW\*(C`END\*(C'\fR construct can be used to define template component blocks which can be processed with the \f(CW\*(C`INCLUDE\*(C'\fR, \f(CW\*(C`PROCESS\*(C'\fR and \f(CW\*(C`WRAPPER\*(C'\fR directives. .PP .Vb 6 \& [% BLOCK tabrow %] \& <tr> \& <td>[% name %]<td> \& <td>[% email %]</td> \& </tr> \& [% END %] \& \& <table> \& [% PROCESS tabrow name=\*(AqFred\*(Aq email=\*(Aqfred@nowhere.com\*(Aq %] \& [% PROCESS tabrow name=\*(AqAlan\*(Aq email=\*(Aqalan@nowhere.com\*(Aq %] \& </table> .Ve .PP A \f(CW\*(C`BLOCK\*(C'\fR definition can be used before it is defined, as long as the definition resides in the same file. The block definition itself does not generate any output. .PP .Vb 1 \& [% PROCESS tmpblk %] \& \& [% BLOCK tmpblk %] This is OK [% END %] .Ve .PP You can use an anonymous \f(CW\*(C`BLOCK\*(C'\fR to capture the output of a template fragment. .PP .Vb 8 \& [% julius = BLOCK %] \& And Caesar\*(Aqs spirit, ranging for revenge, \& With Ate by his side come hot from hell, \& Shall in these confines with a monarch\*(Aqs voice \& Cry \*(AqHavoc\*(Aq, and let slip the dogs of war; \& That this foul deed shall smell above the earth \& With carrion men, groaning for burial. \& [% END %] .Ve .PP Like a named block, it can contain any other template directives which are processed when the block is defined. The output generated by the block is then assigned to the variable \f(CW\*(C`julius\*(C'\fR. .PP Anonymous \f(CW\*(C`BLOCK\*(C'\fRs can also be used to define block macros. The enclosing block is processed each time the macro is called. .PP .Vb 3 \& [% MACRO locate BLOCK %] \& The [% animal %] sat on the [% place %]. \& [% END %] \& \& [% locate(animal=\*(Aqcat\*(Aq, place=\*(Aqmat\*(Aq) %] # The cat sat on the mat \& [% locate(animal=\*(Aqdog\*(Aq, place=\*(Aqlog\*(Aq) %] # The dog sat on the log .Ve .SH "Conditional Processing" .IX Header "Conditional Processing" .SS "\s-1IF / UNLESS / ELSIF / ELSE\s0" .IX Subsection "IF / UNLESS / ELSIF / ELSE" The \f(CW\*(C`IF\*(C'\fR and \f(CW\*(C`UNLESS\*(C'\fR directives can be used to process or ignore a block based on some run-time condition. .PP .Vb 3 \& [% IF frames %] \& [% INCLUDE frameset %] \& [% END %] \& \& [% UNLESS text_mode %] \& [% INCLUDE biglogo %] \& [% END %] .Ve .PP Multiple conditions may be joined with \f(CW\*(C`ELSIF\*(C'\fR and/or \f(CW\*(C`ELSE\*(C'\fR blocks. .PP .Vb 9 \& [% IF age < 10 %] \& Hello [% name %], does your mother know you\*(Aqre \& using her AOL account? \& [% ELSIF age < 18 %] \& Sorry, you\*(Aqre not old enough to enter \& (and too dumb to lie about your age) \& [% ELSE %] \& Welcome [% name %]. \& [% END %] .Ve .PP The following conditional and boolean operators may be used: .PP .Vb 1 \& == != < <= > >= && || ! and or not .Ve .PP Conditions may be arbitrarily complex and are evaluated with the same precedence as in Perl. Parenthesis may be used to explicitly determine evaluation order. .PP .Vb 6 \& # ridiculously contrived complex example \& [% IF (name == \*(Aqadmin\*(Aq || uid <= 0) && mode == \*(Aqdebug\*(Aq %] \& I\*(Aqm confused. \& [% ELSIF more > less %] \& That\*(Aqs more or less correct. \& [% END %] .Ve .PP The \f(CW\*(C`and\*(C'\fR, \f(CW\*(C`or\*(C'\fR and \f(CW\*(C`not\*(C'\fR operator are provided as aliases for \&\f(CW\*(C`&&\*(C'\fR, \f(CW\*(C`||\*(C'\fR and \f(CW\*(C`!\*(C'\fR, respectively. Unlike Perl, which treats \&\f(CW\*(C`and\*(C'\fR, \f(CW\*(C`or\*(C'\fR and \f(CW\*(C`not\*(C'\fR as separate, lower-precedence versions of the other operators, the Template Toolkit performs a straightforward substitution of \f(CW\*(C`and\*(C'\fR for \f(CW\*(C`&&\*(C'\fR, and so on. That means that \f(CW\*(C`and\*(C'\fR, \f(CW\*(C`or\*(C'\fR and \f(CW\*(C`not\*(C'\fR have the same operator precedence as \f(CW\*(C`&&\*(C'\fR, \f(CW\*(C`||\*(C'\fR and \f(CW\*(C`!\*(C'\fR. .SS "\s-1SWITCH / CASE\s0" .IX Subsection "SWITCH / CASE" The \f(CW\*(C`SWITCH\*(C'\fR / \f(CW\*(C`CASE\*(C'\fR construct can be used to perform a multi-way conditional test. The \f(CW\*(C`SWITCH\*(C'\fR directive expects an expression which is first evaluated and then compared against each \s-1CASE\s0 statement in turn. Each \f(CW\*(C`CASE\*(C'\fR directive should contain a single value or a list of values which should match. \f(CW\*(C`CASE\*(C'\fR may also be left blank or written as \&\f(CW\*(C`[% CASE DEFAULT %]\*(C'\fR to specify a default match. Only one \f(CW\*(C`CASE\*(C'\fR matches, there is no drop-through between \f(CW\*(C`CASE\*(C'\fR statements. .PP .Vb 10 \& [% SWITCH myvar %] \& [% CASE \*(Aqvalue1\*(Aq %] \& ... \& [% CASE [\*(Aqvalue2\*(Aq, \*(Aqvalue3\*(Aq] %] # multiple values \& ... \& [% CASE myhash.keys %] # ditto \& ... \& [% CASE %] # default \& ... \& [% END %] .Ve .SH "Loop Processing" .IX Header "Loop Processing" .SS "\s-1FOREACH\s0" .IX Subsection "FOREACH" The \f(CW\*(C`FOREACH\*(C'\fR directive will iterate through the items in a list, processing the enclosed block for each one. .PP .Vb 3 \& [% foo = \*(AqFoo\*(Aq \& items = [ \*(Aqone\*(Aq, \*(Aqtwo\*(Aq, \*(Aqthree\*(Aq ] \& %] \& \& Things: \& [% FOREACH thing IN [ foo \*(AqBar\*(Aq "$foo Baz" ] %] \& * [% thing %] \& [% END %] \& \& Items: \& [% FOREACH i IN items %] \& * [% i %] \& [% END %] \& \& Stuff: \& [% stuff = [ foo "$foo Bar" ] %] \& [% FOREACH s IN stuff %] \& * [% s %] \& [% END %] .Ve .PP output: .PP .Vb 4 \& Things: \& * Foo \& * Bar \& * Foo Baz \& \& Items: \& * one \& * two \& * three \& \& Stuff: \& * Foo \& * Foo Bar .Ve .PP You can use also use \f(CW\*(C`=\*(C'\fR instead of \f(CW\*(C`IN\*(C'\fR if you prefer. .PP .Vb 1 \& [% FOREACH i = items %] .Ve .PP When the \f(CW\*(C`FOREACH\*(C'\fR directive is used without specifying a target variable, any iterated values which are hash references will be automatically imported. .PP .Vb 6 \& [% userlist = [ \& { id => \*(Aqtom\*(Aq, name => \*(AqThomas\*(Aq }, \& { id => \*(Aqdick\*(Aq, name => \*(AqRichard\*(Aq }, \& { id => \*(Aqlarry\*(Aq, name => \*(AqLawrence\*(Aq }, \& ] \& %] \& \& [% FOREACH user IN userlist %] \& [% user.id %] [% user.name %] \& [% END %] .Ve .PP short form: .PP .Vb 3 \& [% FOREACH userlist %] \& [% id %] [% name %] \& [% END %] .Ve .PP Note that this particular usage creates a localised variable context to prevent the imported hash keys from overwriting any existing variables. The imported definitions and any other variables defined in such a \f(CW\*(C`FOREACH\*(C'\fR loop will be lost at the end of the loop, when the previous context and variable values are restored. .PP However, under normal operation, the loop variable remains in scope after the \f(CW\*(C`FOREACH\*(C'\fR loop has ended (caveat: overwriting any variable previously in scope). This is useful as the loop variable is secretly an iterator object (see below) and can be used to analyse the last entry processed by the loop. .PP The \f(CW\*(C`FOREACH\*(C'\fR directive can also be used to iterate through the entries in a hash array. Each entry in the hash is returned in sorted order (based on the key) as a hash array containing 'key' and 'value' items. .PP .Vb 6 \& [% users = { \& tom => \*(AqThomas\*(Aq, \& dick => \*(AqRichard\*(Aq, \& larry => \*(AqLawrence\*(Aq, \& } \& %] \& \& [% FOREACH u IN users %] \& * [% u.key %] : [% u.value %] \& [% END %] .Ve .PP Output: .PP .Vb 3 \& * dick : Richard \& * larry : Lawrence \& * tom : Thomas .Ve .PP The \f(CW\*(C`NEXT\*(C'\fR directive starts the next iteration in the \f(CW\*(C`FOREACH\*(C'\fR loop. .PP .Vb 4 \& [% FOREACH user IN userlist %] \& [% NEXT IF user.isguest %] \& Name: [% user.name %] Email: [% user.email %] \& [% END %] .Ve .PP The \f(CW\*(C`LAST\*(C'\fR directive can be used to prematurely exit the loop. \f(CW\*(C`BREAK\*(C'\fR is also provided as an alias for \f(CW\*(C`LAST\*(C'\fR. .PP .Vb 4 \& [% FOREACH match IN results.nsort(\*(Aqscore\*(Aq).reverse %] \& [% LAST IF match.score < 50 %] \& [% match.score %] : [% match.url %] \& [% END %] .Ve .PP The \f(CW\*(C`FOREACH\*(C'\fR directive is implemented using the Template::Iterator module. A reference to the iterator object for a \f(CW\*(C`FOREACH\*(C'\fR directive is implicitly available in the \f(CW\*(C`loop\*(C'\fR variable. The following methods can be called on the \f(CW\*(C`loop\*(C'\fR iterator. .PP .Vb 8 \& size() number of elements in the list \& max() index number of last element (size \- 1) \& index() index of current iteration from 0 to max() \& count() iteration counter from 1 to size() (i.e. index() + 1) \& first() true if the current iteration is the first \& last() true if the current iteration is the last \& prev() return the previous item in the list \& next() return the next item in the list .Ve .PP See Template::Iterator for further details. .PP Example: .PP .Vb 5 \& [% FOREACH item IN [ \*(Aqfoo\*(Aq, \*(Aqbar\*(Aq, \*(Aqbaz\*(Aq ] \-%] \& [%\- "<ul>\en" IF loop.first %] \& <li>[% loop.count %]/[% loop.size %]: [% item %] \& [%\- "</ul>\en" IF loop.last %] \& [% END %] .Ve .PP Output: .PP .Vb 5 \& <ul> \& <li>1/3: foo \& <li>2/3: bar \& <li>3/3: baz \& </ul> .Ve .PP Nested loops will work as expected, with the \f(CW\*(C`loop\*(C'\fR variable correctly referencing the innermost loop and being restored to any previous value (i.e. an outer loop) at the end of the loop. .PP .Vb 3 \& [% FOREACH group IN grouplist; \& # loop => group iterator \& "Groups:\en" IF loop.first; \& \& FOREACH user IN group.userlist; \& # loop => user iterator \& "$loop.count: $user.name\en"; \& END; \& \& # loop => group iterator \& "End of Groups\en" IF loop.last; \& END \& %] .Ve .PP The \f(CW\*(C`iterator\*(C'\fR plugin can also be used to explicitly create an iterator object. This can be useful within nested loops where you need to keep a reference to the outer iterator within the inner loop. The iterator plugin effectively allows you to create an iterator by a name other than \f(CW\*(C`loop\*(C'\fR. See Template::Plugin::Iterator for further details. .PP .Vb 1 \& [% USE giter = iterator(grouplist) %] \& \& [% FOREACH group IN giter %] \& [% FOREACH user IN group.userlist %] \& user #[% loop.count %] in \& group [% giter.count %] is \& named [% user.name %] \& [% END %] \& [% END %] .Ve .SS "\s-1WHILE\s0" .IX Subsection "WHILE" The \f(CW\*(C`WHILE\*(C'\fR directive can be used to repeatedly process a template block while a conditional expression evaluates true. The expression may be arbitrarily complex as per \f(CW\*(C`IF\*(C'\fR / \f(CW\*(C`UNLESS\*(C'\fR. .PP .Vb 4 \& [% WHILE total < 100 %] \& ... \& [% total = calculate_new_total %] \& [% END %] .Ve .PP An assignment can be enclosed in parenthesis to evaluate the assigned value. .PP .Vb 3 \& [% WHILE (user = get_next_user_record) %] \& [% user.name %] \& [% END %] .Ve .PP The \f(CW\*(C`NEXT\*(C'\fR directive can be used to start the next iteration of a \&\f(CW\*(C`WHILE\*(C'\fR loop and \f(CW\*(C`BREAK\*(C'\fR can be used to exit the loop, both as per \f(CW\*(C`FOREACH\*(C'\fR. .PP The Template Toolkit uses a failsafe counter to prevent runaway \f(CW\*(C`WHILE\*(C'\fR loops which would otherwise never terminate. If the loop exceeds 1000 iterations then an \f(CW\*(C`undef\*(C'\fR exception will be thrown, reporting the error: .PP .Vb 1 \& WHILE loop terminated (> 1000 iterations) .Ve .PP The \f(CW$Template::Directive::WHILE_MAX\fR variable controls this behaviour and can be set to a higher value if necessary. .SH "Filters, Plugins, Macros and Perl" .IX Header "Filters, Plugins, Macros and Perl" .SS "\s-1FILTER\s0" .IX Subsection "FILTER" The \f(CW\*(C`FILTER\*(C'\fR directive can be used to post-process the output of a block. A number of standard filters are provided with the Template Toolkit. The \f(CW\*(C`html\*(C'\fR filter, for example, escapes the '<', '>' and '&' characters to prevent them from being interpreted as \s-1HTML\s0 tags or entity reference markers. .PP .Vb 4 \& [% FILTER html %] \& HTML text may have < and > characters embedded \& which you want converted to the correct HTML entities. \& [% END %] .Ve .PP output: .PP .Vb 2 \& HTML text may have < and > characters embedded \& which you want converted to the correct HTML entities. .Ve .PP The \f(CW\*(C`FILTER\*(C'\fR directive can also follow various other non-block directives. For example: .PP .Vb 1 \& [% INCLUDE mytext FILTER html %] .Ve .PP The \f(CW\*(C`|\*(C'\fR character can also be used as an alias for \f(CW\*(C`FILTER\*(C'\fR. .PP .Vb 1 \& [% INCLUDE mytext | html %] .Ve .PP Multiple filters can be chained together and will be called in sequence. .PP .Vb 1 \& [% INCLUDE mytext FILTER html FILTER html_para %] .Ve .PP or .PP .Vb 1 \& [% INCLUDE mytext | html | html_para %] .Ve .PP Filters come in two flavours, known as 'static' or 'dynamic'. A static filter is a simple subroutine which accepts a text string as the only argument and returns the modified text. The \f(CW\*(C`html\*(C'\fR filter is an example of a static filter, implemented as: .PP .Vb 9 \& sub html_filter { \& my $text = shift; \& for ($text) { \& s/&/&/g; \& s/</</g; \& s/>/>/g; \& } \& return $text; \& } .Ve .PP Dynamic filters can accept arguments which are specified when the filter is called from a template. The \f(CW\*(C`repeat\*(C'\fR filter is such an example, accepting a numerical argument which specifies the number of times that the input text should be repeated. .PP .Vb 1 \& [% FILTER repeat(3) %]blah [% END %] .Ve .PP output: .PP .Vb 1 \& blah blah blah .Ve .PP These are implemented as filter 'factories'. The factory subroutine is passed a reference to the current Template::Context object along with any additional arguments specified. It should then return a subroutine reference (e.g. a closure) which implements the filter. The \f(CW\*(C`repeat\*(C'\fR filter factory is implemented like this: .PP .Vb 3 \& sub repeat_filter_factory { \& my ($context, $iter) = @_; \& $iter = 1 unless defined $iter; \& \& return sub { \& my $text = shift; \& $text = \*(Aq\*(Aq unless defined $text; \& return join(\*(Aq\en\*(Aq, $text) x $iter; \& } \& } .Ve .PP The \f(CW\*(C`FILTERS\*(C'\fR option, described in Template::Manual::Config, allows custom filters to be defined when a Template object is instantiated. The \&\fIdefine_filter()\fR method allows further filters to be defined at any time. .PP When using a filter, it is possible to assign an alias to it for further use. This is most useful for dynamic filters that you want to re-use with the same configuration. .PP .Vb 3 \& [% FILTER echo = repeat(2) %] \& Is there anybody out there? \& [% END %] \& \& [% FILTER echo %] \& Mother, should I build a wall? \& [% END %] .Ve .PP Output: .PP .Vb 2 \& Is there anybody out there? \& Is there anybody out there? \& \& Mother, should I build a wall? \& Mother, should I build a wall? .Ve .PP The \f(CW\*(C`FILTER\*(C'\fR directive automatically quotes the name of the filter. As with \f(CW\*(C`INCLUDE\*(C'\fR et al, you can use a variable to provide the name of the filter, prefixed by \f(CW\*(C`$\*(C'\fR. .PP .Vb 4 \& [% myfilter = \*(Aqhtml\*(Aq %] \& [% FILTER $myfilter %] # same as [% FILTER html %] \& ... \& [% END %] .Ve .PP A template variable can also be used to define a static filter subroutine. However, the Template Toolkit will automatically call any subroutine bound to a variable and use the value returned. Thus, the above example could be implemented as: .PP .Vb 3 \& my $vars = { \& myfilter => sub { return \*(Aqhtml\*(Aq }, \& }; .Ve .PP template: .PP .Vb 3 \& [% FILTER $myfilter %] # same as [% FILTER html %] \& ... \& [% END %] .Ve .PP To define a template variable that evaluates to a subroutine reference that can be used by the \f(CW\*(C`FILTER\*(C'\fR directive, you should create a subroutine that, when called automatically by the Template Toolkit, returns another subroutine reference which can then be used to perform the filter operation. Note that only static filters can be implemented in this way. .PP .Vb 3 \& my $vars = { \& myfilter => sub { \e&my_filter_sub }, \& }; \& \& sub my_filter_sub { \& my $text = shift; \& # do something \& return $text; \& } .Ve .PP template: .PP .Vb 3 \& [% FILTER $myfilter %] \& ... \& [% END %] .Ve .PP Alternately, you can bless a subroutine reference into a class (any class will do) to fool the Template Toolkit into thinking it's an object rather than a subroutine. This will then bypass the automatic \&\*(L"call-a-subroutine-to-return-a-value\*(R" magic. .PP .Vb 3 \& my $vars = { \& myfilter => bless(\e&my_filter_sub, \*(Aqanything_you_like\*(Aq), \& }; .Ve .PP template: .PP .Vb 3 \& [% FILTER $myfilter %] \& ... \& [% END %] .Ve .PP Filters bound to template variables remain local to the variable context in which they are defined. That is, if you define a filter in a \f(CW\*(C`PERL\*(C'\fR block within a template that is loaded via \f(CW\*(C`INCLUDE\*(C'\fR, then the filter definition will only exist until the end of that template when the stash is delocalised, restoring the previous variable state. If you want to define a filter which persists for the lifetime of the processor, or define additional dynamic filter factories, then you can call the \&\fIdefine_filter()\fR method on the current Template::Context object. .PP See Template::Manual::Filters for a complete list of available filters, their descriptions and examples of use. .SS "\s-1USE\s0" .IX Subsection "USE" The \f(CW\*(C`USE\*(C'\fR directive can be used to load and initialise \*(L"plugin\*(R" extension modules. .PP .Vb 1 \& [% USE myplugin %] .Ve .PP A plugin is a regular Perl module that conforms to a particular object-oriented interface, allowing it to be loaded into and used automatically by the Template Toolkit. For details of this interface and information on writing plugins, consult Template::Plugin. .PP A number of standard plugins are included with the Template Toolkit (see below and Template::Manual::Plugins). The names of these standard plugins are case insensitive. .PP .Vb 3 \& [% USE CGI %] # => Template::Plugin::CGI \& [% USE Cgi %] # => Template::Plugin::CGI \& [% USE cgi %] # => Template::Plugin::CGI .Ve .PP You can also define further plugins using the \f(CW\*(C`PLUGINS\*(C'\fR option. .PP .Vb 6 \& my $tt = Template\->new({ \& PLUGINS => { \& foo => \*(AqMy::Plugin::Foo\*(Aq, \& bar => \*(AqMy::Plugin::Bar\*(Aq, \& }, \& }); .Ve .PP The recommended convention is to specify these plugin names in lower case. The Template Toolkit first looks for an exact case-sensitive match and then tries the lower case conversion of the name specified. .PP .Vb 1 \& [% USE Foo %] # look for \*(AqFoo\*(Aq then \*(Aqfoo\*(Aq .Ve .PP If you define all your \f(CW\*(C`PLUGINS\*(C'\fR with lower case names then they will be located regardless of how the user specifies the name in the \f(CW\*(C`USE\*(C'\fR directive. If, on the other hand, you define your \f(CW\*(C`PLUGINS\*(C'\fR with upper or mixed case names then the name specified in the \f(CW\*(C`USE\*(C'\fR directive must match the case exactly. .PP If the plugin isn't defined in either the standard plugins (\f(CW$Template::Plugins::STD_PLUGINS\fR) or via the \f(CW\*(C`PLUGINS\*(C'\fR option, then the \f(CW\*(C`PLUGIN_BASE\*(C'\fR is searched. .PP In this case the plugin name \fIis\fR case-sensitive. It is appended to each of the \f(CW\*(C`PLUGIN_BASE\*(C'\fR module namespaces in turn (default: \&\f(CW\*(C`Template::Plugin\*(C'\fR) to construct a full module name which it attempts to locate and load. Any periods, '\f(CW\*(C`.\*(C'\fR', in the name will be converted to '\f(CW\*(C`::\*(C'\fR'. .PP .Vb 2 \& [% USE MyPlugin %] # => Template::Plugin::MyPlugin \& [% USE Foo.Bar %] # => Template::Plugin::Foo::Bar .Ve .PP The \f(CW\*(C`LOAD_PERL\*(C'\fR option (disabled by default) provides a further way by which external Perl modules may be loaded. If a regular Perl module (i.e. not a \f(CW\*(C`Template::Plugin::*\*(C'\fR or other module relative to some \&\f(CW\*(C`PLUGIN_BASE\*(C'\fR) supports an object-oriented interface and a \f(CW\*(C`new()\*(C'\fR constructor then it can be loaded and instantiated automatically. The following trivial example shows how the IO::File module might be used. .PP .Vb 1 \& [% USE file = IO.File(\*(Aq/tmp/mydata\*(Aq) %] \& \& [% WHILE (line = file.getline) %] \& <!\-\- [% line %] \-\-> \& [% END %] .Ve .PP Any additional parameters supplied in parenthesis after the plugin name will be also be passed to the \f(CW\*(C`new()\*(C'\fR constructor. A reference to the current Template::Context object is passed as the first parameter. .PP .Vb 1 \& [% USE MyPlugin(\*(Aqfoo\*(Aq, 123) %] .Ve .PP equivalent to: .PP .Vb 1 \& Template::Plugin::MyPlugin\->new($context, \*(Aqfoo\*(Aq, 123); .Ve .PP The only exception to this is when a module is loaded via the \&\f(CW\*(C`LOAD_PERL\*(C'\fR option. In this case the \f(CW$context\fR reference is \fInot\fR passed to the \f(CW\*(C`new()\*(C'\fR constructor. This is based on the assumption that the module is a regular Perl module rather than a Template Toolkit plugin so isn't expecting a context reference and wouldn't know what to do with it anyway. .PP Named parameters may also be specified. These are collated into a hash which is passed by reference as the last parameter to the constructor, as per the general code calling interface. .PP .Vb 1 \& [% USE url(\*(Aq/cgi\-bin/foo\*(Aq, mode=\*(Aqsubmit\*(Aq, debug=1) %] .Ve .PP equivalent to: .PP .Vb 5 \& Template::Plugin::URL\->new( \& $context, \& \*(Aq/cgi\-bin/foo\*(Aq \& { mode => \*(Aqsubmit\*(Aq, debug => 1 } \& ); .Ve .PP The plugin may represent any data type; a simple variable, hash, list or code reference, but in the general case it will be an object reference. Methods can be called on the object (or the relevant members of the specific data type) in the usual way: .PP .Vb 1 \& [% USE table(mydata, rows=3) %] \& \& [% FOREACH row IN table.rows %] \& <tr> \& [% FOREACH item IN row %] \& <td>[% item %]</td> \& [% END %] \& </tr> \& [% END %] .Ve .PP An alternative name may be provided for the plugin by which it can be referenced: .PP .Vb 1 \& [% USE scores = table(myscores, cols=5) %] \& \& [% FOREACH row IN scores.rows %] \& ... \& [% END %] .Ve .PP You can use this approach to create multiple plugin objects with different configurations. This example shows how the format plugin is used to create sub-routines bound to variables for formatting text as per \f(CW\*(C`printf()\*(C'\fR. .PP .Vb 4 \& [% USE bold = format(\*(Aq<b>%s</b>\*(Aq) %] \& [% USE ital = format(\*(Aq<i>%s</i>\*(Aq) %] \& [% bold(\*(AqThis is bold\*(Aq) %] \& [% ital(\*(AqThis is italic\*(Aq) %] .Ve .PP Output: .PP .Vb 2 \& <b>This is bold</b> \& <i>This is italic</i> .Ve .PP This next example shows how the \s-1URL\s0 plugin can be used to build dynamic URLs from a base part and optional query parameters. .PP .Vb 3 \& [% USE mycgi = URL(\*(Aq/cgi\-bin/foo.pl\*(Aq, debug=1) %] \& <a href="[% mycgi %]">... \& <a href="[% mycgi(mode=\*(Aqsubmit\*(Aq) %]"... .Ve .PP Output: .PP .Vb 2 \& <a href="/cgi\-bin/foo.pl?debug=1">... \& <a href="/cgi\-bin/foo.pl?mode=submit&debug=1">... .Ve .PP The \s-1CGI\s0 plugin is an example of one which delegates to another Perl module. In this case, to Lincoln Stein's \f(CW\*(C`CGI\*(C'\fR module. All of the methods provided by the \f(CW\*(C`CGI\*(C'\fR module are available via the plugin. .PP .Vb 8 \& [% USE CGI; \& CGI.start_form; \& CGI.checkbox_group( name = \*(Aqcolours\*(Aq, \& values = [ \*(Aqred\*(Aq \*(Aqgreen\*(Aq \*(Aqblue\*(Aq ] ); \& CGI.popup_menu( name = \*(Aqitems\*(Aq, \& values = [ \*(Aqfoo\*(Aq \*(Aqbar\*(Aq \*(Aqbaz\*(Aq ] ); \& CGI.end_form \& %] .Ve .PP See Template::Manual::Plugins for more information on the plugins distributed with the toolkit or available from \s-1CPAN.\s0 .SS "\s-1MACRO\s0" .IX Subsection "MACRO" The \f(CW\*(C`MACRO\*(C'\fR directive allows you to define a directive or directive block which is then evaluated each time the macro is called. .PP .Vb 1 \& [% MACRO header INCLUDE header %] .Ve .PP Calling the macro as: .PP .Vb 1 \& [% header %] .Ve .PP is then equivalent to: .PP .Vb 1 \& [% INCLUDE header %] .Ve .PP Macros can be passed named parameters when called. These values remain local to the macro. .PP .Vb 1 \& [% header(title=\*(AqHello World\*(Aq) %] .Ve .PP equivalent to: .PP .Vb 1 \& [% INCLUDE header title=\*(AqHello World\*(Aq %] .Ve .PP A \f(CW\*(C`MACRO\*(C'\fR definition may include parameter names. Values passed to the macros are then mapped to these local variables. Other named parameters may follow these. .PP .Vb 3 \& [% MACRO header(title) INCLUDE header %] \& [% header(\*(AqHello World\*(Aq) %] \& [% header(\*(AqHello World\*(Aq, bgcol=\*(Aq#123456\*(Aq) %] .Ve .PP equivalent to: .PP .Vb 2 \& [% INCLUDE header title=\*(AqHello World\*(Aq %] \& [% INCLUDE header title=\*(AqHello World\*(Aq bgcol=\*(Aq#123456\*(Aq %] .Ve .PP Here's another example, defining a macro for display numbers in comma-delimited groups of 3, using the chunk and join virtual method. .PP .Vb 2 \& [% MACRO number(n) GET n.chunk(\-3).join(\*(Aq,\*(Aq) %] \& [% number(1234567) %] # 1,234,567 .Ve .PP A \f(CW\*(C`MACRO\*(C'\fR may precede any directive and must conform to the structure of the directive. .PP .Vb 5 \& [% MACRO header IF frames %] \& [% INCLUDE frames/header %] \& [% ELSE %] \& [% INCLUDE header %] \& [% END %] \& \& [% header %] .Ve .PP A \f(CW\*(C`MACRO\*(C'\fR may also be defined as an anonymous \f(CW\*(C`BLOCK\*(C'\fR. The block will be evaluated each time the macro is called. .PP .Vb 3 \& [% MACRO header BLOCK %] \& ...content... \& [% END %] \& \& [% header %] .Ve .PP If you've got the \f(CW\*(C`EVAL_PERL\*(C'\fR option set, then you can even define a \&\f(CW\*(C`MACRO\*(C'\fR as a \f(CW\*(C`PERL\*(C'\fR block (see below): .PP .Vb 4 \& [% MACRO triple(n) PERL %] \& my $n = $stash\->get(\*(Aqn\*(Aq); \& print $n * 3; \& [% END \-%] .Ve .SS "\s-1PERL\s0" .IX Subsection "PERL" (for the advanced reader) .PP The \f(CW\*(C`PERL\*(C'\fR directive is used to mark the start of a block which contains Perl code for evaluation. The \f(CW\*(C`EVAL_PERL\*(C'\fR option must be enabled for Perl code to be evaluated or a \f(CW\*(C`perl\*(C'\fR exception will be thrown with the message '\f(CW\*(C`EVAL_PERL not set\*(C'\fR'. .PP Perl code is evaluated in the \f(CW\*(C`Template::Perl\*(C'\fR package. The \f(CW$context\fR package variable contains a reference to the current Template::Context object. This can be used to access the functionality of the Template Toolkit to process other templates, load plugins, filters, etc. See Template::Context for further details. .PP .Vb 3 \& [% PERL %] \& print $context\->include(\*(Aqmyfile\*(Aq); \& [% END %] .Ve .PP The \f(CW$stash\fR variable contains a reference to the top-level stash object which manages template variables. Through this, variable values can be retrieved and updated. See Template::Stash for further details. .PP .Vb 4 \& [% PERL %] \& $stash\->set(foo => \*(Aqbar\*(Aq); \& print "foo value: ", $stash\->get(\*(Aqfoo\*(Aq); \& [% END %] .Ve .PP Output: .PP .Vb 1 \& foo value: bar .Ve .PP Output is generated from the \f(CW\*(C`PERL\*(C'\fR block by calling \f(CW\*(C`print()\*(C'\fR. Note that the \f(CW\*(C`Template::Perl::PERLOUT\*(C'\fR handle is selected (tied to an output buffer) instead of \f(CW\*(C`STDOUT\*(C'\fR. .PP .Vb 6 \& [% PERL %] \& print "foo\en"; # OK \& print PERLOUT "bar\en"; # OK, same as above \& print Template::Perl::PERLOUT "baz\en"; # OK, same as above \& print STDOUT "qux\en"; # WRONG! \& [% END %] .Ve .PP The \f(CW\*(C`PERL\*(C'\fR block may contain other template directives. These are processed before the Perl code is evaluated. .PP .Vb 1 \& [% name = \*(AqFred Smith\*(Aq %] \& \& [% PERL %] \& print "[% name %]\en"; \& [% END %] .Ve .PP Thus, the Perl code in the above example is evaluated as: .PP .Vb 1 \& print "Fred Smith\en"; .Ve .PP Exceptions may be thrown from within \f(CW\*(C`PERL\*(C'\fR blocks using \f(CW\*(C`die()\*(C'\fR. They will be correctly caught by enclosing \f(CW\*(C`TRY\*(C'\fR blocks. .PP .Vb 7 \& [% TRY %] \& [% PERL %] \& die "nothing to live for\en"; \& [% END %] \& [% CATCH %] \& error: [% error.info %] \& [% END %] .Ve .PP output: error: nothing to live for .SS "\s-1RAWPERL\s0" .IX Subsection "RAWPERL" (for the very advanced reader) .PP The Template Toolkit parser reads a source template and generates the text of a Perl subroutine as output. It then uses \f(CW\*(C`eval()\*(C'\fR to evaluate it into a subroutine reference. This subroutine is then called to process the template, passing a reference to the current Template::Context object through which the functionality of the Template Toolkit can be accessed. The subroutine reference can be cached, allowing the template to be processed repeatedly without requiring any further parsing. .PP For example, a template such as: .PP .Vb 3 \& [% PROCESS header %] \& The [% animal %] sat on the [% location %] \& [% PROCESS footer %] .Ve .PP is converted into the following Perl subroutine definition: .PP .Vb 5 \& sub { \& my $context = shift; \& my $stash = $context\->stash; \& my $output = \*(Aq\*(Aq; \& my $error; \& \& eval { BLOCK: { \& $output .= $context\->process(\*(Aqheader\*(Aq); \& $output .= "The "; \& $output .= $stash\->get(\*(Aqanimal\*(Aq); \& $output .= " sat on the "; \& $output .= $stash\->get(\*(Aqlocation\*(Aq); \& $output .= $context\->process(\*(Aqfooter\*(Aq); \& $output .= "\en"; \& } }; \& if ($@) { \& $error = $context\->catch($@, \e$output); \& die $error unless $error\->type eq \*(Aqreturn\*(Aq; \& } \& \& return $output; \& } .Ve .PP To examine the Perl code generated, such as in the above example, set the \f(CW$Template::Parser::DEBUG\fR package variable to any true value. You can also set the \f(CW$Template::Directive::PRETTY\fR variable true to have the code formatted in a readable manner for human consumption. The source code for each generated template subroutine will be printed to \&\f(CW\*(C`STDERR\*(C'\fR on compilation (i.e. the first time a template is used). .PP .Vb 2 \& $Template::Parser::DEBUG = 1; \& $Template::Directive::PRETTY = 1; \& \& $template\->process($file, $vars) \& || die $template\->error(), "\en"; .Ve .PP The \f(CW\*(C`PERL\*(C'\fR ... \f(CW\*(C`END\*(C'\fR construct allows Perl code to be embedded into a template when the \f(CW\*(C`EVAL_PERL\*(C'\fR option is set. It is evaluated at \&\*(L"runtime\*(R" using \f(CW\*(C`eval()\*(C'\fR each time the template subroutine is called. This is inherently flexible, but not as efficient as it could be, especially in a persistent server environment where a template may be processed many times. .PP The \f(CW\*(C`RAWPERL\*(C'\fR directive allows you to write Perl code that is integrated directly into the generated Perl subroutine text. It is evaluated once at compile time and is stored in cached form as part of the compiled template subroutine. This makes \f(CW\*(C`RAWPERL\*(C'\fR blocks more efficient than \f(CW\*(C`PERL\*(C'\fR blocks. .PP The downside is that you must code much closer to the metal. For example, in a \&\f(CW\*(C`PERL\*(C'\fR block you can call \fIprint()\fR to generate some output. \f(CW\*(C`RAWPERL\*(C'\fR blocks don't afford such luxury. The code is inserted directly into the generated subroutine text and should conform to the convention of appending to the \f(CW$output\fR variable. .PP .Vb 1 \& [% PROCESS header %] \& \& [% RAWPERL %] \& $output .= "Some output\en"; \& ... \& $output .= "Some more output\en"; \& [% END %] .Ve .PP The critical section of the generated subroutine for this example would then look something like: .PP .Vb 10 \& ... \& eval { BLOCK: { \& $output .= $context\->process(\*(Aqheader\*(Aq); \& $output .= "\en"; \& $output .= "Some output\en"; \& ... \& $output .= "Some more output\en"; \& $output .= "\en"; \& } }; \& ... .Ve .PP As with \f(CW\*(C`PERL\*(C'\fR blocks, the \f(CW$context\fR and \&\f(CW$stash\fR references are pre-defined and available for use within \f(CW\*(C`RAWPERL\*(C'\fR code. .SH "Exception Handling and Flow Control" .IX Header "Exception Handling and Flow Control" .SS "\s-1TRY / THROW / CATCH / FINAL\s0" .IX Subsection "TRY / THROW / CATCH / FINAL" (more advanced material) .PP The Template Toolkit supports fully functional, nested exception handling. The \f(CW\*(C`TRY\*(C'\fR directive introduces an exception handling scope which continues until the matching \f(CW\*(C`END\*(C'\fR directive. Any errors that occur within that block will be caught and can be handled by one of the \f(CW\*(C`CATCH\*(C'\fR blocks defined. .PP .Vb 9 \& [% TRY %] \& ...blah...blah... \& [% CALL somecode %] \& ...etc... \& [% INCLUDE someblock %] \& ...and so on... \& [% CATCH %] \& An error occurred! \& [% END %] .Ve .PP Errors are raised as exceptions (objects of the Template::Exception class) which contain two fields: \f(CW\*(C`type\*(C'\fR and \f(CW\*(C`info\*(C'\fR. The exception \f(CW\*(C`type\*(C'\fR is used to indicate the kind of error that occurred. It is a simple text string which can contain letters, numbers, '\f(CW\*(C`_\*(C'\fR' or '\f(CW\*(C`.\*(C'\fR'. The \f(CW\*(C`info\*(C'\fR field contains an error message indicating what actually went wrong. Within a catch block, the exception object is aliased to the \f(CW\*(C`error\*(C'\fR variable. You can access the \f(CW\*(C`type\*(C'\fR and \f(CW\*(C`info\*(C'\fR fields directly. .PP .Vb 2 \& [% mydsn = \*(Aqdbi:MySQL:foobar\*(Aq %] \& ... \& \& [% TRY %] \& [% USE DBI(mydsn) %] \& [% CATCH %] \& ERROR! Type: [% error.type %] \& Info: [% error.info %] \& [% END %] .Ve .PP output (assuming a non-existent database called '\f(CW\*(C`foobar\*(C'\fR'): .PP .Vb 2 \& ERROR! Type: DBI \& Info: Unknown database "foobar" .Ve .PP The \f(CW\*(C`error\*(C'\fR variable can also be specified by itself and will return a string of the form "\f(CW\*(C`$type error \- $info\*(C'\fR". .PP .Vb 4 \& ... \& [% CATCH %] \& ERROR: [% error %] \& [% END %] .Ve .PP Output: .PP .Vb 1 \& ERROR: DBI error \- Unknown database "foobar" .Ve .PP Each \f(CW\*(C`CATCH\*(C'\fR block may be specified with a particular exception type denoting the kind of error that it should catch. Multiple \f(CW\*(C`CATCH\*(C'\fR blocks can be provided to handle different types of exception that may be thrown in the \f(CW\*(C`TRY\*(C'\fR block. A \f(CW\*(C`CATCH\*(C'\fR block specified without any type, as in the previous example, is a default handler which will catch any otherwise uncaught exceptions. This can also be specified as \&\f(CW\*(C`[% CATCH DEFAULT %]\*(C'\fR. .PP .Vb 11 \& [% TRY %] \& [% INCLUDE myfile %] \& [% USE DBI(mydsn) %] \& [% CALL somecode %] \& [% CATCH file %] \& File Error! [% error.info %] \& [% CATCH DBI %] \& [% INCLUDE database/error.html %] \& [% CATCH %] \& [% error %] \& [% END %] .Ve .PP Remember that you can specify multiple directives within a single tag, each delimited by '\f(CW\*(C`;\*(C'\fR'. So the above example can be written more concisely as: .PP .Vb 12 \& [% TRY; \& INCLUDE myfile; \& USE DBI(mydsn); \& CALL somecode; \& CATCH file; \& "File Error! $error.info"; \& CATCH DBI; \& INCLUDE database/error.html; \& CATCH; \& error; \& END \& %] .Ve .PP The \f(CW\*(C`DBI\*(C'\fR plugin throws exceptions of the \f(CW\*(C`DBI\*(C'\fR type (in case that wasn't already obvious). The other specific exception caught here is of the \f(CW\*(C`file\*(C'\fR type. .PP A \f(CW\*(C`file\*(C'\fR exception is automatically thrown by the Template Toolkit when it can't find a file, or fails to load, parse or process a file that has been requested by an \f(CW\*(C`INCLUDE\*(C'\fR, \f(CW\*(C`PROCESS\*(C'\fR, \f(CW\*(C`INSERT\*(C'\fR or \f(CW\*(C`WRAPPER\*(C'\fR directive. If \f(CW\*(C`myfile\*(C'\fR can't be found in the example above, the \f(CW\*(C`[% INCLUDE myfile %]\*(C'\fR directive will raise a \f(CW\*(C`file\*(C'\fR exception which is then caught by the \&\f(CW\*(C`[% CATCH file %]\*(C'\fR block. The output generated would be: .PP .Vb 1 \& File Error! myfile: not found .Ve .PP Note that the \f(CW\*(C`DEFAULT\*(C'\fR option (disabled by default) allows you to specify a default file to be used any time a template file can't be found. This will prevent file exceptions from ever being raised when a non-existent file is requested (unless, of course, the \f(CW\*(C`DEFAULT\*(C'\fR file your specify doesn't exist). Errors encountered once the file has been found (i.e. read error, parse error) will be raised as file exceptions as per usual. .PP Uncaught exceptions (i.e. if the \f(CW\*(C`TRY\*(C'\fR block doesn't have a type specific or default \f(CW\*(C`CATCH\*(C'\fR handler) may be caught by enclosing \f(CW\*(C`TRY\*(C'\fR blocks which can be nested indefinitely across multiple templates. If the error isn't caught at any level then processing will stop and the Template \&\fIprocess()\fR method will return a false value to the caller. The relevant Template::Exception object can be retrieved by calling the \fIerror()\fR method. .PP .Vb 11 \& [% TRY %] \& ... \& [% TRY %] \& [% INCLUDE $user.header %] \& [% CATCH file %] \& [% INCLUDE header %] \& [% END %] \& ... \& [% CATCH DBI %] \& [% INCLUDE database/error.html %] \& [% END %] .Ve .PP In this example, the inner \f(CW\*(C`TRY\*(C'\fR block is used to ensure that the first \&\f(CW\*(C`INCLUDE\*(C'\fR directive works as expected. We're using a variable to provide the name of the template we want to include, \f(CW\*(C`user.header\*(C'\fR, and it's possible this contains the name of a non-existent template, or perhaps one containing invalid template directives. If the \f(CW\*(C`INCLUDE\*(C'\fR fails with a \f(CW\*(C`file\*(C'\fR error then we \f(CW\*(C`CATCH\*(C'\fR it in the inner block and \f(CW\*(C`INCLUDE\*(C'\fR the default \f(CW\*(C`header\*(C'\fR file instead. Any \f(CW\*(C`DBI\*(C'\fR errors that occur within the scope of the outer \f(CW\*(C`TRY\*(C'\fR block will be caught in the relevant \f(CW\*(C`CATCH\*(C'\fR block, causing the \f(CW\*(C`database/error.html\*(C'\fR template to be processed. Note that included templates inherit all currently defined template variable so these error files can quite happily access the <error> variable to retrieve information about the currently caught exception. For example, the \f(CW\*(C`database/error.html\*(C'\fR template might look like this: .PP .Vb 2 \& <h2>Database Error</h2> \& A database error has occurred: [% error.info %] .Ve .PP You can also specify a \f(CW\*(C`FINAL\*(C'\fR block. This is always processed regardless of the outcome of the \f(CW\*(C`TRY\*(C'\fR and/or \f(CW\*(C`CATCH\*(C'\fR blocks. If an exception is uncaught then the \f(CW\*(C`FINAL\*(C'\fR block is processed before jumping to the enclosing block or returning to the caller. .PP .Vb 9 \& [% TRY %] \& ... \& [% CATCH this %] \& ... \& [% CATCH that %] \& ... \& [% FINAL %] \& All done! \& [% END %] .Ve .PP The output from the \f(CW\*(C`TRY\*(C'\fR block is left intact up to the point where an exception occurs. For example, this template: .PP .Vb 7 \& [% TRY %] \& This gets printed \& [% THROW food \*(Aqcarrots\*(Aq %] \& This doesn\*(Aqt \& [% CATCH food %] \& culinary delights: [% error.info %] \& [% END %] .Ve .PP generates the following output: .PP .Vb 2 \& This gets printed \& culinary delights: carrots .Ve .PP The \f(CW\*(C`CLEAR\*(C'\fR directive can be used in a \f(CW\*(C`CATCH\*(C'\fR or \f(CW\*(C`FINAL\*(C'\fR block to clear any output created in the \f(CW\*(C`TRY\*(C'\fR block. .PP .Vb 8 \& [% TRY %] \& This gets printed \& [% THROW food \*(Aqcarrots\*(Aq %] \& This doesn\*(Aqt \& [% CATCH food %] \& [% CLEAR %] \& culinary delights: [% error.info %] \& [% END %] .Ve .PP Output: .PP .Vb 1 \& culinary delights: carrots .Ve .PP Exception types are hierarchical, with each level being separated by the familiar dot operator. A \f(CW\*(C`DBI.connect\*(C'\fR exception is a more specific kind of \f(CW\*(C`DBI\*(C'\fR error. Similarly, an \f(CW\*(C`example.error.barf\*(C'\fR is a more specific kind of \f(CW\*(C`example.error\*(C'\fR type which itself is also a \&\f(CW\*(C`example\*(C'\fR error. .PP A \f(CW\*(C`CATCH\*(C'\fR handler that specifies a general exception type (such as \f(CW\*(C`DBI\*(C'\fR or \f(CW\*(C`example.error\*(C'\fR) will also catch more specific types that have the same prefix as long as a more specific handler isn't defined. Note that the order in which \f(CW\*(C`CATCH\*(C'\fR handlers are defined is irrelevant; a more specific handler will always catch an exception in preference to a more generic or default one. .PP .Vb 10 \& [% TRY %] \& ... \& [% CATCH DBI ; \& INCLUDE database/error.html ; \& CATCH DBI.connect ; \& INCLUDE database/connect.html ; \& CATCH ; \& INCLUDE error.html ; \& END \& %] .Ve .PP In this example, a \f(CW\*(C`DBI.connect\*(C'\fR error has it's own handler, a more general \&\f(CW\*(C`DBI\*(C'\fR block is used for all other \f(CW\*(C`DBI\*(C'\fR or \f(CW\*(C`DBI.*\*(C'\fR errors and a default handler catches everything else. .PP Exceptions can be raised in a template using the \f(CW\*(C`THROW\*(C'\fR directive. The first parameter is the exception type which doesn't need to be quoted (but can be, it's the same as \f(CW\*(C`INCLUDE\*(C'\fR) followed by the relevant error message which can be any regular value such as a quoted string, variable, etc. .PP .Vb 3 \& [% THROW food "Missing ingredients: $recipe.error" %] \& [% THROW user.login \*(Aqno user id: please login\*(Aq %] \& [% THROW $myerror.type "My Error: $myerror.info" %] .Ve .PP It's also possible to specify additional positional or named parameters to the \f(CW\*(C`THROW\*(C'\fR directive if you want to pass more than just a simple message back as the error info field. .PP .Vb 1 \& [% THROW food \*(Aqeggs\*(Aq \*(Aqflour\*(Aq msg=\*(AqMissing Ingredients\*(Aq %] .Ve .PP In this case, the error \f(CW\*(C`info\*(C'\fR field will be a hash array containing the named arguments and an \f(CW\*(C`args\*(C'\fR item which contains a list of the positional arguments. .PP .Vb 5 \& type => \*(Aqfood\*(Aq, \& info => { \& msg => \*(AqMissing Ingredients\*(Aq, \& args => [\*(Aqeggs\*(Aq, \*(Aqflour\*(Aq], \& } .Ve .PP In addition to specifying individual positional arguments as \&\f(CW\*(C`[% error.info.args.n %]\*(C'\fR, the \f(CW\*(C`info\*(C'\fR hash contains keys directly pointing to the positional arguments, as a convenient shortcut. .PP .Vb 1 \& [% error.info.0 %] # same as [% error.info.args.0 %] .Ve .PP Exceptions can also be thrown from Perl code which you've bound to template variables, or defined as a plugin or other extension. To raise an exception, call \f(CW\*(C`die()\*(C'\fR passing a reference to a Template::Exception object as the argument. This will then be caught by any enclosing \f(CW\*(C`TRY\*(C'\fR blocks from where the code was called. .PP .Vb 9 \& use Template::Exception; \& ... \& my $vars = { \& foo => sub { \& # ... do something ... \& die Template::Exception\->new(\*(Aqmyerr.naughty\*(Aq, \& \*(AqBad, bad error\*(Aq); \& }, \& }; .Ve .PP Template: .PP .Vb 6 \& [% TRY %] \& [% foo %] \& [% CATCH myerr ; \& "Error: $error" ; \& END \& %] .Ve .PP Output: .PP .Vb 1 \& Error: myerr.naughty error \- Bad, bad error .Ve .PP The \f(CW\*(C`info\*(C'\fR field can also be a reference to another object or data structure, if required. .PP .Vb 4 \& die Template::Exception\->new(\*(Aqmyerror\*(Aq, { \& module => \*(Aqfoo.pl\*(Aq, \& errors => [ \*(Aqbad permissions\*(Aq, \*(Aqnaughty boy\*(Aq ], \& }); .Ve .PP Later, in a template: .PP .Vb 8 \& [% TRY %] \& ... \& [% CATCH myerror %] \& [% error.info.errors.size or \*(Aqno\*(Aq; \& error.info.errors.size == 1 ? \*(Aq error\*(Aq : \*(Aq errors\*(Aq %] \& in [% error.info.module %]: \& [% error.info.errors.join(\*(Aq, \*(Aq) %]. \& [% END %] .Ve .PP Generating the output: .PP .Vb 2 \& 2 errors in foo.pl: \& bad permissions, naughty boy. .Ve .PP You can also call \f(CW\*(C`die()\*(C'\fR with a single string, as is common in much existing Perl code. This will automatically be converted to an exception of the '\f(CW\*(C`undef\*(C'\fR' type (that's the literal string '\f(CW\*(C`undef\*(C'\fR', not the undefined value). If the string isn't terminated with a newline then Perl will append the familiar \f(CW" at $file line $line"\fR message. .PP .Vb 4 \& sub foo { \& # ... do something ... \& die "I\*(Aqm sorry, Dave, I can\*(Aqt do that\en"; \& } .Ve .PP If you're writing a plugin, or some extension code that has the current Template::Context in scope (you can safely skip this section if this means nothing to you) then you can also raise an exception by calling the context \&\fIthrow()\fR method. You can pass it an Template::Exception object reference, a pair of \f(CW\*(C`($type, $info)\*(C'\fR parameters or just an \f(CW$info\fR string to create an exception of '\f(CW\*(C`undef\*(C'\fR' type. .PP .Vb 3 \& $context\->throw($e); # exception object \& $context\->throw(\*(AqDenied\*(Aq); # \*(Aqundef\*(Aq type \& $context\->throw(\*(Aquser.passwd\*(Aq, \*(AqBad Password\*(Aq); .Ve .SS "\s-1NEXT\s0" .IX Subsection "NEXT" The \f(CW\*(C`NEXT\*(C'\fR directive can be used to start the next iteration of a \f(CW\*(C`FOREACH\*(C'\fR or \f(CW\*(C`WHILE\*(C'\fR loop. .PP .Vb 4 \& [% FOREACH user IN users %] \& [% NEXT IF user.isguest %] \& Name: [% user.name %] Email: [% user.email %] \& [% END %] .Ve .SS "\s-1LAST\s0" .IX Subsection "LAST" The \f(CW\*(C`LAST\*(C'\fR directive can be used to prematurely exit a \f(CW\*(C`FOREACH\*(C'\fR or \f(CW\*(C`WHILE\*(C'\fR loop. .PP .Vb 4 \& [% FOREACH user IN users %] \& Name: [% user.name %] Email: [% user.email %] \& [% LAST IF some.condition %] \& [% END %] .Ve .PP \&\f(CW\*(C`BREAK\*(C'\fR can also be used as an alias for \f(CW\*(C`LAST\*(C'\fR. .SS "\s-1RETURN\s0" .IX Subsection "RETURN" The \f(CW\*(C`RETURN\*(C'\fR directive can be used to stop processing the current template and return to the template from which it was called, resuming processing at the point immediately after the \f(CW\*(C`INCLUDE\*(C'\fR, \f(CW\*(C`PROCESS\*(C'\fR or \f(CW\*(C`WRAPPER\*(C'\fR directive. If there is no enclosing template then the Template \&\fIprocess()\fR method will return to the calling code with a true value. .PP .Vb 3 \& Before \& [% INCLUDE half_wit %] \& After \& \& [% BLOCK half_wit %] \& This is just half... \& [% RETURN %] \& ...a complete block \& [% END %] .Ve .PP Output: .PP .Vb 3 \& Before \& This is just half... \& After .Ve .SS "\s-1STOP\s0" .IX Subsection "STOP" The \f(CW\*(C`STOP\*(C'\fR directive can be used to indicate that the processor should stop gracefully without processing any more of the template document. This is a planned stop and the Template \fIprocess()\fR method will return a \fBtrue\fR value to the caller. This indicates that the template was processed successfully according to the directives within it. .PP .Vb 4 \& [% IF something.terrible.happened %] \& [% INCLUDE fatal/error.html %] \& [% STOP %] \& [% END %] \& \& [% TRY %] \& [% USE DBI(mydsn) %] \& ... \& [% CATCH DBI.connect %] \& <h1>Cannot connect to the database: [% error.info %]</h1> \& <p> \& We apologise for the inconvenience. \& </p> \& [% INCLUDE footer %] \& [% STOP %] \& [% END %] .Ve .SS "\s-1CLEAR\s0" .IX Subsection "CLEAR" The \f(CW\*(C`CLEAR\*(C'\fR directive can be used to clear the output buffer for the current enclosing block. It is most commonly used to clear the output generated from a \f(CW\*(C`TRY\*(C'\fR block up to the point where the error occurred. .PP .Vb 8 \& [% TRY %] \& blah blah blah # this is normally left intact \& [% THROW some \*(Aqerror\*(Aq %] # up to the point of error \& ... \& [% CATCH %] \& [% CLEAR %] # clear the TRY output \& [% error %] # print error string \& [% END %] .Ve .SH "Miscellaneous" .IX Header "Miscellaneous" .SS "\s-1META\s0" .IX Subsection "META" The \f(CW\*(C`META\*(C'\fR directive allows simple metadata items to be defined within a template. These are evaluated when the template is parsed and as such may only contain simple values (e.g. it's not possible to interpolate other variables values into \f(CW\*(C`META\*(C'\fR variables). .PP .Vb 5 \& [% META \& title = \*(AqThe Cat in the Hat\*(Aq \& author = \*(AqDr. Seuss\*(Aq \& version = 1.23 \& %] .Ve .PP The \f(CW\*(C`template\*(C'\fR variable contains a reference to the main template being processed. These metadata items may be retrieved as attributes of the template. .PP .Vb 2 \& <h1>[% template.title %]</h1> \& <h2>[% template.author %]</h2> .Ve .PP The \f(CW\*(C`name\*(C'\fR and \f(CW\*(C`modtime\*(C'\fR metadata items are automatically defined for each template to contain its name and modification time in seconds since the epoch. .PP .Vb 4 \& [% USE date %] # use Date plugin to format time \& ... \& [% template.name %] last modified \& at [% date.format(template.modtime) %] .Ve .PP The \f(CW\*(C`PRE_PROCESS\*(C'\fR and \f(CW\*(C`POST_PROCESS\*(C'\fR options allow common headers and footers to be added to all templates. The \f(CW\*(C`template\*(C'\fR reference is correctly defined when these templates are processed, allowing headers and footers to reference metadata items from the main template. .PP .Vb 4 \& $template = Template\->new({ \& PRE_PROCESS => \*(Aqheader\*(Aq, \& POST_PROCESS => \*(Aqfooter\*(Aq, \& }); \& \& $template\->process(\*(Aqcat_in_hat\*(Aq); .Ve .PP header: .PP .Vb 5 \& <html> \& <head> \& <title>[% template.title %]</title> \& </head> \& <body> .Ve .PP cat_in_hat: .PP .Vb 6 \& [% META \& title = \*(AqThe Cat in the Hat\*(Aq \& author = \*(AqDr. Seuss\*(Aq \& version = 1.23 \& year = 2000 \& %] \& \& The cat in the hat sat on the mat. .Ve .PP footer: .PP .Vb 4 \& <hr> \& © [% template.year %] [% template.author %] \& </body> \& </html> .Ve .PP The output generated from the above example is: .PP .Vb 10 \& <html> \& <head> \& <title>The Cat in the Hat</title> \& </head> \& <body> \& The cat in the hat sat on the mat. \& <hr> \& © 2000 Dr. Seuss \& </body> \& </html> .Ve .SS "\s-1TAGS\s0" .IX Subsection "TAGS" The \f(CW\*(C`TAGS\*(C'\fR directive can be used to set the \f(CW\*(C`START_TAG\*(C'\fR and \f(CW\*(C`END_TAG\*(C'\fR values on a per-template file basis. .PP .Vb 1 \& [% TAGS <+ +> %] \& \& <+ INCLUDE header +> .Ve .PP The \s-1TAGS\s0 directive may also be used to set a named \f(CW\*(C`TAG_STYLE\*(C'\fR .PP .Vb 2 \& [% TAGS html %] \& <!\-\- INCLUDE header \-\-> .Ve .PP See the \s-1TAGS\s0 and \s-1TAG_STYLE\s0 configuration options for further details. .SS "\s-1DEBUG\s0" .IX Subsection "DEBUG" The \f(CW\*(C`DEBUG\*(C'\fR directive can be used to enable or disable directive debug messages within a template. The \f(CW\*(C`DEBUG\*(C'\fR configuration option must be set to include \f(CW\*(C`DEBUG_DIRS\*(C'\fR for the \f(CW\*(C`DEBUG\*(C'\fR directives to have any effect. If \f(CW\*(C`DEBUG_DIRS\*(C'\fR is not set then the parser will automatically ignore and remove any \f(CW\*(C`DEBUG\*(C'\fR directives. .PP The \f(CW\*(C`DEBUG\*(C'\fR directive can be used with an \f(CW\*(C`on\*(C'\fR or \f(CW\*(C`off\*(C'\fR parameter to enable or disable directive debugging messages from that point forward. When enabled, the output of each directive in the generated output will be prefixed by a comment indicate the file, line and original directive text. .PP .Vb 4 \& [% DEBUG on %] \& directive debugging is on (assuming DEBUG option is set true) \& [% DEBUG off %] \& directive debugging is off .Ve .PP The \f(CW\*(C`format\*(C'\fR parameter can be used to change the format of the debugging message. .PP .Vb 1 \& [% DEBUG format \*(Aq<!\-\- $file line $line : [% $text %] \-\->\*(Aq %] .Ve
Save
cmd:
run