This file is indexed.

/usr/share/perl5/Template/Alloy.pod is in libtemplate-alloy-perl 1.020-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
=head1 NAME

Template::Alloy - TT2/3, HT, HTE, Tmpl, and Velocity Engine

=head1 SYNOPSIS

=head2 Template::Toolkit style usage

    my $t = Template::Alloy->new(
        INCLUDE_PATH => ['/path/to/templates'],
    );

    my $swap = {
        key1 => 'val1',
        key2 => 'val2',
        code => sub { 42 },
        hash => {a => 'b'},
    };

    # print to STDOUT
    $t->process('my/template.tt', $swap)
        || die $t->error;

    # process into a variable
    my $out = '';
    $t->process('my/template.tt', $swap, \$out);

    ### Alloy uses the same syntax and configuration as Template::Toolkit


=head2 HTML::Template::Expr style usage

    my $t = Template::Alloy->new(
        filename => 'my/template.ht',
        path     => ['/path/to/templates'],
    );

    my $swap = {
        key1 => 'val1',
        key2 => 'val2',
        code => sub { 42 },
        hash => {a => 'b'},
    };

    $t->param($swap);

    # print to STDOUT (errors die)
    $t->output(print_to => \*STDOUT);

    # process into a variable
    my $out = $t->output;

    ### Alloy can also use the same syntax and configuration as HTML::Template

=head2 Text::Tmpl style usage

    my $t = Template::Alloy->new;

    my $swap = {
        key1 => 'val1',
        key2 => 'val2',
        code => sub { 42 },
        hash => {a => 'b'},
    };

    $t->set_delimiters('#[', ']#');
    $t->set_strip(0);
    $t->set_values($swap);
    $t->set_dir('/path/to/templates');

    my $out = $t->parse_file('my/template.tmpl');

    my $str = "Foo #[echo $key1]# Bar";
    my $out = $t->parse_string($str);


    ### Alloy uses the same syntax and configuration as Text::Tmpl

=head2 Velocity (VTL) style usage

    my $t = Template::Alloy->new;

    my $swap = {
        key1 => 'val1',
        key2 => 'val2',
        code => sub { 42 },
        hash => {a => 'b'},
    };

    my $out = $t->merge('my/template.vtl', $swap);

    my $str = "#set($foo 1 + 3) ($foo) ($bar) ($!baz)";
    my $out = $t->merge(\$str, $swap);

=head2 Javascript style usage (requires Template::Alloy::JS)

    my $t = Template::Alloy->new;

    my $swap = {
        key1 => 'val1',
        key2 => 'val2',
        code => sub { 42 },
        hash => {a => 'b'},
    };

    my $out = '';
    $t->process_js('my/template.jstem', $swap, \$out);

    my $str = "[% var foo = 1 + 3; write('(' + foo + ') (' + get('key1') + ')'); %]";
    my $out = '';
    $t->process_js(\$str, $swap, \$out);


=head1 DESCRIPTION

"An alloy is a homogeneous mixture of two or more elements"
(http://en.wikipedia.org/wiki/Alloy).

Template::Alloy represents the mixing of features and capabilities
from all of the major mini-language based template systems (support
for non-mini-language based systems will happen eventually).  With
Template::Alloy you can use your favorite template interface and syntax
and get features from each of the other major template systems.  And
Template::Alloy is fast - whether your using mod_perl, CGI, or running
from the commandline.  There is even Template::Alloy::JS for getting
a little more speed when that is necessary.

Template::Alloy happened by accident (accidentally on purpose).  The
Template::Alloy (Alloy hereafter) was originally a part of the CGI::Ex
suite that performed simple variable interpolation.  It used TT2 style
variables in TT2 style tags "[% foo.bar %]".  That was all the
original Template::Alloy did.  This was fine and dandy for a couple
of years.  In winter of 2005-2006 Alloy was revamped to add a few
features.  One thing led to another and soon Alloy provided for most of
the features of TT2 as well as some from TT3.  Template::Alloy now
provides a full-featured implementation of the Template::Toolkit language.

After a move to a new company that was using HTML::Template::Expr and
Text::Tmpl templates, support was investigated and interfaces for
HTML::Template, HTML::Template::Expr, Text::Tmpl, and Velocity (VTL)
were added.  All of the various engines offer the same features - each
using a different syntax and interface.

More recently, the Template::Alloy::JS capabilities were introduced
to bring Javascript templates to the server side (along with an increase
in speed if ran in persistent environments).

Template::Toolkit brought the most to the table.  HTML::Template
brought the LOOP directive.  HTML::Template::Expr brought more vmethods
and using vmethods as top level functions.  Text::Tmpl brought the
COMMENT directive and encouraged speed matching (Text::Tmpl is almost
entirely C based and is very fast).  The Velocity engine brought
AUTO_EVAL and SHOW_UNDEFINED_INTERP.

Most of the standard Template::Toolkit documentation covering
directives, variables, configuration, plugins, filters, syntax, and
vmethods should apply to Alloy just fine (This pod tries to explain
everything - but there is too much).  See L<Template::Alloy::TT> for
a listing of the differences between Alloy and TT.

Most of the standard HTML::Template and
HTML::Template::Expr documentation covering methods, variables,
expressions, and syntax will apply to Alloy just fine as well.

Most of the standard Text::Tmpl documentation applies, as does
the documentation covering Velocity (VTL).

So should you use Template::Alloy ?  Well, try it out.  It may
give you no visible improvement.  Or it could.

=head1 BACKEND

Template::Alloy uses a recursive regex based grammar (early versions
during the CGI::Ex::Template phase did not).  This allows for the
embedding of opening and closing tags inside other tags (as in [% a =
"[% 1 + 2 %]" ; a|eval %]).  The individual methods such as parse_expr
and play_expr may be used by external applications to add TT style
variable parsing to other applications.

The regex parser returns an AST (abstract syntax tree) of the text,
directives, variables, and expressions.  All of the different template
syntax options compile to the same AST format.  The AST is composed
only of scalars and arrayrefs and is suitable for sending to
JavaScript via JSON or sharing with other languages.  The parse_tree
method is used for returning this AST.

Once at the AST stage, there are two modes of operation.  Alloy can
either operate directly on the AST using the Play role, or it can
compile the AST to perl code via the Compile role, and then execute
the code.  To use the perl code route, you must set the COMPILE_PERL
flag to 1.  If you are running in a cached-in-memory environment such
as mod_perl, this is the fastest option.  If you are running in a
non-cached-in-memory environment, then using the Play role to run the
AST is generally faster.  The AST method is also more secure as cached
AST won't ever eval any "perl" (assuming PERL blocks are disabled -
which is the default).

=head1 ROLES

Template::Alloy has split out its functionality into discrete roles.
In Template::Toolkit, this functionality is split into separate
classes.  The roles in Template::Alloy simply add on more methods to
the main class.  When Perl 6 arrives, these roles will be translated
into true Roles.

The following is a list of roles used by Template::Alloy.

    Template::Alloy::Compile  - Compile-to-perl role
    Template::Alloy::HTE      - HTML::Template::Expr role
    Template::Alloy::Operator - Operator role
    Template::Alloy::Parse    - Parse-to-AST role
    Template::Alloy::Play     - Play-AST role
    Template::Alloy::Stream   - Stream output role
    Template::Alloy::Tmpl     - Text::Tmpl role
    Template::Alloy::TT       - Template::Toolkit role
    Template::Alloy::Velocity - Velocity role
    Template::Alloy::VMethod  - Virtual methods role

    Template::Alloy::JS       - Javascript functionality - available separately

Template::Alloy automatically loads the roles when they are needed or
requested - but not sooner (with the exception of the Operator role
and the VMethod role which are always needed and always loaded).  This
is good for a CGI environment.  In mod_perl you may want to preload a
role to make the most of shared memory.  You may do this by passing
either the role name or a method supplied by that role.

    # import roles necessary for running TT
    use Template::Alloy qw(Parse Play Compile TT);

    # import roles based on methods
    use Template::Alloy qw(parse_tree play_tree compile_tree process);

Note: importing roles by method names does not import them into
that namespace - it is autoloading the role and methods into the
Template::Alloy namespace.  To help make this more clear you may use
the following syntax as well.

    # import roles necessary for running TT
    use Template::Alloy load => qw(Parse Play Compile TT);

    # import roles based on methods
    use Template::Alloy load => qw(process parse_tree play_tree compile_tree);

    # import roles based on methods
    use Template::Alloy
        Parse => 1,
        Play => 1,
        Compile => 1,
        TT => 1;

Even with all roles loaded Template::Alloy is still relatively small.
You can load all of the roles (except the JS role) by passing "all" to
the use statement.

    use Template::Alloy 'all';

    # or
    use Template::Alloy load => 'all';

    # or
    use Template::Alloy all => 1;

As a final option, Template::Alloy also includes the ability to
stand-in for other template modules.  It is able to do this because it
supports the majority of the interface of the other template systems.
You can do this in the following way:

    use Template::Alloy qw(Text::Tmpl HTML::Template);

    # or
    use Template::Alloy load => qw(Text::Tmpl HTML::Template);

    # or
    use Template::Alloy
        'Text::Tmpl'     => 1,
        'HTML::Template' => 1;

Note that the use statement will die if any of the passed module names
are already loaded and not subclasses of Template::Alloy.  This will
avoid thinking that you are using Template::Alloy when you really aren't.
Using the 'all' option won't automatically do this - you must mention
the "stood-in" modules by name.

The following modules may be "stood-in" for:

    Template
    Text::Tmpl
    HTML::Template
    HTML::Template::Expr

This feature is intended to make using Template::Alloy with existing
code easier.  Most cases should work just fine.  Almost all syntax will
just work (except Alloy may make some things work that were previously
broken).  However Template::Alloy doesn't support 100% of the interface
of any of the template systems.  If you are using "features-on-the-edge"
then you may need to re-write portions of your code that interact with
the template system.

=head1 PUBLIC METHODS

The following section lists most of the publicly available methods.  Some less
commonly used public methods are listed later in this document.

=over 4

=item C<new>

    my $obj = Template::Alloy->new({
        INCLUDE_PATH => ['/my/path/to/content', '/my/path/to/content2'],
    });

Arguments may be passed as a hash or as a hashref.  Returns a Template::Alloy object.

There are currently no errors during Template::Alloy object creation.  If you are
using the HTML::Template interface, this is different behavior.  The document is
not parsed until the output or process methods are called.

=item C<process>

This is the TT interface for starting processing.  Any errors that result in the
template processing being stopped will be stored and available via the ->error method.

    my $t = Template::Alloy->new;
    $t->process($in, $swap, $out)
        || die $t->error;

Process takes three arguments.

The $in argument can be any one of:

    String containing the filename of the template to be processed.
    The filename should be relative to INCLUDE_PATH.  (See
    INCLUDE_PATH, ABSOLUTE, and RELATIVE configuration items).  In
    memory caching and file side caching are available for this type.

    A reference to a scalar containing the contents of the template to be processed.

    A coderef that will be called to return the contents of the template.

    An open filehandle that will return the contents of the template when read.

The $swap argument should be hashref containing key value pairs that
will be available to variables swapped into the template.  Values can
be hashrefs, hashrefs of hashrefs and so on, arrayrefs, arrayrefs of
arrayrefs and so on, coderefs, objects, and simple scalar values such
as numbers and strings.  See the section on variables.

The $out argument can be any one of:

    undef - meaning to print the completed template to STDOUT.

    String containing a filename.  The completed template will be placed in the file.

    A reference to a string.  The contents will be appended to the scalar reference.

    A coderef.  The coderef will be called with the contents as a single argument.

    An object that can run the method "print".  The contents will be passed as
    a single argument to print.

    An arrayref.  The contents will be pushed onto the array.

    An open filehandle.  The contents will be printed to the open handle.

Additionally - the $out argument can be configured using the OUTPUT configuration
item.

The process method defaults to using the "cet" syntax which will parse TT3 and most
TT2 documents.  To parse HT or HTE documents, you must pass the SYNTAX configuration
item to the "new" method.  All calls to process would then default to HTE syntax.

    my $obj = Template::Alloy->new(SYNTAX => 'hte');

=item C<process_simple>

Similar to the process method but with the following restrictions:

The $in parameter is limited to a filename or a reference a string
containing the contents.

The $out parameter may only be a reference to a scalar string that
output will be appended to.

Additionally, the following configuration variables will be ignored:
VARIABLES, PRE_DEFINE, BLOCKS, PRE_PROCESS, PROCESS, POST_PROCESS,
AUTO_RESET, OUTPUT.

=item C<error>

Should something go wrong during a "process" command, the error that
occurred can be retrieved via the error method.

    $obj->process('somefile.html', {a => 'b'}, \$string_ref)
        || die $obj->error;

=item C<output>

HTML::Template way to process a template.  The output method requires
that a filename, filehandle, scalarref, or arrayref argument was
passed to the new method.  All of the HT calling conventions for new
are supported.  The key difference is that Alloy will not actually
process the template until the output method is called.

    my $obj = Template::Alloy->new(filename => 'myfile.html');
    $obj->param(\%swap);
    print $obj->output;

See the HTML::Template documentation for more information.

The output method defaults to using the "hte" syntax which will parse
HTE and HT documents.  To parse TT3 or TT2 documents, you must pass
the SYNTAX configuration item to the "new" method.  All calls to
process would then default to TT3 syntax.

    my $obj = Template::Alloy->new(SYNTAX => 'tt3');

Any errors that occur during the output method will die with the error
as the die value.

=item C<param>

HTML::Template way to get or set variable values that will be used by
the output method.

    my $val = $obj->param('key'); # get one value

    $obj->param(key => $val);     # set one value

    $obj->param(key => $val, key2 => $val2);   # set multiple

    $obj->param({key => $val, key2 => $val2}); # set multiple

See the HTML::Template documentation for more information.

Note: Alloy does not support the die_on_bad_params configuration.
This is because Alloy does not resolve variable names until the output
method is called.

=item C<define_vmethod>

This method is available for defining extra Virtual methods or
filters.  This method is similar to Template::Stash::define_vmethod.

    Template::Alloy->define_vmethod(
        'text',
        reverse => sub { my $item = shift; return scalar reverse $item },
    );

=item C<register_function>

This is the HTML::Template way of defining text vmethods.  It is the same as
calling define_vmethod with "text" as the first argument.

    Template::Alloy->register_function(
        reverse => sub { my $item = shift; return scalar reverse $item },
    );

=item C<define_directive>

This method can be used for adding new directives or overridding existing
ones.

   Template::Alloy->define_directive(
       MYDIR => {
           parse_sub => sub {}, # parse additional items in the tag
           play_sub  => sub {
               my ($self, $ref, $node, $out_ref) = @_;
               $$out_ref .= "I always say the same thing!";
               return;
           },
           is_block  => 1,  # is this block like
           is_postop => 0,  # not a post operative directive
           no_interp => 1,  # no interpolation in this block
           continues => undef, # it doesn't "continue" any other directives
       },
   );

Now with a template like:

   my $str = "([% MYDIR %]This is something[% END %])";
   Template::Alloy->new->process(\$str);

You will get:

   (I always say the same thing!)

We'll add more details in later revisions of this document.

=item C<define_syntax>

This method can be used for adding another syntax to or overriding
existing ones in the list of choices available in Alloy.  The syntax can
be chosen by the SYNTAX configuration item.

    Template::Alloy->define_syntax(
        my_uber_syntax => sub {
            my $self = shift;
            local $self->{'V2PIPE'}      = 0;
            local $self->{'V2EQUALS'}    = 0;
            local $self->{'PRE_CHOMP'}   = 0;
            local $self->{'POST_CHOMP'}  = 0;
            local $self->{'NO_INCLUDES'} = 0;
            return $self->parse_tree_tt3(@_);
        },
    );

The subroutine that is used must return an opcode tree (AST) that
can be played by the execute_tree method.

=item C<define_operator>

This method allows for adding new operators or overriding existing ones.

    Template::Alloy->define_operator({
        type       => 'right', # can be one of prefix, postfix, right, left, none, ternary, assign
        precedence => 84,      # relative precedence for resolving multiple operators without parens
        symbols    => ['foo', 'FOO'], # any mix of chars can be used for the operators
        play_sub   => sub {
            my ($one, $two) = @_;
            return "You've been foo'ed ($one, $two)";
        },
    });

You can then use it in a template as in the following:

   my $str = "[% 'ralph' foo 1 + 2 * 3 %]";
   Template::Alloy->new->process(\$str);

You will get:

   You've been foo'ed (ralph, 7)

Future revisions of this document will include more samples.
This is an experimental feature and the API will probably change.

=item C<dump_parse_tree>

This method allows for returning a Data::Dumper dump of a parsed
template.  It is mainly used for testing.

=item C<dump_parse_expr>

This method allows for returning a Data::Dumper dump of a parsed
variable.  It is mainly used for testing.

=item C<import>

All of the arguments that can be passed to "use" that are listed
above in the section dealing with ROLES, can be used with the
import method.

    # import by role
    Template::Alloy->import(qw(Compile Play Parse TT));

    # import by method
    Template::Alloy->import(qw(compile_tree play_tree parse_tree process));

    # import by "stand-in" class
    Template::Alloy->import('Text::Tmpl', 'HTML::Template::Expr');

As mentioned in the ROLE section - arguments passed to import are
not imported into current namespace.  Roles and methods are only
imported into the Template::Alloy namespace.

=back

=head1 VARIABLES

This section discusses how to use variables and expressions in the TT
mini-language.

A variable is the most simple construct to insert into the TT mini
language.  A variable name will look for the matching value inside
Template::Alloys internal stash of variables which is essentially a
hash reference.  This stash is initially populated by either passing a
hashref as the second argument to the process method, or by setting
the "VARIABLES" or "PRE_DEFINE" configuration variables.

If you are using either the HT or the HTE syntax, the VAR, IF, UNLESS,
LOOP, and INCLUDE directives will accept a NAME attribute which may
only be a single level (non-chained) HTML::Template variable name, or
they may accept an EXPR attribute which may be any valid TT3 variable
or expression.

The following are some sample ways to access variables.

    ### some sample variables
    my %vars = (
        one       => '1.0',
        foo       => 'bar',
        vname     => 'one',
        some_code => sub { "You passed me (".join(', ', @_).")" },
        some_data => {
            a     => 'A',
            bar   => 3234,
            c     => [3, 1, 4, 1, 5, 9],
            vname => 'one',
        },
        my_list   => [20 .. 50],
        cet       => Template::Alloy->new,
    );

    ### pass the variables into the Alloy process
    $cet->process($template_name, \%vars)
         || die $cet->error;

    ### pass the variables during object creation (will be available to every process call)
    my $cet = Template::Alloy->new(VARIABLES => \%vars);

=head2 GETTING VARIABLES

Once you have variables defined, they can be used directly in the
template by using their name in the stash.  Or by using the GET
directive.

    [% foo %]
    [% one %]
    [% GET foo %]

Would print when processed:

    bar
    1.0
    bar

To access members of a hashref or an arrayref, you can chain together
the names using a ".".

    [% some_data.a %]
    [% my_list.0] [% my_list.1 %] [% my_list.-1 %]
    [% some_data.c.2 %]

Would print:

    A
    20 21 50
    4

If the value of a variable is a code reference, it will be called.
You can add a set of parenthesis and arguments to pass arguments.
Arguments are variables and can be as complex as necessary.

    [% some_code %]
    [% some_code() %]
    [% some_code(foo) %]
    [% some_code(one, 2, 3) %]

Would print:

    You passed me ().
    You passed me ().
    You passed me (bar).
    You passed me (1.0, 2, 3).

If the value of a variable is an object, methods can be called using
the "." operator.

    [% cet %]

    [% cet.dump_parse_expr('1 + 2').replace('\s+', ' ') %]

Would print something like:

    Template::Alloy=HASH(0x814dc28)

    $VAR1 = [ [ undef, '+', '1', '2' ], 0 ];

Each type of data (string, array and hash) have virtual methods
associated with them.  Virtual methods allow for access to functions
that are commonly used on those types of data.  For the full list of
built in virtual methods, please see the section titled VIRTUAL
METHODS

    [% foo.length %]
    [% my_list.size %]
    [% some_data.c.join(" | ") %]

Would print:

    3
    31
    3 | 1 | 4 | 5 | 9

It is also possible to "interpolate" variable names using a "$".  This
allows for storing the name of a variable inside another variable.  If
a variable name is a little more complex it can be embedded inside of
"${" and "}".

    [% $vname %]
    [% ${vname} %]
    [% ${some_data.vname} %]
    [% some_data.$foo %]
    [% some_data.${foo} %]

Would print:

    1.0
    1.0
    1.0
    3234
    3234

In Alloy it is also possible to embed any expression (non-directive) in
"${" and "}" and it is possible to use non-integers for array access.
(This is not available in TT2)

    [% ['a'..'z'].${ 2.3 } %]
    [% {ab => 'AB'}.${ 'a' ~ 'b' } %]
    [% color = qw/Red Blue/; FOR [1..4] ; color.${ loop.index % color.size } ; END %]

Would print:

    c
    AB
    RedBlueRedBlue

=head2 SETTING VARIABLES.

To define variables during processing, you can use the = operator.  In
most cases this is the same as using the SET directive.

    [% a = 234 %][% a %]
    [% SET b = "Hello" %][% b %]

Would print:

    234
    Hello

It is also possible to create arrayrefs and hashrefs.

    [% a = [1, 2, 3] %]
    [% b = {key1 => 'val1', 'key2' => 'val2'} %]

    [% a.1 %]
    [% b.key1 %] [% b.key2 %]

Would print:

    2
    val1 val2

It is possible to set multiple values in the same SET directive.

    [% SET a = 'A'
           b = 'B'
           c = 'C' %]
    [% a %]    [% b %]    [% c %]

Would print:

    A    B    C

It is also possible to unset variables, or to set members of
nested data structures.

    [% a = 1 %]
    [% SET a %]

    [% b.0.c = 37 %]

    ([% a %])
    [% b.0.c %]

Would print

    ()
    37

=head1 LITERALS AND CONSTRUCTORS

The following are the types of literals (numbers and strings) and
constructors (hash and array constructs) allowed in Alloy.  They can be
used as arguments to functions, in place of variables in directives,
and in place of variables in expressions.  In Alloy it is also possible
to call virtual methods on literal values.

=over 4

=item Integers and Numbers.

    [% 23423   %]        Prints an integer.
    [% 3.14159 %]        Prints a number.
    [% pi = 3.14159 %]   Sets the value of the variable.
    [% 3.13159.length %] Prints 7 (the string length of the number)

Scientific notation is supported.

    [% 314159e-5 + 0 %]      Prints 3.14159.

    [% .0000001.fmt('%.1e') %]  Prints 1.0e-07

Hexadecimal input is also supported.

    [% 0xff + 0 %]    Prints 255

    [% 48875.fmt('%x') %]  Prints beeb

=item Single quoted strings.

Returns the string.  No variable interpolation happens.

    [% 'foobar' %]          Prints "foobar".
    [% '$foo\n' %]          Prints "$foo\\n".  # the \\n is a literal "\" and an "n"
    [% 'That\'s nice' %]    Prints "That's nice".
    [% str = 'A string' %]  Sets the value of str.
    [% 'A string'.split %]  Splits the string on ' ' and returns the list.

Note: virtual methods can only be used on literal strings in Alloy, not in TT.

You may also embed the current tags in strings (Alloy only).

    [% '[% 1 + 2 %]' | eval %]  Prints "3"

=item Double quoted strings.

Returns the string.  Variable interpolation happens.

    [% "foobar" %]                   Prints "foobar".
    [% "$foo"   %]                   Prints "bar" (assuming the value of foo is bar).
    [% "${foo}" %]                   Prints "bar" (assuming the value of foo is bar).
    [% "foobar\n" %]                 Prints "foobar\n".  # the \n is a newline.
    [% str = "Hello" %]              Sets the value of str.
    [% "foo".replace('foo','bar') %] Prints "bar".

Note: virtual methods can only be used on literal strings in Alloy, not in TT.

You may also embed the current tags in strings (Alloy only).

    [% "[% 1 + 2 %]" | eval %]  Prints "3"

=item Array Constructs.

    [% [1, 2, 3] %]               Prints something like ARRAY(0x8309e90).
    [% array1 = [1 .. 3] %]       Sets the value of array1.
    [% array2 = [foo, 'a', []] %] Sets the value of array2.
    [% [4, 5, 6].size %]          Prints 3.
    [% [7, 8, 9].reverse.0 %]     Prints 9.

Note: virtual methods can only be used on array contructs in Alloy, not in TT.

=item Quoted Array Constructs.

    [% qw/1 2 3/ %]                Prints something like ARRAY(0x8309e90).
    [% array1 = qw{Foo Bar Baz} %] Sets the value of array1.
    [% qw[4 5 6].size %]           Prints 3.
    [% qw(Red Blue).reverse.0 %]   Prints Blue.

Note: this works in Alloy and is planned for TT3.

=item Hash Constructs.

    [% {foo => 'bar'} %]                 Prints something like HASH(0x8305880)
    [% hash = {foo => 'bar', c => {}} %] Sets the value of hash.
    [% {a => 'A', b => 'B'}.size %]      Prints 2.
    [% {'a' => 'A', 'b' => 'B'}.size %]  Prints 2.
    [% name = "Tom" %]
    [% {Tom => 'You are Tom',
        Kay => 'You are Kay'}.$name %]   Prints You are Tom

Note: virtual methods can only be used on hash contructs in Alloy, not in TT.

=item Regex Constructs.

    [% /foo/ %]                              Prints (?-xism:foo)
    [% a = /(foo)/i %][% "FOO".match(a).0 %] Prints FOO

Note: this works in Alloy and is planned for TT3.

=back

=head1 VIRTUAL METHODS

Virtual methods (vmethods) are a TT feature that allow for operating on the
swapped template variables.

This document shows some samples of using vmethods.  For a full
listing of available virtual methods, see L<Template::Alloy::VMethod>.

=head1 EXPRESSIONS

Expressions are one or more variables or literals joined together with
operators.  An expression can be used anywhere a variable can be used
with the exception of the variable name in the SET directive, and the
filename of PROCESS, INCLUDE, WRAPPER, and INSERT.

For a full listing of operators, see L<Template::Alloy::Operator>.

The following section shows some samples of expressions.  For a full
list of available operators, please see the section titled OPERATORS.

    [% 1 + 2 %]           Prints 3
    [% 1 + 2 * 3 %]       Prints 7
    [% (1 + 2) * 3 %]     Prints 9

    [% x = 2 %]                      # assignments don't return anything
    [% (x = 2) %]         Prints 2   # unless they are in parens
    [% y = 3 %]
    [% x * (y - 1) %]     Prints 4

=head1 DIRECTIVES

This section contains the alphabetical list of DIRECTIVES available in
Alloy.  DIRECTIVES are the "functions" and control structures that
work in the various mini-languages.  For further discussion and
examples beyond what is listed below, please refer to the TT
directives documentation or to the appropriate documentation
for the particular directive.

The examples given in this section are done using the
Template::Toolkit syntax, but can be done in any of the various
syntax options.  See L<Template::Alloy::TT>, L<Template::Alloy::HTE>,
L<Template::Alloy::Tmpl>, and L<Template::Alloy::Velocity>.

    [% IF 1 %]One[% END %]
    [% FOREACH a = [1 .. 3] %]
        a = [% a %]
    [% END %]

    [% SET a = 1 %][% SET a = 2 %][% GET a %]

In TT multiple directives can be inside the same set of '[%' and '%]'
tags as long as they are separated by space or semi-colons (;) (The
Alloy version of Tmpl allows multiple also - but none of the other
syntax options do).  Any block directive that can also be used as a
post-operative directive (such as IF, WHILE, FOREACH, UNLESS, FILTER,
and WRAPPER) must be separated from preceding directives with a
semi-colon if it is being used as a block directive.  It is more safe
to always use a semi-colon.  Note: separating by space is only
available in Alloy but is a planned TT3 feature.

    [% SET a = 1 ; SET a = 2 ; GET a %]
    [% SET a = 1
       SET a = 2
       GET a
     %]

    [% GET 1
         IF 0   # is a post-operative
       GET 2 %] # prints 2

    [% GET 1;
       IF 0     # it is block based
         GET 2
       END
     %]         # prints 1

The following is the list of directives.

=over 4

=item C<BLOCK>

Saves a block of text under a name for later use in PROCESS, INCLUDE,
and WRAPPER directives.  Blocks may be placed anywhere within the
template being processed including after where they are used.

    [% BLOCK foo %]Some text[% END %]
    [% PROCESS foo %]

    Would print

    Some text

    [% INCLUDE foo %]
    [% BLOCK foo %]Some text[% END %]

    Would print

    Some text

Anonymous BLOCKS can be used for capturing.

    [% a = BLOCK %]Some text[% END %][% a %]

    Would print

    Some text

Anonymous BLOCKS can be used with macros.


=item C<BREAK>

Alias for LAST.  Used for exiting FOREACH and WHILE loops.

=item C<CALL>

Calls the variable (and any underlying coderefs) as in the GET method, but
always returns an empty string.

=item C<CASE>

Used with the SWITCH directive.  See the L</"SWITCH"> directive.

=item C<CATCH>

Used with the TRY directive.  See the L</"TRY"> directive.

=item C<CLEAR>

Clears any of the content currently generated in the innermost block
or template.  This can be useful when used in conjunction with the TRY
statement to clear generated content if an error occurs later.

=item C<COMMENT>

Will comment out any text found between open and close tags.  Note, that
the intermediate items are still parsed and END tags must align - but the
parsed content will be discarded.

    [% COMMENT %]
       This text won't be shown.
       [% IF 1 %]And this won't either.[% END %]
    [% END %]

=item C<CONFIG>

Allow for changing the value of some compile time and runtime configuration
options.

    [% CONFIG
        ANYCASE   => 1
        PRE_CHOMP => '-'
    %]

The following compile time configuration options may be set:

    ANYCASE
    AUTO_EVAL
    AUTO_FILTER
    CACHE_STR_REFS
    ENCODING
    INTERPOLATE
    POST_CHOMP
    PRE_CHOMP
    SEMICOLONS
    SHOW_UNDEFINED_INTERP
    SYNTAX
    V1DOLLAR
    V2EQUALS
    V2PIPE

The following runtime configuration options may be set:

    ADD_LOCAL_PATH
    CALL_CONTEXT
    DUMP
    VMETHOD_FUNCTIONS
    STRICT (can only be enabled, cannot be disabled)

If non-named parameters as passed, they will show the current configuration:

   [% CONFIG ANYCASE, PRE_CHOMP %]

   CONFIG ANYCASE = undef
   CONFIG PRE_CHOMP = undef

=item C<DEBUG>

Used to reset the DEBUG_FORMAT configuration variable, or to turn
DEBUG statements on or off.  This only has effect if the DEBUG_DIRS or
DEBUG_ALL flags were passed to the DEBUG configuration variable.

    [% DEBUG format '($file) (line $line) ($text)' %]
    [% DEBUG on %]
    [% DEBUG off %]

=item C<DEFAULT>

Similar to SET, but only sets the value if a previous value was not
defined or was zero length.

    [% DEFAULT foo = 'bar' %][% foo %] => 'bar'

    [% foo = 'baz' %][% DEFAULT foo = 'bar' %][% foo %] => 'baz'

=item C<DUMP>

DUMP inserts a Data::Dumper printout of the variable or expression.
If no argument is passed it will dump the entire contents of the
current variable stash (with private keys removed).

The output also includes the current file and line number that the
DUMP directive was called from.

See the DUMP configuration item for ways to customize and control
the output available to the DUMP directive.

    [% DUMP %] # dumps everything

    [% DUMP 1 + 2 %]

=item C<ELSE>

Used with the IF directive.  See the L</"IF"> directive.

=item C<ELSIF>

Used with the IF directive.  See the L</"IF"> directive.

=item C<END>

Used to end a block directive.

=item C<EVAL>

Same as the EVALUATE directive.

=item C<EVALUATE>

Introduced by the Velocity templating language.  Parses and processes the
contents of the passed item.  This is similar to the eval filter, but
Velocity needs a directive.  Named arguments may be used for
re-configuring the parser.  Any of the items that can be passed to
the CONFIG directive may be passed here.

    [% EVALUATE "[% 1 + 3 %]" %]

    [% foo = "bar" %]
    [% EVALUATE "<TMPL_VAR foo>" SYNTAX => 'ht' %]

=item C<FILTER>

Used to apply different treatments to blocks of text.  It may operate as a BLOCK
directive or as a post operative directive.  Alloy supports all of the filters in
Template::Filters.  The lines between scalar virtual methods and filters is blurred (or
non-existent) in Alloy.  Anything that is a scalar virtual method may be used as a FILTER.

TODO - enumerate the at least 7 ways to pass and use filters.

=item C<'|'>

Alias for the FILTER directive.  Note that | is similar to the
'.' in Template::Alloy.  Therefore a pipe cannot be used directly after a
variable name in some situations (the pipe will act only on that variable).
This is the behavior employed by TT3.  To get the TT2 behavior for a PIPE, use
the V2PIPE configuration item.

=item C<FINAL>

Used with the TRY directive.  See the L</"TRY"> directive.

=item C<FOR>

Alias for FOREACH

=item C<FOREACH>

Allows for iterating over the contents of any arrayref.  If the variable is not an
arrayref, it is automatically promoted to one.

    [% FOREACH i IN [1 .. 3] %]
        The variable i = [% i %]
    [%~ END %]

    [% a = [1 .. 3] %]
    [% FOREACH j IN a %]
        The variable j = [% j %]
    [%~ END %]

Would print:

        The variable i = 1
        The variable i = 2
        The variable i = 3

        The variable j = 1
        The variable j = 2
        The variable j = 3

You can also use the "=" instead of "IN" or "in".

    [% FOREACH i = [1 .. 3] %]
        The variable i = [% i %]
    [%~ END %]

    Same as before.

Setting into a variable is optional.

    [% a = [1 .. 3] %]
    [% FOREACH a %] Hi [% END %]

Would print:

     hi  hi  hi 

If the item being iterated is a hashref and the FOREACH does not
set into a variable, then values of the hashref are copied into
the variable stash.

    [% FOREACH [{a => 1}, {a => 2}] %]
        Key a = [% a %]
    [%~ END %]

Would print:

        Key a = 1
        Key a = 2

The FOREACH process uses the Template::Alloy::Iterator class to handle
iterations (It is compatible with Template::Iterator).  During the FOREACH
loop an object blessed into the iterator class is stored in the variable "loop".

The loop variable provides the following information during a FOREACH:

    index  - the current index
    max    - the max index of the list
    size   - the number of items in the list
    count  - index + 1
    number - index + 1
    first  - true if on the first item
    last   - true if on the last item
    next   - return the next item in the list
    prev   - return the previous item in the list
    odd    - return 1 if the current count is odd, 0 otherwise
    even   - return 1 if the current count is even, 0 otherwise
    parity - return "odd" if the current count is odd, "even" otherwise

The following:

    [% FOREACH [1 .. 3] %] [% loop.count %]/[% loop.size %] [% END %]

Would print:

     1/3  2/3  3/3 

The iterator is also available using a plugin.  This allows for access
to multiple "loop" variables in a nested FOREACH directive.

    [%~ USE outer_loop = Iterator(["a", "b"]) %]
    [%~ FOREACH i = outer_loop %]
        [%~ FOREACH j = ["X", "Y"] %]
           [% outer_loop.count %]-[% loop.count %] = ([% i %] and [% j %])
        [%~ END %]
    [%~ END %]

Would print:

           1-1 = (a and X)
           1-2 = (a and Y)
           2-1 = (b and X)
           2-2 = (b and Y)

FOREACH may also be used as a post operative directive.

    [% "$i" FOREACH i = [1 .. 5] %] => 12345

=item C<GET>

Return the value of a variable or expression.

    [% GET a %]

The GET keyword may be omitted.

    [% a %]

    [% 7 + 2 - 3 %] => 6

See the section on VARIABLES.

=item C<IF (IF / ELSIF / ELSE)>

Allows for conditional testing.  Expects an expression as its only
argument.  If the expression is true, the contents of its block are
processed.  If false, the processor looks for an ELSIF block.  If an
ELSIF's expression is true then it is processed.  Finally it looks for
an ELSE block which is processed if none of the IF or ELSIF's
expressions were true.

    [% IF a == b %]A equaled B[% END %]

    [% IF a == b -%]
        A equaled B
    [%- ELSIF a == c -%]
        A equaled C
    [%- ELSE -%]
        Couldn't determine that A equaled anything.
    [%- END %]

IF may also be used as a post operative directive.

    [% 'A equaled B' IF a == b %]

Note: If you are using HTML::Template style documents, the TMPL_IF
tag parses using the limited HTML::Template parsing rules.  However,
you may use EXPR="" to embed a TT3 style expression.

=item C<INCLUDE>

Parse the contents of a file or block and insert them.  Variables defined
or modifications made to existing variables are discarded after
a template is included.

    [% INCLUDE path/to/template.html %]

    [% INCLUDE "path/to/template.html" %]

    [% file = "path/to/template.html" %]
    [% INCLUDE $file %]

    [% BLOCK foo %]This is foo[% END %]
    [% INCLUDE foo %]

Arguments may also be passed to the template:

    [% INCLUDE "path/to/template.html" a = "An arg" b = "Another arg" %]

Filenames must be relative to INCLUDE_PATH unless the ABSOLUTE
or RELATIVE configuration items are set.

Multiple filenames can be passed by separating them with a plus, a space,
or commas (TT2 doesn't support the comma).  Any supplied arguments will
be used on all templates.

    [% INCLUDE "path/to/template.html",
               "path/to/template2.html" a = "An arg" b = "Another arg" %]

On Perl 5.6 on some platforms there may be some issues with the variable
localization.  There is no problem on 5.8 and greater.

=item C<INSERT>

Insert the contents of a file without template parsing.

Filenames must be relative to INCLUDE_PATH unless the ABSOLUTE
or RELATIVE configuration items are set.

Multiple filenames can be passed by separating them with a plus, a space,
or commas (TT2 doesn't support the comma).

    [% INSERT "path/to/template.html",
              "path/to/template2.html" %]

=item C<JS>

Only available if the COMPILE_JS configuration item is true (default is false).
This requires the L<Template::Alloy::JS> module to be installed.

Allow eval'ing the block of text as javascript.  The block will be parsed and then eval'ed.

    [% a = "BimBam" %]
    [%~ JS %]
        write('The variable a was "' + get('a') + '"');
        set('b', "FooBar");
    [% END %]
    [% b %]

Would print:

    The variable a was "BimBam"
    FooBar

=item C<LAST>

Used to exit out of a WHILE or FOREACH loop.

=item C<LOOP>

This directive operates similar to the HTML::Template loop directive.
The LOOP directive expects a single variable name.  This variable name
should point to an arrayref of hashrefs.  The keys of each hashref
will be added to the variable stash when it is iterated.

    [% var a = [{b => 1}, {b => 2}, {b => 3}] %]

    [% LOOP a %] ([% b %]) [% END %]

Would print:

     (1)  (2)  (3) 

If Alloy is in HT mode and GLOBAL_VARS is false, the contents of
the hashref will be the only items available during the loop iteration.

If LOOP_CONTEXT_VARS is true, and $QR_PRIVATE is false (default when
called through the output method), then the variables __first__, __last__,
 __inner__, __odd__, and __counter__ will be set.  See the HTML::Template
loop_context_vars configuration item for more information.

=item C<MACRO>

Takes a directive and turns it into a variable that can take arguments.

    [% MACRO foo(i, j) BLOCK %]You passed me [% i %] and [% j %].[% END %]

    [%~ foo("a", "b") %]
    [% foo(1, 2) %]

Would print:

    You passed me a and b.
    You passed me 1 and 2.

Another example:

    [% MACRO bar(max) FOREACH i = [1 .. max] %]([% i %])[% END %]

    [%~ bar(4) %]

Would print:

    (1)(2)(3)(4)

Starting with version 1.012 of Template::Alloy there is also
a macro operator.

    [% foo = ->(i,j){ "You passed me $i and $j" } %]

    [% bar = ->(max){ FOREACH i = [1 .. max]; i ; END } %]

See the Template::Alloy::Operator documentation for more examples.

=item C<META>

Used to define variables that will be available via either the
template or component namespace.

Once defined, they cannot be overwritten.

    [% template.foobar %]
    [%~ META foobar = 'baz' %]
    [%~ META foobar = 'bing' %]

Would print:

    baz

=item C<NEXT>

Used to go to the next iteration of a WHILE or FOREACH loop.

=item C<PERL>

Only available if the EVAL_PERL configuration item is true (default is false).

Allow eval'ing the block of text as perl.  The block will be parsed and then eval'ed.

    [% a = "BimBam" %]
    [%~ PERL %]
        my $a = "[% a %]";
        print "The variable \$a was \"$a\"";
        $stash->set('b', "FooBar");
    [% END %]
    [% b %]

Would print:

    The variable $a was "BimBam"
    FooBar

During execution, anything printed to STDOUT will be inserted into the template.  Also,
the $stash and $context variables are set and are references to objects that mimic the
interface provided by Template::Context and Template::Stash.  These are provided for
compatibility only.  $self contains the current Template::Alloy object.

=item C<PROCESS>

Parse the contents of a file or block and insert them.  Unlike INCLUDE,
no variable localization happens so variables defined or modifications made
to existing variables remain after the template is processed.

    [% PROCESS path/to/template.html %]

    [% PROCESS "path/to/template.html" %]

    [% file = "path/to/template.html" %]
    [% PROCESS $file %]

    [% BLOCK foo %]This is foo[% END %]
    [% PROCESS foo %]

Arguments may also be passed to the template:

    [% PROCESS "path/to/template.html" a = "An arg" b = "Another arg" %]

Filenames must be relative to INCLUDE_PATH unless the ABSOLUTE
or RELATIVE configuration items are set.

Multiple filenames can be passed by separating them with a plus, a space,
or commas (TT2 doesn't support the comma).  Any supplied arguments will
be used on all templates.

    [% PROCESS "path/to/template.html",
               "path/to/template2.html" a = "An arg" b = "Another arg" %]

=item C<RAWPERL>

Only available if the EVAL_PERL configuration item is true (default is false).
Similar to the PERL directive, but you will need to append
to the $output variable rather than just calling PRINT.

=item C<RETURN>

Used to exit the innermost block or template and continue processing
in the surrounding block or template.

There are two changes from TT2 behavior.  First, In Alloy, a RETURN during
a MACRO call will only exit the MACRO.  Second, the RETURN directive
takes an optional variable name or expression, if passed, the MACRO will
return this value instead of the normal text from the MACRO.  The process_simple
method will also return this value.

You can also use the item, list, and hash return vmethods.

    [% RETURN %]       # just exits
    [% RETURN "foo" %] # return value is foo
    [% "foo".return %] # same thing

=item C<SET>

Used to set variables.

   [% SET a = 1 %][% a %]             => "1"
   [% a = 1 %][% a %]                 => "1"
   [% b = 1 %][% SET a = b %][% a %]  => "1"
   [% a = 1 %][% SET a %][% a %]      => ""
   [% SET a = [1, 2, 3] %][% a.1 %]   => "2"
   [% SET a = {b => 'c'} %][% a.b %]  => "c"

=item C<STOP>

Used to exit the entire process method (out of all blocks and templates).
No content will be processed beyond this point.

=item C<SWITCH>

Allow for SWITCH and CASE functionality.

   [% a = "hi" %]
   [% b = "bar" %]
   [% SWITCH a %]
       [% CASE "foo"           %]a was foo
       [% CASE b               %]a was bar
       [% CASE ["hi", "hello"] %]You said hi or hello
       [% CASE DEFAULT         %]I don't know what you said
   [% END %]

Would print:

   You said hi or hello

=item C<TAGS>

Change the type of enclosing braces used to delineate template tags.  This
remains in effect until the end of the enclosing block or template or until
the next TAGS directive.  Either a named set of tags must be supplied, or
two tags themselves must be supplied.

    [% TAGS html %]

    [% TAGS <!-- --> %]

The named tags are (duplicated from TT):

    asp       => ['<%',     '%>'    ], # ASP
    default   => ['\[%',    '%\]'   ], # default
    html      => ['<!--',   '-->'   ], # HTML comments
    mason     => ['<%',     '>'     ], # HTML::Mason
    metatext  => ['%%',     '%%'    ], # Text::MetaText
    php       => ['<\?',    '\?>'   ], # PHP
    star      => ['\[\*',   '\*\]'  ], # TT alternate
    template  => ['\[%',    '%\]'   ], # Normal Template Toolkit
    template1 => ['[\[%]%', '%[%\]]'], # allow TT1 style
    tt2       => ['\[%',    '%\]'   ], # TT2

If custom tags are supplied, by default they are escaped using
quotemeta.  You may also pass explicitly quoted strings,
or regular expressions as arguments as well (if your
regex begins with a ', ", or / you must quote it.

    [% TAGS [<] [>] %]          matches "[<] tag [>]"

    [% TAGS '[<]' '[>]' %]      matches "[<] tag [>]"

    [% TAGS "[<]" "[>]" %]      matches "[<] tag [>]"

    [% TAGS /[<]/ /[>]/ %]      matches "< tag >"

    [% TAGS ** ** %]            matches "** tag **"

    [% TAGS /**/ /**/ %]        Throws an exception.

You should be sure that the start tag does not include grouping
parens or INTERPOLATE will not function properly.

=item C<THROW>

Allows for throwing an exception.  If the exception is not caught
via the TRY DIRECTIVE, the template will abort processing of the directive.

    [% THROW mytypes.sometime 'Something happened' arg1 => val1 %]

See the TRY directive for examples of usage.

=item C<TRY>

The TRY block directive will catch exceptions that are thrown
while processing its block (It cannot catch parse errors unless
they are in included files or evaltt'ed strings.   The TRY block
will then look for a CATCH block that will be processed.  While
it is being processed, the "error" variable will be set with the thrown
exception as the value.  After the TRY block - the FINAL
block will be ran whether or not an error was thrown (unless a CATCH
block throws an error).

Note: Parse errors cannot be caught unless they are in an eval FILTER, or are
in a separate template being INCLUDEd or PROCESSed.

    [% TRY %]
    Nothing bad happened.
    [% CATCH %]
    Caught the error.
    [% FINAL %]
    This section runs no matter what happens.
    [% END %]

Would print:

    Nothing bad happened.
    This section runs no matter what happens.

Another example:

    [% TRY %]
    [% THROW "Something happened" %]
    [% CATCH %]
      Error:               [% error %]
      Error.type:          [% error.type %]
      Error.info:          [% error.info %]
    [% FINAL %]
      This section runs no matter what happens.
    [% END %]

Would print:

      Error:               undef error - Something happened
      Error.type:          undef
      Error.info:          Something happened
      This section runs no matter what happens.

You can give the error a type and more information including named arguments.
This information replaces the "info" property of the exception.

    [% TRY %]
    [% THROW foo.bar "Something happened" "grrrr" foo => 'bar' %]
    [% CATCH %]
      Error:               [% error %]
      Error.type:          [% error.type %]
      Error.info:          [% error.info %]
      Error.info.0:        [% error.info.0 %]
      Error.info.1:        [% error.info.1 %]
      Error.info.args.0:   [% error.info.args.0 %]
      Error.info.foo:      [% error.info.foo %]
    [% END %]

Would print something like:

      Error:               foo.bar error - HASH(0x82a395c)
      Error.type:          foo.bar
      Error.info:          HASH(0x82a395c)
      Error.info.0:        Something happened
      Error.info.1:        grrrr
      Error.info.args.0:   Something happened
      Error.info.foo:      bar

You can also give the CATCH block a type to catch.  And you
can nest TRY blocks.  If types are specified, Alloy will try and
find the closest matching type.  Also, an error object can
be re-thrown using $error as the argument to THROW.

    [% TRY %]
      [% TRY %]
        [% THROW foo.bar "Something happened" %]
      [% CATCH bar %]
        Caught bar.
      [% CATCH DEFAULT %]
        Caught default - but re-threw.
        [% THROW $error %]
      [% END %]
    [% CATCH foo %]
      Caught foo.
    [% CATCH foo.bar %]
      Caught foo.bar.
    [% CATCH %]
      Caught anything else.
    [% END %]

Would print:

        Caught default - but re-threw.

      Caught foo.bar.

=item C<UNLESS>

Same as IF but condition is negated.

    [% UNLESS 0 %]hi[% END %]  => hi

Can also be a post operative directive.

=item C<USE>

Allows for loading a Template::Toolkit style plugin.

    [% USE iter = Iterator(['foo', 'bar']) %]
    [%~ iter.get_first %]
    [% iter.size %]

Would print:

    foo
    2

Note that it is possible to send arguments to the new object
constructor.  It is also possible to omit the variable name being
assigned.  In that case the name of the plugin becomes the variable.

    [% USE Iterator(['foo', 'bar', 'baz']) %]
    [%~ Iterator.get_first %]
    [% Iterator.size %]

Would print:

    foo
    3

Plugins that are loaded are looked up for in the namespace listed in
the PLUGIN_BASE directive which defaults to Template::Plugin.  So in
the previous example, if Template::Toolkit was installed, the iter
object would loaded by the class Template::Plugin::Iterator.  In Alloy,
an effective way to disable plugins is to set the PLUGIN_BASE to a
non-existent base such as "_" (In TT it will still fall back to look
in Template::Plugin).

Note: The iterator plugin will fall back and use
Template::Alloy::Iterator if Template::Toolkit is not installed.  No
other plugins come installed with Template::Alloy.

The names of the Plugin being loaded from PLUGIN_BASE are case
insensitive.  However, using case insensitive names is bad as it
requires scanning the @INC directories for any module matching the
PLUGIN_BASE and caching the result (OK - not that bad).

If the plugin is not found and the LOAD_PERL directive is set, then
Alloy will try and load a module by that name (note: this type of lookup
is case sensitive and will not scan the @INC dirs for a matching
file).

    # The LOAD_PERL directive should be set to 1
    [% USE ta = Template::Alloy %]
    [%~ ta.dump_parse_expr('2 * 3') %]

Would print:

    [[undef, '*', 2, 3], 0];

See the PLUGIN_BASE, and PLUGINS configuration items.

See the documentation for Template::Manual::Plugins.

=item C<VIEW>

Implement a TT style view.  For more information, please
see the Template::View documentation.  This DIRECTIVE
will correctly parse the arguments and then pass them
along to a newly created Template::View object.  It
will fail if Template::View can not be found.

=item C<WHILE>

Will process a block of code while a condition is true.

    [% WHILE i < 3 %]
        [%~ i = i + 1 %]
        i = [% i %]
    [%~ END %]

Would print:

        i = 1
        i = 2
        i = 3

You could also do:

    [% i = 4 %]
    [% WHILE (i = i - 1) %]
        i = [% i %]
    [%~ END %]

Would print:

        i = 3
        i = 2
        i = 1

Note that (f = f - 1) is a valid expression that returns the value
of the assignment.  The parenthesis are not optional.

WHILE has a built in limit of 1000 iterations.  This is controlled by the
global variable $WHILE_MAX in Template::Alloy.

WHILE may also be used as a post operative directive.

    [% "$i" WHILE (i = i + 1) < 7 %] => 123456

=item C<WRAPPER>

Block directive.  Processes contents of its block and then passes them
in the [% content %] variable to the block or filename listed in the
WRAPPER tag.

    [% WRAPPER foo b = 23 %]
    My content to be processed ([% b %]).[% a = 2 %]
    [% END %]

    [% BLOCK foo %]
    A header ([% a %]).
    [% content %]
    A footer ([% a %]).
    [% END %]

This would print.

    A header (2).
    My content to be processed (23).
    A footer (2).

The WRAPPER directive may also be used as a post operative directive.

    [% BLOCK baz %]([% content %])[% END -%]
    [% "foobar" WRAPPER baz %]

Would print

    (foobar)');

Multiple filenames can be passed by separating them with a plus, a space,
or commas (TT2 doesn't support the comma).  Any supplied arguments will
be used on all templates.  Wrappers are processed in reverse order, so
that the first wrapper listed will surround each subsequent wrapper listed.
Variables from inner wrappers are available to the next wrapper that
surrounds it.

    [% WRAPPER "path/to/outer.html",
               "path/to/inner.html" a = "An arg" b = "Another arg" %]


=back

=head1 DIRECTIVES (HTML::Template Style)

HTML::Template templates use directives that look similar to the
following:

    <TMPL_VAR NAME="foo">

    <TMPL_IF NAME="bar">
      BAR
    </TMPL_IF>

The normal set of HTML::Template directives are TMPL_VAR,
TMPL_IF, TMPL_ELSE, TMPL_UNLESS, TMPL_INCLUDE, and TMPL_LOOP.
These tags should have either a NAME attribute, an EXPR attribute,
or a bare variable name that is used to specify the value to
be operated.  If a NAME is specified, it may only be a single
level value (as opposed to a TT chained variable).  In the case
of the TMPL_INCLUDE directive, the NAME is the file to be included.

In Alloy, the EXPR attribute can be used with any of these types to
specify TT compatible variable or expression that will be used for
the value.

    <TMPL_VAR NAME="foo">          Prints the value contained in foo
    <TMPL_VAR foo>                 Prints the value contained in foo
    <TMPL_VAR EXPR="foo">          Prints the value contained in foo

    <TMPL_VAR NAME="foo.bar.baz">  Prints the value contained in {'foo.bar.baz'}
    <TMPL_VAR EXPR="foo.bar.baz">  Prints the value contained in {foo}->{bar}->{baz}

    <TMPL_IF foo>                  Prints FOO if foo is true
      FOO
    </TMPL_IF

    <TMPL_UNLESS foo>              Prints FOO unless foo is true
      FOO
    </TMPL_UNLESS

    <TMPL_INCLUDE NAME="foo.ht">   Includes the template in "foo.ht"

    <TMPL_LOOP foo>                Iterates on the arrayref foo
      <TMPL_VAR name>
    </TMPL_LOOP>

Template::Alloy makes all of the other TT3 directives available
in addition to the normal set of HTML::Template directives.  For
example, the following is valid in Alloy.

    <TMPL_MACRO bar(n) BLOCK>You said <TMPL_VAR n></TMPL_MACRO>
    <TMPL_GET bar("hello")>

The TMPL_VAR tag may also include an optional ESCAPE attribute.
This specifies how the value of the tag should be escaped prior
to substituting into the template.

    Escape value |   Type of escape
    ---------------------------------
    HTML, 1      |   HTML encoding
    URL          |   URL encoding
    JS           |   basic javascript encoding (\n, \r, and \")
    NONE, 0      |   No encoding (default).

The TMPL_VAR tag may also include an optional DEFAULT attribute
that contains a string that will be used if the variable returns
false.

    <TMPL_VAR foo DEFAULT="Foo was false">

=head1 CHOMPING

Chomping refers to the handling of whitespace immediately before and
immediately after template tags.  By default, nothing happens to this
whitespace.  Modifiers can be placed just inside the opening and just
before the closing tags to control this behavior.

Additionally, the PRE_CHOMP and POST_CHOMP configuration variables can
be set and will globally control all chomping behavior for tags that
do not have their own chomp modifier.  PRE_CHOMP and POST_CHOMP can
be set to any of the following values:

    none:      0   +   Template::Constants::CHOMP_NONE
    one:       1   -   Template::Constants::CHOMP_ONE
    collapse:  2   =   Template::Constants::CHOMP_COLLAPSE
    greedy:    3   ~   Template::Constants::CHOMP_GREEDY

=over 4

=item CHOMP_NONE

Don't do any chomping.  The "+" sign is used to indicate CHOMP_NONE.

    Hello.

    [%+ "Hi." +%]

    Howdy.

Would print:

    Hello.

    Hi.

    Howdy.

=item CHOMP_ONE (formerly known as CHOMP_ALL)

Delete any whitespace up to the adjacent newline.  The "-" is used to indicate CHOMP_ONE.

    Hello.

    [%- "Hi." -%]

    Howdy.

Would print:

    Hello.
    Hi.
    Howdy.

=item CHOMP_COLLAPSE

Collapse adjacent whitespace to a single space.  The "=" is used to indicate CHOMP_COLLAPSE.

    Hello.

    [%= "Hi." =%]

    Howdy.

Would print:

    Hello. Hi. Howdy.

=item CHOMP_GREEDY

Remove all adjacent whitespace.  The "~" is used to indicate CHOMP_GREEDY.

    Hello.

    [%~ "Hi." ~%]

    Howdy.

Would print:

    Hello.Hi.Howdy.

=back

=head1 CONFIGURATION

The following configuration variables are supported (in
alphabetical order).  Note: for further discussion you can refer to
the TT config documentation.

Items may be passed in upper or lower case.  If lower case names
are passed they will be resolved to uppercase during the "new"
method.

All of the variables in this section can be passed to the "new" constructor.

    my $obj = Template::Alloy->new(
        VARIABLES  => \%hash_of_variables,
        AUTO_RESET => 0,
        TRIM       => 1,
        POST_CHOMP => "=",
        PRE_CHOMP  => "-",
    );

=over 4

=item ABSOLUTE

Boolean.  Default false.  Are absolute paths allowed for included files.

=item ADD_LOCAL_PATH

If true, allows calls include_filename to temporarily add the
directory of the current template being processed to the INCLUDE_PATHS
arrayref.  This allows templates to refer to files in the local
template directory without specifying the local directory as part of
the filename.  Default is 0.  If set to a negative value, the current
directory will be added to the end of the current INCLUDE_PATHS.

This property may also be set in the template using the CONFIG directive.

    [% CONFIG ADD_LOCAL_PATH => 1 %]

=item ANYCASE

Allow directive matching to be case insensitive.

    [% get 23 %] prints 23 with ANYCASE => 1

=item AUTO_RESET

Boolean.  Default 1.  Clear blocks that were set during the process method.

=item AUTO_EVAL

Boolean.  Default 0 (default 1 in Velocity syntax).  If set to true,
double quoted strings will automatically be passed to the eval filter.
This configuration option may also be passed to the CONFIG directive.

=item AUTO_FILTER

Can be the name of any filter.  Default undef.  Any variable returned by a
GET directive (including implicit GET) will be passed to the named filter.
This configuration option may also be passed to the CONFIG directive.

    # with AUTO_FILTER => 'html'

    [% f = "&"; GET f %] prints &amp;
    [% f = "&"; f %]     prints &amp; (implicit GET)

If a variable already has another filter applied the AUTO_FILTER is not applied.
The "none" scalar virtual method has been added to allow for using variables
without reapplying filters.

    # with AUTO_FILTER => 'html'

    [% f = "&";  f | none %] prints &
    [% f = "&"; g = f; g %]  prints &amp;
    [% f = "&"; g = f; g | none %]  prints & (because g = f is a SET directive)
    [% f = "&"; g = GET f; g | none %]  prints &amp; (because the actual GET directive was called)

=item BLOCKS

Only available via when using the process interface.

A hashref of blocks that can be used by the process method.

    BLOCKS => {
        block_1 => sub { ... }, # coderef that returns a block
        block_2 => 'A String',  # simple string
    },

Note that a Template::Document cannot be supplied as a value (TT
supports this).  However, it is possible to supply a value that is
equal to the hashref returned by the load_template method.

=item CACHE_SIZE

Number of compiled templates to keep in memory.  Default undef.
Undefined means to allow all templates to cache.  A value of 0 will
force no caching.  The cache mechanism will clear templates that have
not been used recently.

=item CACHE_STR_REFS

Default 1.  If set, any string refs will have an MD5 sum taken that
will then be used for caching the document - both in memory and on
the file system (if configured).  This will give a significant speed
boost.  Note that this affects strings passed to the EVALUATE directive
or eval filters as well.  It may be set using the CONFIG directive.

=item CALL_CONTEXT (Not in TT)

Can be one of 'item', 'list', or 'smart'.  The default type is
'smart'.  The CALL_CONTEXT configuration specifies in what Perl
context coderefs and methods used in the processed templates will be
called.  TT historically has avoided the distinction of item (scalar)
vs list context.  To avoid worrying about this, TT introduced 'smart'
context.  The C<@()> and C<$()> context specifiers make it easier to use
CALL_CONTEXT in some situations.

The following table shows the relationship between the various contexts:

       return values      smart context   list context    item context
       -------------      -------------   ------------    ------------
    A   'foo'              'foo'           ['foo']         'foo'
    B   undef              undef           [undef]         undef
    C   (no return value)  undef           []              undef
    D   (7)                7               [7]             7
    E   (7,8,9)            [7,8,9]         [7,8,9]         9
    F   @a = (7)           7               [7]             1
    G   @a = (7,8,9)       [7,8,9]         [7,8,9]         3
    H   ({b=>"c"})         {b=>"c"}        [{b=>"c"}]      {b=>"c"}
    I   ([1])              [1]             [[1]]           [1]
    J   ([1],[2])          [[1],[2]]       [[1],[2]]       [2]
    K   [7,8,9]            [7,8,9]         [[7,8,9]]       [7,8,9]
    L   (undef, "foo")     die "foo"       [undef, "foo"]  "foo"
    M   wantarray?1:0      1               [1]             0

Cases F, H, I and M are common sticking points of the smart context
in TT2.  Note that list context always returns an arrayref from a method
or function call.  Smart context can give confusing results sometimes,
especially the I and J cases.  Case L for smart match is very surprising.

The list and item context provide another feature for method calls.  In
smart context, TT will look for a hash key in the object by the same name
as the method, if a method by that name doesn't exist.  In item and list
context Alloy will die if a method by that name cannot be found.

The CALL_CONTEXT configuration item can be passed to new or it may
also be set during runtime using the CONFIG directive.  The following
method call would be in list context:

    [% CONFIG CALL_CONTEXT => 'list';
       results = my_obj.get_results;
       CONFIG CALL_CONTEXT => 'smart'
    %]

Note that we needed to restore CALL_CONTEXT to the default 'smart' value.
Template::Alloy has added the C<@()> (list) and the C<$()> (item) context
specifiers.  The previous example could be written as:

    [% results = @( my_obj.get_results ) %]

To call that same method in item (scalar) context you would do the following:

    [% results = $( my_obj.get_results ) %]

The C<@()> and C<$()> operators are based on the Perl 6 counterpart.

=item COMPILE_DIR

Base directory to store compiled templates.  Default undef. Compiled
templates will only be stored if one of COMPILE_DIR and COMPILE_EXT is
set.

If set, the AST of parsed documents will be cached.  If COMPILE_PERL is
set, the compiled perl code will also be stored.

=item COMPILE_EXT

Extension to add to stored compiled template filenames.  Default undef.

If set, the AST of parsed documents will be cached.  If COMPILE_PERL is
set, the compiled perl code will also be stored.

=item COMPILE_JS

Default false.

Requires installation of L<Template::Alloy::JS>.  When enabled, the parsed
templates will be translated into Javascript and executed using the
V8 javascript engine.  If compile_dir is also set, this compiled javascript
will be cached to disk.

If your templates are short, there is little benefit to using this other
than you can then use the JS directive.  If your templates are long or
you are running in a cached environment, this will speed up your templates.

Certain limitations exist when COMPILE_JS is set, most notably the USE
and VIEW directives are not supported, and method calls on objects
passed to the template do not work (code refs passed in do work
however).  These limitations are due to the nature of JavaScript::V8
bind and Perl/JavaScript OO differences.

=item COMPILE_PERL

Default false.

If set to 1 or 2, will translate the normal AST into a perl 5 code document.
This document can then be executed directly, cached in memory, or cached
on the file system depending upon the configuration items set.

If set to 1, a perl code document will always be generated.

If set to 2, a perl code document will only be generated if an AST has
already been cached for the document.  This should give a speed benefit and
avoid extra compilation unless the document has been used more than once.

If Alloy is running in a cached environment such as mod_perl, then using
compile_perl can offer some speed benefit and makes Alloy faster than Text::Tmpl
and as fast as HTML::Template::Compiled (but Alloy has more features).

If you are not running in a cached environment, such as from commandline, or from
CGI, it is generally faster to only run from the AST (with COMPILE_PERL => 0).

=item CONSTANTS

Hashref.  Used to define variables that will be "folded" into the
compiled template.  Variables defined here cannot be overridden.

    CONSTANTS => {my_constant => 42},

    A template containing:

    [% constants.my_constant %]

    Will have the value 42 compiled in.

Constants defined in this way can be chained as in [%
constant.foo.bar.baz %].

=item CONSTANT_NAMESPACE

Allow for setting the top level of values passed in CONSTANTS.  Default
value is 'constants'.

=item DEBUG

Takes a list of constants |'ed together which enables different
debugging modes.  Alternately the lowercase names may be used
(multiple values joined by a ",").

    The only supported TT values are:
    DEBUG_UNDEF (2)    - debug when an undefined value is used (now easier to use STRICT)
    DEBUG_DIRS  (8)    - debug when a directive is used.
    DEBUG_ALL   (2047) - turn on all debugging.

    Either of the following would turn on undef and directive debugging:

    DEBUG => 'undef, dirs',            # preferred
    DEBUG => 2 | 8,
    DEBUG => DEBUG_UNDEF | DEBUG_DIRS, # constants from Template::Constants

=item DEBUG_FORMAT

Change the format of messages inserted when DEBUG has DEBUG_DIRS set on.
This essentially the same thing as setting the format using the DEBUG
directive.

=item DEFAULT

The name of a default template file to use if the passed one is not found.

=item DELIMITER

String to use to split INCLUDE_PATH with.  Default is :.  It is more
straight forward to just send INCLUDE_PATH an arrayref of paths.

=item DUMP

Configures the behavior of the DUMP tag.  May be set to 0, a hashref,
or another true value.  Default is true.

If set to 0, all DUMP directives will do nothing.  This is useful if
you would like to turn off the DUMP directives under some environments.

IF set to a true value (or undefined) then DUMP directives will operate.

If set to a hashref, the values of the hash can be used to configure
the operation of the DUMP directives.  The following are the values
that can be set in this hash.

=over 4

=item EntireStash

Default 1.  If set to 0, then the DUMP directive will not print the
entire contents of the stash when a DUMP directive is called without
arguments.

=item handler

Defaults to an internal coderef.  If set to a coderef, the DUMP directive will pass the
arguments to be dumped and expects a string with the dumped data.  This
gives complete control over the dump process.

Note 1: The default handler makes sure that values matching the
private variable regex are not included.  If you install your own handler,
you will need to take care of these variables if you intend for them
to not be shown.

Note 2: If you would like the name of the variable to be dumped, include
the string '$VAR1' and the DUMP directive will interpolate the value.  For
example, to dump all output as YAML - you could do the following:

    DUMP => {
       handler => sub {
           require YAML;
           return "\$VAR1 =\n".YAML::Dump(shift);
       },
    }

=item header

Default 1.  Controls whether a header is printed for each DUMP directive.
The header contains the file and line number the DUMP directive was
called from.  If set to 0 the headers are disabled.

=item html

Defaults to 1 if $ENV{'REQUEST_METHOD'} is set - 0 otherwise.  If set to
1, then the output of the DUMP directive is passed to the html filter
and encased in "pre" tags.  If set to 0 no html encoding takes place.

=item Sortkeys, Useqq, Ident, Pad, etc

Any of the Data::Dumper configuration items may be passed.

=back

=item ENCODING

Default undef.  If set, and if Perl version is greater than or equal to
5.7.3 (when Encode.pm was first included), then Encode::decode will
be called every time a template file is processed and will be passed
the value of ENCODING and text from the template.

This item can also be set using [% CONFIG ENCODING => encoding %] before
calling INCLUDE or PROCESS directives to change encodings on the fly.

=item END_TAG

Set a string to use as the closing delimiter for TT.  Default is "%]".

=item ERROR

Used as a fall back when the processing of a template fails.  May either
be a single filename that will be used in all cases, or may be a hashref
of options where the keynames represent error types that will be handled
by the filename in their value.  A key named default will be used if no
other matching keyname can be found.  The selection process is similar
to that of the TRY/CATCH/THROW directives (see those directives for more
information).

    my $t = Template::Alloy->new({
        ERROR => 'general/catch_all_errors.html',
    });

    my $t = Template::Alloy->new({
        ERROR => {
            default   => 'general/catch_all_errors.html',
            foo       => 'catch_all_general_foo_errors.html',
            'foo.bar' => 'catch_foo_bar_errors.html',
        },
    });

Note that the ERROR handler will only be used for errors during the
processing of the main document.  It will not catch errors that
occur in templates found in the PRE_PROCESS, POST_PROCESS, and WRAPPER
configuration items.

=item ERRORS

Same as the ERROR configuration item.  Both may be used interchangeably.

=item EVAL_PERL

Boolean.  Default false.  If set to a true value, PERL and RAWPERL blocks
will be allowed to run.  This is a potential security hole, as arbitrary
perl can be included in the template.  If Template::Toolkit is installed,
a true EVAL_PERL value also allows the perl and evalperl filters to be used.

=item FILTERS

Allow for passing in TT style filters.

    my $filters = {
        filter1 =>  sub { my $str = shift; $s =~ s/./1/gs; $s },
        filter2 => [sub { my $str = shift; $s =~ s/./2/gs; $s }, 0],
        filter3 => [sub { my ($context, @args) = @_; return sub { my $s = shift; $s =~ s/./3/gs; $s } }, 1],
    };

    my $str = q{
        [% a = "Hello" %]
        1 ([% a | filter1 %])
        2 ([% a | filter2 %])
        3 ([% a | filter3 %])
    };

    my $obj = Template::Alloy->new(FILTERS => $filters);
    $obj->process(\$str) || die $obj->error;

Would print:

        1 (11111)
        2 (22222)
        3 (33333)

Filters passed in as an arrayref should contain a coderef and a value
indicating if they are dynamic or static (true meaning dynamic).  The
dynamic filters are passed the pseudo context object and any arguments
and should return a coderef that will be called as the filter.  The filter
coderef is then passed the string.

=item GLOBAL_CACHE

Default 0.  If true, documents will be cached in $Template::Alloy::GLOBAL_CACHE.
It may also be passed a hashref, in which case the documents will be
cached in the passed hashref.

The TT, Tmpl, and velocity will automatically cache documents in the object.  The
HTML::Template interface uses a new object each time.  Setting the HTML::Template's
CACHE configuration is the same as setting GLOBAL_CACHE.

=item INCLUDE_PATH

A string or an arrayref or coderef that returns an arrayref that
contains directories to look for files included by processed
templates.  Defaults to "." (the current directory).

=item INCLUDE_PATHS

Non-TT item.  Same as INCLUDE_PATH but only takes an arrayref.  If not specified
then INCLUDE_PATH is turned into an arrayref and stored in INCLUDE_PATHS.
Overrides INCLUDE_PATH.

=item INTERPOLATE

Boolean.  Specifies whether variables in text portions of the template will be
interpolated.  For example, the $variable and ${var.value} would be substituted
with the appropriate values from the variable cache (if INTERPOLATE is on).

    [% IF 1 %]The variable $variable had a value ${var.value}[% END %]

=item LOAD_PERL

Indicates if the USE directive can fall back and try and load a perl module
if the indicated module was not found in the PLUGIN_BASE path.  See the
USE directive.  This configuration has no bearing on the COMPILE_PERL
directive used to indicate using compiled perl documents.

=item MAX_EVAL_RECURSE (Alloy only)

Will use $Template::Alloy::MAX_EVAL_RECURSE if not present.  Default is 50.
Prevents runaway on the following:

    [% f = "[% f|eval %]" %][% f|eval %]

=item MAX_MACRO_RECURSE (Alloy only)

Will use $Template::Alloy::MAX_MACRO_RECURSE if not present.  Default is 50.
Prevents runaway on the following:

    [% MACRO f BLOCK %][% f %][% END %][% f %]

=item NAMESPACE

No Template::Namespace::Constants support.  Hashref of hashrefs representing
constants that will be folded into the template at compile time.

    Template::Alloy->new(NAMESPACE => {constants => {
         foo => 'bar',
    }});

Is the same as

    Template::Alloy->new(CONSTANTS => {
         foo => 'bar',
    });

Any number of hashes can be added to the NAMESPACE hash.

=item NEGATIVE_STAT_TTL (Not in TT)

Defaults to STAT_TTL which defaults to $STAT_TTL which defaults to 1.

Similar to STAT_TTL - but represents the time-to-live
seconds until a document that was not found is checked again against
the system for modifications.  Setting this number higher will allow for
fewer file system accesses.  Setting it to a negative number will allow
for the file system to be checked every hit.

=item NO_INCLUDES

Default false.  If true, calls to INCLUDE, PROCESS, WRAPPER and INSERT
will fail.  This option is also available when using the process method.

=item OUTPUT

Alternate way of passing in the output location for processed templates.
If process is not passed an output argument, it will look for this value.

See the process method for a listing of possible values.

=item OUTPUT_PATH

Base path for files written out via the process method or via the redirect
and file filters.  See the redirect virtual method and the process method
for more information.

=item PLUGINS

A hashref of mappings of plugin modules.

   PLUGINS => {
      Iterator => 'Template::Plugin::Iterator',
      DBI      => 'MyDBI',
   },

See the USE directive for more information.

=item PLUGIN_BASE

Default value is Template::Plugin.  The base module namespace
that template plugins will be looked for.  See the USE directive
for more information.  May be either a single namespace, or an arrayref
of namespaces.

=item POST_CHOMP

Set the type of chomping at the ending of a tag.
See the section on chomping for more information.

=item POST_PROCESS

Only available via when using the process interface.

A list of templates to be processed and appended to the content
after the main template.  During this processing the "template"
namespace will contain the name of the main file being processed.

This is useful for adding a global footer to all templates.

=item PRE_CHOMP

Set the type of chomping at the beginning of a tag.
See the section on chomping for more information.

=item PRE_DEFINE

Same as the VARIABLES configuration item.

=item PRE_PROCESS

Only available via when using the process interface.

A list of templates to be processed before and pre-pended to the content
before the main template.  During this processing the "template"
namespace will contain the name of the main file being processed.

This is useful for adding a global header to all templates.

=item PROCESS

Only available via when using the process interface.

Specify a file to use as the template rather than the one passed in
to the ->process method.

=item RECURSION

Boolean.  Default false.  Indicates that INCLUDED or PROCESSED files
can refer to each other in a circular manner.  Be careful about recursion.

=item RELATIVE

Boolean.  Default false.  If true, allows filenames to be specified
that are relative to the currently running process.

=item SEMICOLONS

Boolean.  Default false.  If true, then the syntax will require that
semi-colons separate multiple directives in the same tag.  This is
useful for keeping the syntax a little more clean as well as trouble
shooting some errors.

=item SHOW_UNDEFINED_INTERP (Not in TT)

Default false (default true in Velocity).  If INTERPOLATE is true,
interpolated dollar variables that return undef will be removed.  With
SHOW_UNDEFINED_INTERP set, undef values will leave the variable there.

    [% CONFIG INTERPOLATE => 1 %]
    [% SET foo = 1 %][% SET bar %]
    ($foo)($bar) ($!foo)($!bar)

Would print:

    (1)() (1)()

But the following:

    [% CONFIG INTERPOLATE => 1, SHOW_UNDEFINED_INTERP => 1 %]
    [% SET foo = 1 %][% SET bar %]
    ($foo)($bar) ($!foo)($!bar)

Would print:

    (1)($bar) (1)()

Note that you can use an exclamation point directly after the dollar
to make the variable silent.  This is similar to how Velocity works.

=item START_TAG

Set a string or regular expression to use as the opening delimiter
for TT.  Default is "[%".
You should be sure that the tag does not include grouping parens or
INTERPOLATE will not function properly.

=item STASH

Template::Alloy manages its own stash of variables.  You can pass a
Template::Stash or Template::Stash::XS object, but Template::Alloy
will copy all of values out of the object into its own stash.
Template::Alloy won't use any of the methods of the passed STASH
object.  The STASH option is only available when using the process
method.

=item STAT_TTL

Defaults to $STAT_TTL which defaults to 1.  Represents time-to-live
seconds until a cached in memory document is compared to the file
system for modifications.  Setting this number higher will allow for
fewer file system accesses.  Setting it to a negative number will allow
for the file system to be checked every hit.

=item STREAM

Defaults to false.  If set to true, generated template content will be
printed to the currently selected filehandle (default is STDOUT) as
soon as it is ready - there will be no buffering of the output.

The Stream role uses the Play role's directives (non-compiled_perl).

All directives and configuration work, except for the following
exceptions:

=over 4

=item CLEAR directive

Because the output is not buffered - the CLEAR directive would have no
effect.  The CLEAR directive will throw an error when STREAM is on.

=item TRIM configuration

Because the output is not buffered - trim operations cannot be played
on the output buffers.

=item WRAPPER configuration/directive

The WRAPPER configuration and directive items effectively turn off
STREAM since the WRAPPERS are generated in reverse order and because
the content is inserted into the middle of the WRAPPERS.  WRAPPERS
will still work, they just won't stream.

=item VARIOUS errors

Because the template is streaming, items that cause errors my result
in partially printed pages - since the error would occur part way
through the print.

=back

All output is printed directly to the currently selected filehandle
(defaults to STDOUT) via the CORE::print function.  Any output
parameter passed to process or process_simple will be ignored.

If you would like the output to go to another handle, you will need to
select that handle, process the template, and re-select STDOUT.

=item STRICT

Defaults to false.  If set to true, any undefined variable that is
encountered will cause the processing of the template to abort.  This
can be caught with a TRY block.  This can be useful for making sure
that the template only attempts to use variables that were correctly
initialized similar in spirit to Perl's "use strict."

When this occurs the strict_throw method is called.

See the STRICT_THROW configuration for additional options.

Similar functionality could be implemented using UNDEFINED_ANY.

The STRICT configuration item can be passed to new or it may also be
set during runtime using the CONFIG directive.  Once set though it
cannot be disabled for the duration of the current template and sub
components.  For example you could call [% CONFIG STRICT => 1 %] in
header.tt and strict mode would be enabled for the header.tt and any
sub templates processed by header.tt.

=item STRICT_THROW (not in TT)

Default undef.  Can be set to a subroutine which will be called when
STRICT is set and an undefined variable is processed.  It will be
passed the error type, error message, and a hashref of template
information containing the current component being processed, the
current outer template being processed, the identity reference for the
variable, and the stringified name of the identity.  This override can
be used for filtering allowable elements.

    my $ta = Template::Alloy->new({
        STRICT => 1,
        STRICT_THROW => sub {
            my ($ta, $err_type, $msg, $args) = @_;

            return if $args->{'component'} eq 'header.tt'
                      && $args->{'template'} eq 'main.html'
                      && $args->{'name'} eq 'foo.bar(1)'; # stringified identity name

            $ta->throw($err_type, $msg); # all other undefined variables die
        },
    });

=item SYNTAX (not in TT)

Defaults to "cet".  Indicates the syntax that will be used for parsing
included templates or eval'ed strings.  You can use the CONFIG
directive to change the SYNTAX on the fly (it will not affect
the syntax of the document currently being parsed).

The syntax may be passed in upper or lower case.

The available choices are:

    alloy - Template::Alloy style - the same as TT3
    tt3   - Template::Toolkit ver3 - same as Alloy
    tt2   - Template::Toolkit ver2 - almost the same as TT3
    tt1   - Template::Toolkit ver1 - almost the same as TT2
    ht    - HTML::Template - same as HTML::Template::Expr without EXPR
    hte   - HTML::Template::Expr
    js    - JavaScript style - requires compile_js to be set.
    jsr   - JavaScript Raw style - requires compile_js to be set.

Passing in a different syntax allows for the process method
to use a non-TT syntax and for the output method to use a non-HT
syntax.

The following is a sample of HTML::Template interface usage parsing
a Template::Toolkit style document.

    my $obj = Template::Alloy->new(filename => 'my/template.tt'
                                     syntax   => 'cet');
    $obj->param(\%swap);
    print $obj->output;

The following is a sample of Template::Toolkit interface usage parsing
a HTML::Template::Expr style document.

    my $obj = Template::Alloy->new(SYNTAX => 'hte');
    $obj->process('my/template.ht', \%swap);

You can use the define_syntax method to add another custom syntax to
the list of available options.

=item TAG_STYLE

Allow for setting the type of tag delimiters to use for parsing the TT.
See the TAGS directive for a listing of the available types.

=item TRIM

Remove leading and trailing whitespace from blocks and templates.
This operation is performed after all enclosed template tags have
been executed.

=item UNDEFINED_ANY

This is not a TT configuration option.  This option expects to be a code
ref that will be called if a variable is undefined during a call to play_expr.
It is passed the variable identity array as a single argument.  This
is most similar to the "undefined" method of Template::Stash.  It allows
for the "auto-defining" of a variable for use in the template.  It is
suggested that UNDEFINED_GET be used instead as UNDEFINED_ANY is a little
to general in defining variables.

You can also sub class the module and override the undefined_any method.

=item UNDEFINED_GET

This is not a TT configuration option.  This option expects to be a code
ref that will be called if a variable is undefined during a call to GET.
It is passed the variable identity array as a single argument.  This is more useful
than UNDEFINED_ANY in that it is only called during a GET directive
rather than in embedded expressions (such as [% a || b || c %]).

You can also sub class the module and override the undefined_get method.

=item V1DOLLAR

This allows for some compatibility with TT1 templates.  The only real
behavior change is that [% $foo %] becomes the same as [% foo %].  The
following is a basic table of changes invoked by using V1DOLLAR.

   With V1DOLLAR        Equivalent Without V1DOLLAR (Normal default)
   "[% foo %]"          "[% foo %]"
   "[% $foo %]"         "[% foo %]"
   "[% ${foo} %]"       "[% ${foo} %]"
   "[% foo.$bar %]"     "[% foo.bar %]"
   "[% ${foo.bar} %]"   "[% ${foo.bar} %]"
   "[% ${foo.$bar} %]"  "[% ${foo.bar} %]"
   "Text: $foo"         "Text: $foo"
   "Text: ${foo}"       "Text: ${foo}"
   "Text: ${$foo}"      "Text: ${foo}"

=item V2EQUALS

Default 1 in the TT syntax, defaults to 0 in the HTML::Template syntax.

If set to 1 then "==" is an alias for "eq" and "!= is an alias for
"ne".

    [% CONFIG V2EQUALS => 1 %][% ('7' == '7.0') || 0 %]
    [% CONFIG V2EQUALS => 0 %][% ('7' == '7.0') || 0 %]

    Prints

    0
    1

=item V2PIPE

Restores the behavior of the pipe operator to be compatible with TT2.

With V2PIPE = 1

    [%- BLOCK a %]b is [% b %]
    [% END %]
    [%- PROCESS a b => 237 | repeat(2) %]

    # output of block "a" with b set to 237 is passed to the repeat(2) filter

    b is 237
    b is 237

With V2PIPE = 0 (default)

    [%- BLOCK a %]b is [% b %]
    [% END %]
    [% PROCESS a b => 237 | repeat(2) %]

    # b set to 237 repeated twice, and b passed to block "a"

    b is 237237

=item VARIABLES

A hashref of variables to initialize the template stash with.  These
variables are available for use in any of the executed templates.
See the section on VARIABLES for the types of information that can be passed in.

=item VMETHOD_FUNCTIONS

Defaults to 1.  All scalar virtual methods are available as top level functions as well.
This is not true of TT2.  In Template::Alloy the following are equivalent:

    [% "abc".length %]
    [% length("abc") %]

You may set VMETHOD_FUNCTIONS to 0 to disable this behavior.

=item WRAPPER

Only available via when using the process interface.

Operates similar to the WRAPPER directive.  The option can be given a
single filename, or an arrayref of filenames that will be used to wrap
the processed content.  If an arrayref is passed the filenames are
processed in reverse order, so that the first filename specified will
end up being on the outside (surrounding all other wrappers).

   my $t = Template::Alloy->new(
       WRAPPER => ['my/wrappers/outer.html', 'my/wrappers/inner.html'],
   );

Content generated by the PRE_PROCESS and POST_PROCESS will come before
and after (respectively) the content generated by the WRAPPER
configuration item.

See the WRAPPER directive for more examples of how wrappers are constructed.

=back

=head1 CONFIGURATION (HTML::Template STYLE)

The following HTML::Template and HTML::Template::Expr
configuration variables are supported (in HTML::Template documentation order).
Note: for further discussion you can refer to the HT documentation.
Many of the variables mentioned in the TT CONFIGURATION section
apply here as well.  Unless noted, these items only apply when
using the output method.

Items may be passed in upper or lower case.  All passed items are resolved
to upper case.

These variables should be passed to the "new" constructor.

    my $obj = Template::Alloy->new(
        type   => 'filename',
        source => 'my/template.ht',
        die_on_bad_params => 1,
        loop_context_vars => 1,
        global_vars       => 1
        post_chomp => "=",
        pre_chomp  => "-",
    );

=over 4

=item TYPE

Can be one of filename, filehandle, arrayref, or scalarref.  Indicates what type
of input is in the "source" configuration item.

=item SOURCE

Stores where to read the input file.  The type is specified in the "type"
configuration item.

=item FILENAME

Indicates a filename to read the template from.  Same as putting the
filename in the "source" item and setting "type" to "filename".

Must be set to enable caching.

=item FILEHANDLE

Should contain an open filehandle to read the template from.  Same as
putting the filehandle in the "source" item and setting "type" to "filehandle".

Will not be cached.

=item ARRAYREF

Should contain an arrayref whose values are the lines of the template.  Same as
putting the arrayref in the "source" item and setting "type" to "arrayref".

Will not be cached.

=item SCALARREF

Should contain an reference to a scalar that contains the template.  Same as
putting the scalar ref in the "source" item and setting "type" to "scalarref".

Will not be cached.

=item CACHE

If set to one, then Alloy will use a global, in-memory document cache
to store compiled templates in between calls.  This is generally only
useful in a mod_perl environment.  The document is checked for a different
modification time at each request.

=item BLIND_CACHE

Same as with cache enabled, but will not check if the document has
been modified.

=item FILE_CACHE

If set to 1, will cache the compiled document on the file system.  If
true, file_cache_dir must be set.

=item FILE_CACHE_DIR

The directory where to store cached documents when file_cache is true.
This is similar to the TT compile_dir option.

=item DOUBLE_FILE_CACHE

Uses a combination of file_cache and cache.

=item PATH

Same as INCLUDE_PATH when using the process method.

=item ASSOCIATE

May be a single CGI object or an arrayref of objects.  The params
from these objects will be added to the params during the
output call.

=item CASE_SENSITIVE

Allow passed variables set through the param method, or the
associate configuration to be used case sensitively.  Default is
off.  It is highly suggested that this be set to 1.

=item LOOP_CONTEXT_VARS

Default false.  When true, calls to the loop directive will
create the following variables that give information about the
current iteration of the loop:

   __first__   - True on first iteration only
   __last__    - True on last iteration only
   __inner__   - True on any iteration that isn't first or last
   __odd__     - True on odd iterations
   __counter__ - The iteration count

These variables are also available to LOOPs run under
TT syntax if loop_context_vars is set and if QR_PRIVATE is set to 0.

=item GLOBAL_VARS.

Default true in HTE mode.  Default false in HT.  Allows top level
variables to be used in LOOPs.  When false, only variables defined
in the current LOOP iteration hashref will be available.

=item DEFAULT_ESCAPE

Controls the type of escape used on named variables in TMPL_VAR
directives.  Can be one of HTML, URL, or JS.  The values of
TMPL_VAR directives will be encoded with this type unless
they specify their own type via an ESCAPE attribute.

You may alternately use the AUTO_FILTER directive which can be
any of the item vmethod filters (you must use lower case when
specifying the AUTO_FILTER directive).  The AUTO_FILTER directive
will also be applied to TMPL_VAR EXPR and TMPL_GET items while
DEFAULT_ESCAPE only applies to TMPL_VAR NAME items.

=item NO_TT

Default false in 'hte' syntax.  Default true in 'ht' syntax.  If true,
no extended TT directives will be allowed.

The output method uses 'hte' syntax by default.

=back

=head1 SEMI PUBLIC METHODS

The following list of methods are other interesting methods of Alloy that
may be re-implemented by subclasses of Alloy.

=over 4

=item C<exception>

Creates an exception object blessed into the package listed in
Template::Alloy::Exception.

=item C<execute_tree>

Executes a parsed tree (returned from parse_tree)

=item C<play_expr>

Play the parsed expression.  Turns a variable identity array into the
parsed variable.  This method is also responsible for playing
operators and running virtual methods and filters.  The variable
identity array may also contain literal values, or operator identity
arrays.

=item C<include_filename>

Takes a file path, and resolves it into the full filename using
paths from INCLUDE_PATH or INCLUDE_PATHS.

=item C<_insert>

Resolves the file passed, and then returns its contents.

=item C<list_filters>

Dynamically loads the filters list from Template::Filters when a filter
is used that does not have a native implementation in Alloy.

=item C<load_template>

Given a filename or a string reference will return a "document" hashref
hash that contains the parsed tree.

    my $doc = $self->load_template($file); # errors die

This method handles the in-memory caching of the document.

=item C<load_tree>

Given the "document" hashref, will either load the parsed AST from
file (if configured to do so), or will load the content, parse the
content using the Parse role, and will return the tree.  File based
caching of the parsed AST happens here.

=item C<load_perl>

Only used if COMPILE_PERL is true (default is false).

Given the "document" hashref, will either load the compiled perl from
file (if configured to do so), or will load the AST using "load_tree",
will compile a new perl code document using the Compile role, and will
return the perl code.  File based caching of the compiled perl happens
here.

=item C<parse_tree>

Parses the passed string ref with the appropriate template syntax.

See L<Template::Alloy::Parse> for more details.

=item C<parse_expr>

Parses the passed string ref for a variable or expression.

See L<Template::Alloy::Parse> for more details.

=item C<parse_args>

See L<Template::Alloy::Parse> for more details.

=item C<set_variable>

Used to set a variable.  Expects a variable identity array and the
value to set.  It will autovifiy as necessary.

=item C<strict_throw>

Called during processing of template when STRICT configuration is
set and an uninitialized variable is met.  Arguments are the variable
identity reference.  Will call STRICT_THROW configuration item if set,
otherwise will call throw with a useful message.

=item C<throw>

Creates an exception object from the arguments and dies.

=item C<undefined_any>

Called during play_expr if a value is returned that is undefined.
This could be used to magically create variables on the fly.  This is
similar to Template::Stash::undefined.  It is suggested that
undefined_get be used instead.  Default behavior returns undef.  You
may also pass a coderef via the UNDEFINED_ANY configuration variable.
Also, you can try using the DEBUG => 'undef', configuration option
which will throw an error on undefined variables.

=item C<undefined_get>

Called when a variable is undefined during a GET directive.  This is
useful to see if a value that is about to get inserted into the text
is undefined.  undefined_any is a little too general for most cases.
Also, you may pass a coderef via the UNDEFINED_GET configuration
variable.

=back

=head1 OTHER UTILITY METHODS

The following is a brief list of other methods used by Alloy.  Generally, these
shouldn't be overwritten by subclasses.

=over 4

=item C<ast_string>

Returns perl code representation of a variable.

=item C<context>

Used to create a "pseudo" context object that allows for portability
of TT plugins, filters, and perl blocks that need a context object.
Uses the Template::Alloy::Context class.

=item C<debug_node>

Used to get debug info on a directive if DEBUG_DIRS is set.

=item C<get_line_number_by_index>

Used to turn string index position into line number

=item C<interpolate_node>

Used for parsing text nodes for dollar variables when interpolate is on.

=item C<play_operator>

Provided by the Operator role.  Allows for playing an operator AST.

See L<Template::Alloy::Operator> for more details.

=item C<apply_precedence>

Provided by the Parse role.  Allows for parsed operator array to be
translated to a tree based upon operator precedence.

=item C<_process>

Called by process and the PROCESS, INCLUDE and other directives.

=item C<slurp>

Reads contents of passed filename - throws file exception on error.

=item C<split_paths>

Used to split INCLUDE_PATH or other directives if an arrayref is not passed.

=item C<tt_var_string>

Returns a template toolkit representation of a variable.

=item C<_vars>

Return a reference to the current stash of variables.  This is currently only used
by the pseudo context object and may disappear at some point.

=back

=head1 THANKS

Thanks to Andy Wardley for creating Template::Toolkit.

Thanks to Sam Tregar for creating HTML::Template.

Thanks to David Lowe for creating Text::Tmpl.

Thanks to the Apache Velocity guys.

Thanks to Ben Grimm for a patch to allow passing a parsed document to the ->process method.

Thanks to David Warring for finding a parse error in HTE syntax.

Thanks to Carl Franks for adding the base ENCODING support.

=head1 AUTHOR

Paul Seamons <paul@seamons.com>

=head1 LICENSE

This module may be distributed under the same terms as Perl itself.

=cut