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
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
|
#!/usr/bin/env perl
# This chunk of stuff was generated by App::FatPacker. To find the original
# file's code, look for the end of this BEGIN block or the string 'FATPACK'
BEGIN {
my %fatpacked;
$fatpacked{"Pod/POM.pm"} = <<'POD_POM';
#============================================================= -*-Perl-*-
#
# Pod::POM
#
# DESCRIPTION
# Parses POD from a file or text string and builds a tree structure,
# hereafter known as the POD Object Model (POM).
#
# AUTHOR
# Andy Wardley <abw@wardley.org>
#
# Andrew Ford <A.Ford@ford-mason.co.uk> (co-maintainer as of 03/2009)
#
# COPYRIGHT
# Copyright (C) 2000-2009 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: POM.pm 88 2010-04-02 13:37:41Z ford $
#
#========================================================================
package Pod::POM;
require 5.004;
use strict;
use Pod::POM::Constants qw( :all );
use Pod::POM::Nodes;
use Pod::POM::View::Pod;
use vars qw( $VERSION $DEBUG $ERROR $ROOT $TEXTSEQ $DEFAULT_VIEW );
use base qw( Exporter );
$VERSION = '0.27';
$DEBUG = 0 unless defined $DEBUG;
$ROOT = 'Pod::POM::Node::Pod'; # root node class
$TEXTSEQ = 'Pod::POM::Node::Sequence'; # text sequence class
$DEFAULT_VIEW = 'Pod::POM::View::Pod'; # default view class
#------------------------------------------------------------------------
# allow 'meta' to be specified as a load option to activate =meta tags
#------------------------------------------------------------------------
use vars qw( @EXPORT_FAIL @EXPORT_OK $ALLOW_META );
@EXPORT_OK = qw( meta );
@EXPORT_FAIL = qw( meta );
$ALLOW_META = 0;
sub export_fail {
my $class = shift;
my $meta = shift;
return ($meta, @_) unless $meta eq 'meta';
$ALLOW_META++;
return @_;
}
#------------------------------------------------------------------------
# new(\%options)
#------------------------------------------------------------------------
sub new {
my $class = shift;
my $config = ref $_[0] eq 'HASH' ? shift : { @_ };
bless {
CODE => $config->{ code } || 0,
WARN => $config->{ warn } || 0,
META => $config->{ meta } || $ALLOW_META,
WARNINGS => [ ],
FILENAME => '',
ERROR => '',
}, $class;
}
#------------------------------------------------------------------------
# parse($text_or_file)
#
# General purpose parse method which attempts to Do The Right Thing in
# calling parse_file() or parse_text() according to the argument
# passed. A hash reference can be specified that contains a 'text'
# or 'file' key and corresponding value. Otherwise, the argument can
# be a reference to an input handle which is passed off to parse_file().
# If the argument is a text string that contains '=' at the start of
# any line then it is treated as Pod text and passed to parse_text(),
# otherwise it is assumed to be a filename and passed to parse_file().
#------------------------------------------------------------------------
sub parse {
my ($self, $input) = @_;
my $result;
if (ref $input eq 'HASH') {
if ($input = $input->{ text }) {
$result = $self->parse_text($input, $input->{ name });
}
elsif ($input = $input->{ file }) {
$result = $self->parse_file($input);
}
else {
$result = $self->error("no 'text' or 'file' specified");
}
}
elsif (ref $input || $input !~ /^=/m) { # doesn't look like POD text
$result = $self->parse_file($input);
}
else { # looks like POD text
$result = $self->parse_text($input);
}
return $result;
}
#------------------------------------------------------------------------
# parse_file($filename_or_handle)
#
# Reads the content of a Pod file specified by name or file handle, and
# passes it to parse_text() for parsing.
#------------------------------------------------------------------------
sub parse_file {
my ($self, $file) = @_;
my ($text, $name);
if (ref $file) { # assume open filehandle
local $/ = undef;
$name = '<filehandle>';
$text = <$file>;
}
else { # a file which must be opened
local *FP;
local $/ = undef;
$name = ( $file eq '-' ? '<standard input>' : $file );
open(FP, $file) || return $self->error("$file: $!");
$text = <FP>;
close(FP);
}
$self->parse_text($text, $name);
}
#------------------------------------------------------------------------
# parse_text($text, $name)
#
# Main parser method. Scans the input text for Pod sections and splits
# them into paragraphs. Builds a tree of Pod::POM::Node::* objects
# to represent the Pod document in object model form.
#------------------------------------------------------------------------
sub parse_text {
my ($self, $text, $name) = @_;
my ($para, $paralen, $gap, $type, $line, $inpod, $code, $result, $verbatim);
my $warn = $self->{ WARNINGS } = [ ];
my @stack = ( );
my $item = $ROOT->new($self);
return $self->error($ROOT->error())
unless defined $item;
push(@stack, $item);
$name = '<input text>' unless defined $name;
$self->{ FILENAME } = $name;
$code = $self->{ CODE };
$line = \$self->{ LINE };
$$line = 1;
$inpod = 0;
my @encchunks = split /^(=encoding.*)/m, $text;
$text = shift @encchunks;
while (@encchunks) {
my($encline,$chunk) = splice @encchunks, 0, 2;
require Encode;
my($encoding) = $encline =~ /^=encoding\s+(\S+)/;
Encode::from_to($chunk, $encoding, "utf8");
Encode::_utf8_on($chunk);
# $text .= "xxx$encline";
$text .= $chunk;
}
# patch from JJ
# while ($text =~ /(?:(.*?)(\n{2,}))|(.+$)/sg) {
while ($text =~ /(?:(.*?)((?:\s*\n){2,}))|(.+$)/sg) {
($para, $gap) = defined $1 ? ($1, $2) : ($3, '');
if ($para =~ s/^==?(\w+)\s*//) {
$type = $1;
# switch on for =pod or any other =cmd, switch off for =cut
if ($type eq 'pod') { $inpod = 1; next }
elsif ($type eq 'cut') { $inpod = 0; next }
else { $inpod = 1 };
if ($type eq 'meta') {
$self->{ META }
? $stack[0]->metadata(split(/\s+/, $para, 2))
: $self->warning("metadata not allowed", $name, $$line);
next;
}
}
elsif (! $inpod) {
next unless $code;
$type = 'code';
$para .= $gap;
$gap = '';
}
elsif ($para =~ /^\s+/) {
$verbatim .= $para;
$verbatim .= $gap;
next;
}
else {
$type = 'text';
chomp($para); # catches last line in file
}
if ($verbatim) {
while(@stack) {
$verbatim =~ s/\s+$//s;
$result = $stack[-1]->add($self, 'verbatim', $verbatim);
if (! defined $result) {
$self->warning($stack[-1]->error(), $name, $$line);
undef $verbatim;
last;
}
elsif (ref $result) {
push(@stack, $result);
undef $verbatim;
last;
}
elsif ($result == REDUCE) {
pop @stack;
undef $verbatim;
last;
}
elsif ($result == REJECT) {
$self->warning($stack[-1]->error(), $name, $$line);
pop @stack;
}
elsif (@stack == 1) {
$self->warning("unexpected $type", $name, $$line);
undef $verbatim;
last;
}
else {
pop @stack;
}
}
}
while(@stack) {
$result = $stack[-1]->add($self, $type, $para);
if (! defined $result) {
$self->warning($stack[-1]->error(), $name, $$line);
last;
}
elsif (ref $result) {
push(@stack, $result);
last;
}
elsif ($result == REDUCE) {
pop @stack;
last;
}
elsif ($result == REJECT) {
$self->warning($stack[-1]->error(), $name, $$line);
pop @stack;
}
elsif (@stack == 1) {
$self->warning("unexpected $type", $name, $$line);
last;
}
else {
pop @stack;
}
}
}
continue {
$$line += ($para =~ tr/\n//);
$$line += ($gap =~ tr/\n//);
}
if ($verbatim) {
while(@stack) {
$verbatim =~ s/\s+$//s;
$result = $stack[-1]->add($self, 'verbatim', $verbatim);
if (! defined $result) {
$self->warning($stack[-1]->error(), $name, $$line);
undef $verbatim;
last;
}
elsif (ref $result) {
push(@stack, $result);
undef $verbatim;
last;
}
elsif ($result == REDUCE) {
pop @stack;
undef $verbatim;
last;
}
elsif ($result == REJECT) {
$self->warning($stack[-1]->error(), $name, $$line);
pop @stack;
}
elsif (@stack == 1) {
$self->warning("unexpected $type", $name, $$line);
undef $verbatim;
last;
}
else {
pop @stack;
}
}
}
return $stack[0];
}
#------------------------------------------------------------------------
# parse_sequence($text)
#
# Parse a text paragraph to identify internal sequences (e.g. B<foo>)
# which may be nested within each other. Returns a simple scalar (no
# embedded sequences) or a reference to a Pod::POM::Text object.
#------------------------------------------------------------------------
sub parse_sequence {
my ($self, $text) = @_;
my ($cmd, $lparen, $rparen, $plain);
my ($name, $line, $warn) = @$self{ qw( FILENAME LINE WARNINGS ) };
my @stack;
push(@stack, [ '', '', 'EOF', $name, $line, [ ] ] );
while ($text =~ /
(?: ([A-Z]) (< (?:<+\s)?) ) # open
| ( (?:\s>+)? > ) # or close
| (?: (.+?) # or text...
(?= # ...up to
(?: [A-Z]< ) # open
| (?: (?: \s>+)? > ) # or close
| $ # or EOF
)
)
/gxs) {
if (defined $1) {
($cmd, $lparen) = ($1, $2);
$lparen =~ s/\s$//;
($rparen = $lparen) =~ tr/</>/;
push(@stack, [ $cmd, $lparen, $rparen, $name, $line, [ ] ]);
}
elsif (defined $3) {
$rparen = $3;
$rparen =~ s/^\s+//;
if ($rparen eq $stack[-1]->[RPAREN]) {
$cmd = $TEXTSEQ->new(pop(@stack))
|| return $self->error($TEXTSEQ->error());
push(@{ $stack[-1]->[CONTENT] }, $cmd);
}
else {
$self->warning((scalar @stack > 1
? "expected '$stack[-1]->[RPAREN]' not '$rparen'"
: "spurious '$rparen'"), $name, $line);
push(@{ $stack[-1]->[CONTENT] }, $rparen);
}
}
elsif (defined $4) {
$plain = $4;
push(@{ $stack[-1]->[CONTENT] }, $plain);
$line += ($plain =~ tr/\n//);
}
else {
$self->warning("unexpected end of input", $name, $line);
last;
}
}
while (@stack > 1) {
$cmd = pop @stack;
$self->warning("unterminated '$cmd->[CMD]$cmd->[LPAREN]' starting",
$name, $cmd->[LINE]);
$cmd = $TEXTSEQ->new($cmd)
|| $self->error($TEXTSEQ->error());
push(@{ $stack[-1]->[CONTENT] }, $cmd);
}
return $TEXTSEQ->new(pop(@stack))
|| $self->error($TEXTSEQ->error());
}
#------------------------------------------------------------------------
# default_view($viewer)
#
# Accessor method to return or update the $DEFVIEW package variable,
# loading the module for any package name specified.
#------------------------------------------------------------------------
sub default_view {
my ($self, $viewer) = @_;
return $DEFAULT_VIEW unless $viewer;
unless (ref $viewer) {
my $file = $viewer;
$file =~ s[::][/]g;
$file .= '.pm';
eval { require $file };
return $self->error($@) if $@;
}
return ($DEFAULT_VIEW = $viewer);
}
#------------------------------------------------------------------------
# warning($msg, $file, $line)
#
# Appends a string of the form " at $file line $line" to $msg if
# $file is specified and then stores $msg in the internals
# WARNINGS list. If the WARN option is set then the warning is
# raised, either via warn(), or by dispatching to a subroutine
# when WARN is defined as such.
#------------------------------------------------------------------------
sub warning {
my ($self, $msg, $file, $line) = @_;
my $warn = $self->{ WARN };
$line = 'unknown' unless defined $line && length $line;
$msg .= " at $file line $line" if $file;
push(@{ $self->{ WARNINGS } }, $msg);
if (ref $warn eq 'CODE') {
&$warn($msg);
}
elsif ($warn) {
warn($msg, "\n");
}
}
#------------------------------------------------------------------------
# warnings()
#
# Returns a reference to the (possibly empty) list of warnings raised by
# the most recent call to any of the parse_XXX() methods
#------------------------------------------------------------------------
sub warnings {
my $self = shift;
return wantarray ? @{ $self->{ WARNINGS } } : $self->{ WARNINGS };
}
#------------------------------------------------------------------------
# error($msg)
#
# Sets the internal ERROR member and returns undef when called with an
# argument(s), returns the current value when called without.
#------------------------------------------------------------------------
sub error {
my $self = shift;
my $errvar;
{
no strict qw( refs );
if (ref $self) {
$errvar = \$self->{ ERROR };
}
else {
$errvar = \${"$self\::ERROR"};
}
}
if (@_) {
$$errvar = ref($_[0]) ? shift : join('', @_);
return undef;
}
else {
return $$errvar;
}
}
sub DEBUG {
print STDERR "DEBUG: ", @_ if $DEBUG;
}
1;
__END__
=head1 NAME
Pod::POM - POD Object Model
=head1 SYNOPSIS
use Pod::POM;
my $parser = Pod::POM->new(\%options);
# parse from a text string
my $pom = $parser->parse_text($text)
|| die $parser->error();
# parse from a file specified by name or filehandle
my $pom = $parser->parse_file($file)
|| die $parser->error();
# parse from text or file
my $pom = $parser->parse($text_or_file)
|| die $parser->error();
# examine any warnings raised
foreach my $warning ($parser->warnings()) {
warn $warning, "\n";
}
# print table of contents using each =head1 title
foreach my $head1 ($pom->head1()) {
print $head1->title(), "\n";
}
# print each section
foreach my $head1 ($pom->head1()) {
print $head1->title(), "\n";
print $head1->content();
}
# print the entire document as HTML
use Pod::POM::View::HTML;
print Pod::POM::View::HTML->print($pom);
# create custom view
package My::View;
use base qw( Pod::POM::View::HTML );
sub view_head1 {
my ($self, $item) = @_;
return '<h1>',
$item->title->present($self),
"</h1>\n",
$item->content->present($self);
}
package main;
print My::View->print($pom);
=head1 DESCRIPTION
This module implements a parser to convert Pod documents into a simple
object model form known hereafter as the Pod Object Model. The object
model is generated as a hierarchical tree of nodes, each of which
represents a different element of the original document. The tree can
be walked manually and the nodes examined, printed or otherwise
manipulated. In addition, Pod::POM supports and provides view objects
which can automatically traverse the tree, or section thereof, and
generate an output representation in one form or another.
Let's look at a typical Pod document by way of example.
=head1 NAME
My::Module - just another My::Module
=head1 DESCRIPTION
This is My::Module, a deeply funky piece of Perl code.
=head2 METHODS
My::Module implements the following methods
=over 4
=item new(\%config)
This is the constructor method. It accepts the following
configuration options:
=over 4
=item name
The name of the thingy.
=item colour
The colour of the thingy.
=back
=item print()
This prints the thingy.
=back
=head1 AUTHOR
My::Module was written by me E<lt>me@here.orgE<gt>
This document contains 3 main sections, NAME, DESCRIPTION and
AUTHOR, each of which is delimited by an opening C<=head1> tag.
NAME and AUTHOR each contain only a single line of text, but
DESCRIPTION is more interesting. It contains a line of text
followed by the C<=head2> subsection, METHODS. This contains
a line of text and a list extending from the C<=over 4> to the
final C<=back> just before the AUTHOR section starts. The list
contains 2 items, C<new(\%config)>, which itself contains some
text and a list of 2 items, and C<print()>.
Presented as plain text and using indentation to indicate the element
nesting, the model then looks something like this :
NAME
My::Module - just another My::Module
DESCRIPTION
This is My::Module, a deeply funky piece of Perl code.
METHODS
My::Module implements the following methods
* new(\%config)
This is the constructor method. It accepts the
following configuration options:
* name
The name of the thingy.
* colour
The colour of the thingy.
* item print()
This prints the thingy.
AUTHOR
My::Myodule was written by me <me@here.org>
Those of you familiar with XML may prefer to think of it in the
following way:
<pod>
<head1 title="NAME">
<p>My::Module - just another My::Module</p>
</head1>
<head1 title="DESCRIPTION">
<p>This is My::Module, a deeply funky piece of
Perl code.</p>
<head2 title="METHODS">
<p>My::Module implements the following methods</p>
<over indent=4>
<item title="item new(\%config)">
<p>This is the constructor method. It accepts
the following configuration options:</p>
<over indent=4>
<item title="name">
<p>The name of the thingy.</p>
</item>
<item title="colour">
<p>The colour of the thingy.</p>
</item>
</over>
</item>
<item title="print()">
<p>This prints the thingy.</p>
</item>
</over>
</head2>
</head1>
<head1 title="AUTHOR">
<p>My::Myodule was written by me <me@here.org>
</head1>
</pod>
Notice how we can make certain assumptions about various elements.
For example, we can assume that any C<=head1> section we find begins a
new section and implicitly ends any previous section. Similarly, we
can assume an C<=item> ends when the next one begins, and so on. In
terms of the XML example shown above, we are saying that we're smart
enough to add a C<E<lt>/head1E<gt>> element to terminate any
previously opened C<E<lt>head1E<gt>> when we find a new C<=head1> tag
in the input document.
However you like to visualise the content, it all comes down to the
same underlying model. The job of the Pod::POM module is to read an
input Pod document and build an object model to represent it in this
structured form.
Each node in the tree (i.e. element in the document) is represented
by a Pod::POM::Node::* object. These encapsulate the attributes for
an element (such as the title for a C<=head1> tag) and also act as
containers for further Pod::POM::Node::* objects representing the
content of the element. Right down at the leaf nodes, we have simple
object types to represent formatted and verbatim text paragraphs and
other basic elements like these.
=head2 Parsing Pod
The Pod::POM module implements the methods parse_file($file),
parse_text($text) and parse($file_or_text) to parse Pod files and
input text. They return a Pod::POM::Node::Pod object to represent the
root of the Pod Object Model, effectively the C<E<lt>podE<gt>> element
in the XML tree shown above.
use Pod::POM;
my $parser = Pod::POM->new();
my $pom = $parser->parse_file($filename)
|| die $parser->error();
The parse(), parse_text() and parse_file() methods return
undef on error. The error() method can be called to retrieve the
error message generated. Parsing a document may also generate
non-fatal warnings. These can be retrieved via the warnings() method
which returns a reference to a list when called in scalar context or a
list of warnings when called in list context.
foreach my $warn ($parser->warnings()) {
warn $warn, "\n";
}
Alternatively, the 'warn' configuration option can be set to have
warnings automatically raised via C<warn()> as they are encountered.
my $parser = Pod::POM->new( warn => 1 );
=head2 Walking the Object Model
Having parsed a document into an object model, we can then select
various items from it. Each node implements methods (via AUTOLOAD)
which correspond to the attributes and content elements permitted
within in.
So to fetch the list of '=head1' sections within our parsed document,
we would do the following:
my $sections = $pom->head1();
Methods like this will return a list of further Pod::POM::Node::*
objects when called in list context or a reference to a list when
called in scalar context. In the latter case, the list is blessed
into the Pod::POM::Node::Content class which gives it certain
magical properties (more on that later).
Given the list of Pod::POM::Node::Head1 objects returned by the above,
we can print the title attributes of each like this:
foreach my $s (@$sections) {
print $s->title();
}
Let's look at the second section, DESCRIPTION.
my $desc = $sections->[1];
We can print the title of each subsection within it:
foreach my $ss ($desc->head2()) {
print $ss->title();
}
Hopefully you're getting the idea by now, so here's a more studly
example to print the title for each item contained in the first list
within the METHODS section:
foreach my $item ($desc->head2->[0]->over->[0]->item) {
print $item->title(), "\n";
}
=head2 Element Content
This is all well and good if you know the precise structure of a
document in advance. For those more common cases when you don't,
each node that can contain other nodes provides a 'content' method
to return a complete list of all the other nodes that it contains.
The 'type' method can be called on any node to return its element
type (e.g. 'head1', 'head2', 'over', item', etc).
foreach my $item ($pom->content()) {
my $type = $item->type();
if ($type eq 'head1') {
...
}
elsif ($type eq 'head2') {
...
}
...
}
The content for an element is represented by a reference to a list,
blessed into the Pod::POM::Node::Content class. This provides some
magic in the form of an overloaded stringification operator which
will automatically print the contents of the list if you print
the object itself. In plain English, or rather, in plain Perl,
this means you can do things like the following:
foreach my $head1 ($pom->head1()) {
print '<h1>', $head1->title(), "</h1>\n\n";
print $head1->content();
}
# print all the root content
foreach my $item ($pom->content()) {
print $item;
}
# same as above
print $pom->content();
In fact, all Pod::POM::Node::* objects provide this same magic, and
will attempt to Do The Right Thing to present themselves in the
appropriate manner when printed. Thus, the following are all valid.
print $pom; # entire document
print $pom->content; # content of document
print $pom->head1->[0]; # just first section
print $pom->head1; # print all sections
foreach my $h1 ($pom->head1()) {
print $h1->head2(); # print all subsections
}
=head2 Output Views
To understand how the different elements go about presenting
themselves in "the appropriate manner", we must introduce the concept
of a view. A view is quite simply a particular way of looking at the
model. In real terms, we can think of a view as being some kind of
output type generated by a pod2whatever converter. Notionally we can
think in terms of reading in an input document, building a Pod Object
Model, and then generating an HTML view of the document, and/or a
LaTeX view, a plain text view, and so on.
A view is represented in this case by an object class which contains
methods for displaying each of the different element types that could
be encountered in any Pod document. There's a method for displaying
C<=head1> sections (view_head1()), another method for displaying
C<=head2> sections (view_head2()), one for C<=over> (view_over()),
another for C<=item> (view_item()) and so on.
If we happen to have a reference to a $node and we know it's a 'head1'
node, then we can directly call the right view method to have it
displayed properly:
$view = 'Pod::POM::View::HTML';
$view->view_head1($node);
Thus our earlier example can be modified to be I<slightly> less laborious
and I<marginally> more flexible.
foreach my $node ($pom->content) {
my $type = $node->type();
if ($type eq 'head1') {
print $view->view_head1($node);
}
elsif ($type eq 'head2') {
print $view->view_head2($node);
}
...
}
However, this is still far from ideal. To make life easier, each
Pod::POM::Node::* class inherits (or possibly redefines) a
C<present($view)> method from the Pod::POM::Node base class. This method
expects a reference to a view object passed as an argument, and it
simply calls the appropriate view_xxx() method on the view object,
passing itself back as an argument. In object parlance, this is known
as "double dispatch". The beauty of it is that you don't need to know
what kind of node you have to be able to print it. You simply pass
it a view object and leave it to work out the rest.
foreach my $node ($pom->content) {
print $node->present($view);
}
If $node is a Pod::POM::Node::Head1 object, then the view_head1($node)
method gets called against the $view object. Otherwise, if it's a
Pod::POM::Node::Head2 object, then the view_head2($node) method is
dispatched. And so on, and so on, with each node knowing what it is
and where it's going as if determined by some genetically pre-programmed
instinct. Fullfilling their destinies, so to speak.
Double dispatch allows us to do away with all the explicit type
checking and other nonsense and have the node objects themselves worry
about where they should be routed to. At the cost of an extra method
call per node, we get programmer convenience, and that's usually
a Good Thing.
Let's have a look at how the view and node classes might be
implemented.
package Pod::POM::View::HTML;
sub view_pod {
my ($self, $node) = @_;
return $node->content->present($self);
}
sub view_head1 {
my ($self, $node) = @_;
return "<h1>", $node->title->present($self), "</h1>\n\n"
. $node->content->present($self);
}
sub view_head2 {
my ($self, $node) = @_;
return "<h2>", $node->title->present($self), "</h2>\n\n"
. $node->content->present($self);
}
...
package Pod::POM::Node::Pod;
sub present {
my ($self, $view) = @_;
$view->view_pod($self);
}
package Pod::POM::Node::Head1;
sub present {
my ($self, $view) = @_;
$view->view_head1($self);
}
package Pod::POM::Node::Head2;
sub present {
my ($self, $view) = @_;
$view->view_head2($self);
}
...
Some of the view_xxx methods make calls back against the node objects
to display their attributes and/or content. This is shown in, for
example, the view_head1() method above, where the method prints the
section title in C<E<lt>h1E<gt>>...C<E<lt>h1E<gt>> tags, followed by
the remaining section content.
Note that the title() attribute is printed by calling its present()
method, passing on the reference to the current view. Similarly,
the content present() method is called giving it a chance to Do
The Right Thing to present itself correctly via the view object.
There's a good chance that the title attribute is going to be regular
text, so we might be tempted to simply print the title rather than
call its present method.
sub view_head1 {
my ($self, $node) = @_;
# not recommended, prefer $node->title->present($self)
return "<h1>", $node->title(), "</h1>\n\n", ...
}
However, it is entirely valid for titles and other element attributes,
as well as regular, formatted text blocks to contain code sequences,
such like C<BE<lt>thisE<gt>> and C<IE<lt>thisE<gt>>. These are used
to indicate different markup styles, mark external references or index
items, and so on. What's more, they can be C<BE<lt>nested
IE<lt>indefinatelyE<gt>E<gt>>. Pod::POM takes care of all this by
parsing such text, along with any embedded sequences, into Yet Another
Tree, the root node of which is a Pod::POM::Node::Text object,
possibly containing other Pod::POM::Node::Sequence objects. When the
text is presented, the tree is automatically walked and relevant
callbacks made against the view for the different sequence types. The
methods called against the view are all prefixed 'view_seq_', e.g.
'view_seq_bold', 'view_seq_italic'.
Now the real magic comes into effect. You can define one view to
render bold/italic text in one style:
package My::View::Text;
use base qw( Pod::POM::View::Text );
sub view_seq_bold {
my ($self, $text) = @_;
return "*$text*";
}
sub view_seq_italic {
my ($self, $text) = @_;
return "_$text_";
}
And another view to render it in a different style:
package My::View::HTML;
use base qw( Pod::POM::View::HTML );
sub view_seq_bold {
my ($self, $text) = @_;
return "<b>$text</b>";
}
sub view_seq_italic {
my ($self, $text) = @_;
return "<i>$text</i>";
}
Then, you can easily view a Pod Object Model in either style:
my $text = 'My::View::Text';
my $html = 'My::View::HTML';
print $pom->present($text);
print $pom->present($html);
And you can apply this technique to any node within the object
model.
print $pom->head1->[0]->present($text);
print $pom->head1->[0]->present($html);
In these examples, the view passed to the present() method has
been a class name. Thus, the view_xxx methods get called as
class methods, as if written:
My::View::Text->view_head1(...);
If your view needs to maintain state then you can create a view object
and pass that to the present() method.
my $view = My::View->new();
$node->present($view);
In this case the view_xxx methods get called as object methods.
sub view_head1 {
my ($self, $node) = @_;
my $title = $node->title();
if ($title eq 'NAME' && ref $self) {
$self->{ title } = $title();
}
$self->SUPER::view_head1($node);
}
Whenever you print a Pod::POM::Node::* object, or do anything to cause
Perl to stringify it (such as including it another quoted string "like
$this"), then its present() method is automatically called. When
called without a view argument, the present() method uses the default
view specified in $Pod::POM::DEFAULT_VIEW, which is, by default,
'Pod::POM::View::Pod'. This view regenerates the original Pod
document, although it should be noted that the output generated may
not be exactly the same as the input. The parser is smart enough to
detect some common errors (e.g. not terminating an C<=over> with a C<=back>)
and correct them automatically. Thus you might find a C<=back>
correctly placed in the output, even if you forgot to add it to the
input. Such corrections raise non-fatal warnings which can later
be examined via the warnings() method.
You can update the $Pod::POM::DEFAULT_VIEW package variable to set the
default view, or call the default_view() method. The default_view()
method will automatically load any package you specify. If setting
the package variable directly, you should ensure that any packages
required have been pre-loaded.
use My::View::HTML;
$Pod::POM::DEFAULT_VIEW = 'My::View::HTML';
or
Pod::POM->default_view('My::View::HTML');
=head2 Template Toolkit Views
One of the motivations for writing this module was to make it easier
to customise Pod documentation to your own look and feel or local
formatting conventions. By clearly separating the content
(represented by the Pod Object Model) from the presentation style
(represented by one or more views) it becomes much easier to achieve
this.
The latest version of the Template Toolkit (2.06 at the time of
writing) provides a Pod plugin to interface to this module. It also
implements a new (but experimental) VIEW directive which can be used
to build different presentation styles for converting Pod to other
formats. The Template Toolkit is available from CPAN:
http://www.cpan.org/modules/by-module/Template/
Template Toolkit views are similar to the Pod::POM::View objects
described above, except that they allow the presentation style for
each Pod component to be written as a template file or block rather
than an object method. The precise syntax and structure of the VIEW
directive is subject to change (given that it's still experimental),
but at present it can be used to define a view something like this:
[% VIEW myview %]
[% BLOCK view_head1 %]
<h1>[% item.title.present(view) %]</h1>
[% item.content.present(view) %]
[% END %]
[% BLOCK view_head2 %]
<h2>[% item.title.present(view) %]</h2>
[% item.content.present(view) %]
[% END %]
...
[% END %]
A plugin is provided to interface to the Pod::POM module:
[% USE pod %]
[% pom = pod.parse('/path/to/podfile') %]
The returned Pod Object Model instance can then be navigated and
presented via the view in almost any way imaginable:
<h1>Table of Contents</h1>
<ul>
[% FOREACH section = pom.head1 %]
<li>[% section.title.present(view) %]
[% END %]
</ul>
<hr>
[% FOREACH section = pom.head1 %]
[% section.present(myview) %]
[% END %]
You can either pass a reference to the VIEW (myview) to the
present() method of a Pod::POM node:
[% pom.present(myview) %] # present entire document
Or alternately call the print() method on the VIEW, passing the
Pod::POM node as an argument:
[% myview.print(pom) %]
Internally, the view calls the present() method on the node,
passing itself as an argument. Thus it is equivalent to the
previous example.
The Pod::POM node and the view conspire to "Do The Right Thing" to
process the right template block for the node. A reference to the
node is available within the template as the 'item' variable.
[% BLOCK view_head2 %]
<h2>[% item.title.present(view) %]</h2>
[% item.content.present(view) %]
[% END %]
The Template Toolkit documentation contains further information on
defining and using views. However, as noted above, this may be
subject to change or incomplete pending further development of the
VIEW directive.
=head1 METHODS
=head2 new(\%config)
Constructor method which instantiates and returns a new Pod::POM
parser object.
use Pod::POM;
my $parser = Pod::POM->new();
A reference to a hash array of configuration options may be passed as
an argument.
my $parser = Pod::POM->new( { warn => 1 } );
For convenience, configuration options can also be passed as a list of
(key =E<gt> value) pairs.
my $parser = Pod::POM->new( warn => 1 );
The following configuration options are defined:
=over 4
=item code
This option can be set to have all non-Pod parts of the input document
stored within the object model as 'code' elements, represented by
objects of the Pod::POM::Node::Code class. It is disabled by default
and code sections are ignored.
my $parser = Pod::POM->new( code => 1 );
my $podpom = $parser->parse(\*DATA);
foreach my $code ($podpom->code()) {
print "<pre>$code</pre>\n";
}
__DATA__
This is some program code.
=head1 NAME
...
This will generate the output:
<pre>This is some program code.</pre>
Note that code elements are stored within the POM element in which
they are encountered. For example, the code element below embedded
within between Pod sections is stored in the array which can be
retrieved by calling C<$podpom-E<gt>head1-E<gt>[0]-E<gt>code()>.
=head1 NAME
My::Module::Name;
=cut
Some program code embedded in Pod.
=head1 SYNOPSIS
...
=item warn
Non-fatal warnings encountered while parsing a Pod document are stored
internally and subsequently available via the warnings() method.
my $parser = Pod::POM->new();
my $podpom = $parser->parse_file($filename);
foreach my $warning ($parser->warnings()) {
warn $warning, "\n";
}
The 'warn' option can be set to have warnings raised automatically
via C<warn()> as and when they are encountered.
my $parser = Pod::POM->new( warn => 1 );
my $podpom = $parser->parse_file($filename);
If the configuration value is specified as a subroutine reference then
the code will be called each time a warning is raised, passing the
warning message as an argument.
sub my_warning {
my $msg = shift;
warn $msg, "\n";
};
my $parser = Pod::POM->new( warn => \&my_warning );
my $podpom = $parser->parse_file($filename);
=item meta
The 'meta' option can be set to allow C<=meta> tags within the Pod
document.
my $parser = Pod::POM->new( meta => 1 );
my $podpom = $parser->parse_file($filename);
This is an experimental feature which is not part of standard
POD. For example:
=meta author Andy Wardley
These are made available as metadata items within the root
node of the parsed POM.
my $author = $podpom->metadata('author');
See the L<METADATA|METADATA> section below for further information.
=back
=head2 parse_file($file)
Parses the file specified by name or reference to a file handle.
Returns a reference to a Pod::POM::Node::Pod object which represents
the root node of the Pod Object Model on success. On error, undef
is returned and the error message generated can be retrieved by calling
error().
my $podpom = $parser->parse_file($filename)
|| die $parser->error();
my $podpom = $parser->parse_file(\*STDIN)
|| die $parser->error();
Any warnings encountered can be examined by calling the
warnings() method.
foreach my $warn ($parser->warnings()) {
warn $warn, "\n";
}
=head2 parse_text($text)
Parses the Pod text string passed as an argument into a Pod Object
Model, as per parse_file().
=head2 parse($text_or_$file)
General purpose method which attempts to Do The Right Thing in calling
parse_file() or parse_text() according to the argument passed.
A hash reference can be passed as an argument that contains a 'text'
or 'file' key and corresponding value.
my $podpom = $parser->parse({ file => $filename })
|| die $parser->error();
Otherwise, the argument can be a reference to an input handle which is
passed off to parse_file().
my $podpom = $parser->parse(\*DATA)
|| die $parser->error();
If the argument is a text string that looks like Pod text (i.e. it
contains '=' at the start of any line) then it is passed to parse_text().
my $podpom = $parser->parse($podtext)
|| die $parser->error();
Otherwise it is assumed to be a filename and is passed to parse_file().
my $podpom = $parser->parse($podfile)
|| die $parser->error();
=head1 NODE TYPES, ATTRIBUTES AND ELEMENTS
This section lists the different nodes that may be present in a Pod Object
Model. These are implemented as Pod::POM::Node::* object instances
(e.g. head1 =E<gt> Pod::POM::Node::Head1). To present a node, a view should
implement a method which corresponds to the node name prefixed by 'view_'
(e.g. head1 =E<gt> view_head1()).
=over 4
=item pod
The C<pod> node is used to represent the root node of the Pod Object Model.
Content elements: head1, head2, head3, head4, over, begin, for,
verbatim, text, code.
=item head1
A C<head1> node contains the Pod content from a C<=head1> tag up to the
next C<=head1> tag or the end of the file.
Attributes: title
Content elements: head2, head3, head4, over, begin, for, verbatim, text, code.
=item head2
A C<head2> node contains the Pod content from a C<=head2> tag up to the
next C<=head1> or C<=head2> tag or the end of the file.
Attributes: title
Content elements: head3, head4, over, begin, for, verbatim, text, code.
=item head3
A C<head3> node contains the Pod content from a C<=head3> tag up to the
next C<=head1>, C<=head2> or C<=head3> tag or the end of the file.
Attributes: title
Content elements: head4, over, begin, for, verbatim, text, code.
=item head4
A C<head4> node contains the Pod content from a C<=head4> tag up to the
next C<=head1>, C<=head2>, C<=head3> or C<=head4> tag or the end of the file.
Attributes: title
Content elements: over, begin, for, verbatim, text, code.
=item over
The C<over> node encloses the Pod content in a list starting at an C<=over>
tag and continuing up to the matching C<=back> tag. Lists may be nested
indefinately.
Attributes: indent (default: 4)
Content elements: over, item, begin, for, verbatim, text, code.
=item item
The C<item> node encloses the Pod content in a list item starting at an
C<=item> tag and continuing up to the next C<=item> tag or a C<=back> tag
which terminates the list.
Attributes: title (default: *)
Content elements: over, begin, for, verbatim, text, code.
=item begin
A C<begin> node encloses the Pod content in a conditional block starting
with a C<=begin> tag and continuing up to the next C<=end> tag.
Attributes: format
Content elements: verbatim, text, code.
=item for
A C<for> node contains a single paragraph containing text relevant to a
particular format.
Attributes: format, text
=item verbatim
A C<verbatim> node contains a verbatim text paragraph which is prefixed by
whitespace in the source Pod document (i.e. indented).
Attributes: text
=item text
A C<text> node contains a regular text paragraph. This may include
embedded inline sequences.
Attributes: text
=item code
A C<code> node contains Perl code which is by default, not considered to be
part of a Pod document. The C<code> configuration option must be set for
Pod::POM to generate code blocks, otherwise they are ignored.
Attributes: text
=back
=head1 INLINE SEQUENCES
Embedded sequences are permitted within regular text blocks (i.e. not
verbatim) and title attributes. To present these sequences, a view
should implement methods corresponding to the sequence name, prefixed
by 'view_seq_' (e.g. bold =E<gt> view_seq_bold()).
=over 4
=item code
Code extract, e.g. CE<lt>my codeE<gt>
=item bold
Bold text, e.g. BE<lt>bold textE<gt>
=item italic
Italic text, e.g. IE<lt>italic textE<gt>
=item link
A link (cross reference), e.g. LE<lt>My::ModuleE<gt>
=item space
Text contains non-breaking space, e.g.SE<lt>Buffy The Vampire SlayerE<gt>
=item file
A filename, e.g. FE<lt>/etc/lilo.confE<gt>
=item index
An index entry, e.g. XE<lt>AngelE<gt>
=item zero
A zero-width character, e.g. ZE<lt>E<gt>
=item entity
An entity escape, e.g. EE<lt>ltE<gt>
=back
=head1 BUNDLED MODULES AND TOOLS
The Pod::POM module distribution includes a number of sample view
objects for rendering Pod Object Models into particular formats. These
are incomplete and may require some further work, but serve at present to
illustrate the principal and can be used as the basis for your own view
objects.
=over 4
=item Pod::POM::View::Pod
Regenerates the model as Pod.
=item Pod::POM::View::Text
Presents the model as plain text.
=item Pod::POM::View::HTML
Presents the model as HTML.
=back
A script is provided for converting Pod documents to other format by
using the view objects provided. The C<pom2> script should be called
with two arguments, the first specifying the output format, the second
the input filename. e.g.
$ pom2 text My/Module.pm > README
$ pom2 html My/Module.pm > ~/public_html/My/Module.html
You can also create symbolic links to the script if you prefer and
leave it to determine the output format from its own name.
$ ln -s pom2 pom2text
$ ln -s pom2 pom2html
$ pom2text My/Module.pm > README
$ pom2html My/Module.pm > ~/public_html/My/Module.html
The distribution also contains a trivial script, C<podlint>
(previously C<pomcheck>), which checks a Pod document for
well-formedness by simply parsing it into a Pod Object Model with
warnings enabled. Warnings are printed to STDERR.
$ podlint My/Module.pm
The C<-f> option can be set to have the script attempt to fix any problems
it encounters. The regenerated Pod output is printed to STDOUT.
$ podlint -f My/Module.pm > newfile
=head1 METADATA
This module includes support for an experimental new C<=meta> tag. This
is disabled by default but can be enabled by loading Pod::POM with the
C<meta> option.
use Pod::POM qw( meta );
Alternately, you can specify the C<meta> option to be any true value when
you instantiate a Pod::POM parser:
my $parser = Pod::POM->new( meta => 1 );
my $pom = $parser->parse_file($filename);
Any C<=meta> tags in the document will be stored as metadata items in the
root node of the Pod model created.
For example:
=meta module Foo::Bar
=meta author Andy Wardley
You can then access these items via the metadata() method.
print "module: ", $pom->metadata('module'), "\n";
print "author: ", $pom->metadata('author'), "\n";
or
my $metadata = $pom->metadata();
print "module: $metadata->{ module }\n";
print "author: $metadata->{ author }\n";
Please note that this is an experimental feature which is not supported by
other POD processors and is therefore likely to be most incompatible. Use
carefully.
=head1 AUTHOR
Andy Wardley E<lt>abw@kfs.orgE<gt>
Andrew Ford E<lt>A.Ford@ford-mason.co.ukE<gt> (co-maintainer as of 03/2009)
=head1 VERSION
This is version 0.25 of the Pod::POM module.
=head1 COPYRIGHT
Copyright (C) 2000-2009 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
For the definitive reference on Pod, see L<perlpod>.
For an overview of Pod::POM internals and details relating to subclassing
of POM nodes, see L<Pod::POM::Node>.
There are numerous other fine Pod modules available from CPAN which
perform conversion from Pod to other formats. In many cases these are
likely to be faster and quite possibly more reliable and/or complete
than this module. But as far as I know, there aren't any that offer
the same kind of flexibility in being able to customise the generated
output. But don't take my word for it - see your local CPAN site for
further details:
http://www.cpan.org/modules/by-module/Pod/
POD_POM
$fatpacked{"Pod/POM/Constants.pm"} = <<'POD_POM_CONSTANTS';
#============================================================= -*-Perl-*-
#
# Pod::POM::Constants
#
# DESCRIPTION
# Constants used by Pod::POM.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Constants.pm 78 2009-08-20 20:44:53Z ford $
#
#========================================================================
package Pod::POM::Constants;
require 5.004;
use strict;
use vars qw( $VERSION @SEQUENCE @STATUS @EXPORT_OK %EXPORT_TAGS );
use parent qw( Exporter );
$VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
@SEQUENCE = qw( CMD LPAREN RPAREN FILE LINE CONTENT );
@STATUS = qw( IGNORE REDUCE REJECT );
@EXPORT_OK = ( @SEQUENCE, @STATUS );
%EXPORT_TAGS = (
status => [ @STATUS ],
seq => [ @SEQUENCE ],
all => [ @STATUS, @SEQUENCE ],
);
# sequence items
use constant CMD => 0;
use constant LPAREN => 1;
use constant RPAREN => 2;
use constant FILE => 3;
use constant LINE => 4;
use constant CONTENT => 5;
# node add return values
use constant IGNORE => 0;
use constant REDUCE => 1;
use constant REJECT => 2;
1;
=head1 NAME
Pod::POM::Constants
=head1 DESCRIPTION
Constants used by Pod::POM.
=head1 AUTHOR
Andy Wardley E<lt>abw@kfs.orgE<gt>
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
POD_POM_CONSTANTS
$fatpacked{"Pod/POM/Node.pm"} = <<'POD_POM_NODE';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node
#
# DESCRIPTION
# Base class for a node in a Pod::POM tree.
#
# AUTHOR
# Andy Wardley <abw@wardley.org>
#
# COPYRIGHT
# Copyright (C) 2000-2003 Andy Wardley. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Node.pm 88 2010-04-02 13:37:41Z ford $
#
#========================================================================
package Pod::POM::Node;
require 5.004;
use strict;
use Pod::POM::Nodes;
use Pod::POM::Constants qw( :all );
use vars qw( $VERSION $DEBUG $ERROR $NODES $NAMES $AUTOLOAD );
use constant DUMP_LINE_LENGTH => 80;
$VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
$NODES = {
pod => 'Pod::POM::Node::Pod',
head1 => 'Pod::POM::Node::Head1',
head2 => 'Pod::POM::Node::Head2',
head3 => 'Pod::POM::Node::Head3',
head4 => 'Pod::POM::Node::Head4',
over => 'Pod::POM::Node::Over',
item => 'Pod::POM::Node::Item',
begin => 'Pod::POM::Node::Begin',
for => 'Pod::POM::Node::For',
text => 'Pod::POM::Node::Text',
code => 'Pod::POM::Node::Code',
verbatim => 'Pod::POM::Node::Verbatim',
};
$NAMES = {
map { ( $NODES->{ $_ } => $_ ) } keys %$NODES,
};
# overload stringification to present node via a view
use overload
'""' => 'present',
fallback => 1,
'bool' => sub { 1 };
# alias meta() to metadata()
*meta = \*metadata;
#------------------------------------------------------------------------
# new($pom, @attr)
#
# Constructor method. Returns a new Pod::POM::Node::* object or undef
# on error. First argument is the Pod::POM parser object, remaining
# arguments are node attributes as specified in %ATTRIBS in derived class
# package.
#------------------------------------------------------------------------
sub new {
my $class = shift;
my $pom = shift;
my ($type, $attribs, $accept, $key, $value, $default);
$type = $NAMES->{ $class };
{
no strict qw( refs );
$attribs = \%{"$class\::ATTRIBS"} || [ ];
$accept = \@{"$class\::ACCEPT"} || [ ];
unless (%{"$class\::ACCEPT"}) {
%{"$class\::ACCEPT"} = (
map { ( $_ => $NODES->{ $_ } ) } @$accept,
);
}
}
# create object with slots for each acceptable child and overall content
my $self = bless {
type => $type,
content => bless([ ], 'Pod::POM::Node::Content'),
map { ($_ => bless([ ], 'Pod::POM::Node::Content')) }
(@$accept, 'code'),
}, $class;
# set attributes from arguments
keys %$attribs; # reset hash iterator
while(my ($key, $default) = each %$attribs) {
$value = shift || $default;
return $class->error("$type expected a $key")
unless $value;
$self->{ $key } = $value;
}
return $self;
}
#------------------------------------------------------------------------
# add($pom, $type, @attr)
#
# Adds a new node as a child element (content) of the current node.
# First argument is the Pod::POM parser object. Second argument is the
# child node type specified by name (e.g. 'head1') which is mapped via
# the $NODES hash to a class name against which new() can be called.
# Remaining arguments are attributes passed to the child node constructor.
# Returns a reference to the new node (child was accepted) or one of the
# constants REDUCE (child terminated node, e.g. '=back' terminates an
# '=over' node), REJECT (child rejected, e.g. '=back' expected to terminate
# '=over' but something else found instead) or IGNORE (node didn't expect
# child and is implicitly terminated).
#------------------------------------------------------------------------
sub add {
my $self = shift;
my $pom = shift;
my $type = shift;
my $class = ref $self;
my ($name, $attribs, $accept, $expect, $nodeclass, $node);
$name = $NAMES->{ $class }
|| return $self->error("no name for $class");
{
no strict qw( refs );
$accept = \%{"$class\::ACCEPT"};
$expect = ${"$class\::EXPECT"};
}
# SHIFT: accept indicates child nodes that can be accepted; a
# new node is created, added it to content list and node specific
# list, then returned by reference.
if ($nodeclass = $accept->{ $type }) {
defined($node = $nodeclass->new($pom, @_))
|| return $self->error($nodeclass->error())
unless defined $node;
push(@{ $self->{ $type } }, $node);
push(@{ $self->{ content } }, $node);
$pom->{in_begin} = 1 if $nodeclass eq 'Pod::POM::Node::Begin';
return $node;
}
# REDUCE: expect indicates the token that should terminate this node
if (defined $expect && ($type eq $expect)) {
DEBUG("$name terminated by expected $type\n");
$pom->{in_begin} = 0 if $name eq 'begin';
return REDUCE;
}
# REJECT: expected terminating node was not found
if (defined $expect) {
DEBUG("$name rejecting $type, expecting a terminating $expect\n");
$self->error("$name expected a terminating $expect");
return REJECT;
}
# IGNORE: don't know anything about this node
DEBUG("$name ignoring $type\n");
return IGNORE;
}
#------------------------------------------------------------------------
# present($view)
#
# Present the node by making a callback on the appropriate method against
# the view object passed as an argument. $Pod::POM::DEFAULT_VIEW is used
# if $view is unspecified.
#------------------------------------------------------------------------
sub present {
my ($self, $view, @args) = @_;
$view ||= $Pod::POM::DEFAULT_VIEW;
my $type = $self->{ type };
my $method = "view_$type";
DEBUG("presenting method $method to $view\n");
my $txt = $view->$method($self, @args);
if ($view->can("encode")){
return $view->encode($txt);
} else {
return $txt;
}
}
#------------------------------------------------------------------------
# metadata()
# metadata($key)
# metadata($key, $value)
#
# Returns the metadata hash when called without any arguments. Returns
# the value of a metadata item when called with a single argument.
# Sets a metadata item to a value when called with two arguments.
#------------------------------------------------------------------------
sub metadata {
my ($self, $key, $value) = @_;
my $metadata = $self->{ METADATA } ||= { };
return $metadata unless defined $key;
if (defined $value) {
$metadata->{ $key } = $value;
}
else {
$value = $self->{ METADATA }->{ $key };
return defined $value ? $value
: $self->error("no such metadata item: $key");
}
}
#------------------------------------------------------------------------
# error()
# error($msg, ...)
#
# May be called as a class or object method to set or retrieve the
# package variable $ERROR (class method) or internal member
# $self->{ _ERROR } (object method). The presence of parameters indicates
# that the error value should be set. Undef is then returned. In the
# abscence of parameters, the current error value is returned.
#------------------------------------------------------------------------
sub error {
my $self = shift;
my $errvar;
# use Carp;
{
no strict qw( refs );
if (ref $self) {
# my ($pkg, $file, $line) = caller();
# print STDERR "called from $file line $line\n";
# croak "cannot get/set error in non-hash: $self\n"
# unless UNIVERSAL::isa($self, 'HASH');
$errvar = \$self->{ ERROR };
}
else {
$errvar = \${"$self\::ERROR"};
}
}
if (@_) {
$$errvar = ref($_[0]) ? shift : join('', @_);
return undef;
}
else {
return $$errvar;
}
}
#------------------------------------------------------------------------
# dump()
#
# Returns a representation of the element and all its children in a
# format useful only for debugging. The structure of the document is
# shown by indentation (inspired by HTML::Element).
#------------------------------------------------------------------------
sub dump {
my($self, $depth) = @_;
my $output;
$depth = 0 unless defined $depth;
my $nodepkg = ref $self;
if ($self->isa('REF')) {
$self = $$self;
my $cmd = $self->[CMD];
my @content = @{ $self->[CONTENT] };
if ($cmd) {
$output .= (" " x $depth) . $cmd . $self->[LPAREN] . "\n";
}
foreach my $item (@content) {
if (ref $item) {
$output .= $item->dump($depth+1); # recurse
}
else { # text node
$output .= _dump_text($item, $depth+1);
}
}
if ($cmd) {
$output .= (" " x $depth) . $self->[RPAREN] . "\n", ;
}
}
else {
no strict 'refs';
my @attrs = sort keys %{"*${nodepkg}::ATTRIBS"};
$output .= (" " x $depth) . $self->type . "\n";
foreach my $attr (@attrs) {
if (my $value = $self->{$attr}) {
$output .= (" " x ($depth+1)) . "\@$attr\n";
if (ref $value) {
$output .= $value->dump($depth+1);
}
else {
$output .= _dump_text($value, $depth+2);
}
}
}
foreach my $item (@{$self->{content}}) {
if (ref $item) { # element
$output .= $item->dump($depth+1); # recurse
}
else { # text node
$output .= _dump_text($item, $depth+1);
}
}
}
return $output;
}
sub _dump_text {
my ($text, $depth) = @_;
my $output = "";
my $padding = " " x $depth;
my $max_text_len = DUMP_LINE_LENGTH - length($depth) - 2;
foreach my $line (split(/\n/, $text)) {
$output .= $padding;
if (length($line) > $max_text_len or $line =~ m<[\x00-\x1F]>) {
# it needs prettyin' up somehow or other
my $x = (length($line) <= $max_text_len) ? $_ : (substr($line, 0, $max_text_len) . '...');
$x =~ s<([\x00-\x1F])>
<'\\x'.(unpack("H2",$1))>eg;
$output .= qq{"$x"\n};
} else {
$output .= qq{"$line"\n};
}
}
return $output;
}
#------------------------------------------------------------------------
# AUTOLOAD
#------------------------------------------------------------------------
sub AUTOLOAD {
my $self = shift;
my $name = $AUTOLOAD;
my $item;
$name =~ s/.*:://;
return if $name eq 'DESTROY';
# my ($pkg, $file, $line) = caller();
# print STDERR "called from $file line $line to return ", ref($item), "\n";
return $self->error("can't manipulate \$self")
unless UNIVERSAL::isa($self, 'HASH');
return $self->error("no such member: $name")
unless defined ($item = $self->{ $name });
return wantarray ? ( UNIVERSAL::isa($item, 'ARRAY') ? @$item : $item )
: $item;
}
#------------------------------------------------------------------------
# DEBUG(@msg)
#------------------------------------------------------------------------
sub DEBUG {
print STDERR "DEBUG: ", @_ if $DEBUG;
}
1;
=head1 NAME
Pod::POM::Node - base class for a POM node
=head1 SYNOPSIS
package Pod::POM::Node::Over;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );
%ATTRIBS = ( indent => 4 );
@ACCEPT = qw( over item begin for text verbatim );
$EXPECT = q( back );
package main;
my $list = Pod::POM::Node::Over->new(8);
$list->add('item', 'First Item');
$list->add('item', 'Second Item');
...
=head1 DESCRIPTION
This documentation describes the inner workings of the Pod::POM::Node
module and gives a brief overview of the relationship between it and
its derived classes. It is intended more as a guide to the internals
for interested hackers than as general user documentation. See
L<Pod::POM> for information on using the modules.
This module implements a base class node which is subclassed to
represent different elements within a Pod Object Model.
package Pod::POM::Node::Over;
use base qw( Pod::POM::Node );
The base class implements the new() constructor method to instantiate
new node objects.
my $list = Pod::POM::Node::Over->new();
The characteristics of a node can be specified by defining certain
variables in the derived class package. The C<%ATTRIBS> hash can be
used to denote attributes that the node should accept. In the case of
an C<=over> node, for example, an C<indent> attribute can be specified
which otherwise defaults to 4.
package Pod::POM::Node::Over;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );
%ATTRIBS = ( indent => 4 );
The new() method will now expect an argument to set the indent value,
or will use 4 as the default if no argument is provided.
my $list = Pod::POM::Node::Over->new(8); # indent: 8
my $list = Pod::POM::Node::Over->new( ); # indent: 4
If the default value is undefined then the argument is mandatory.
package Pod::POM::Node::Head1;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );
%ATTRIBS = ( title => undef );
package main;
my $head = Pod::POM::Node::Head1->new('My Title');
If a mandatory argument isn't provided then the constructor will
return undef to indicate failure. The $ERROR variable in the derived
class package is set to contain a string of the form "$type expected a
$attribute".
# dies with error: "head1 expected a title"
my $head = Pod::POM::Node::Head1->new()
|| die $Pod::POM::Node::Head1::ERROR;
For convenience, the error() subroutine can be called as a class
method to retrieve this value.
my $type = 'Pod::POM::Node::Head1';
my $head = $type->new()
|| die $type->error();
The C<@ACCEPT> package variable can be used to indicate the node types
that are permitted as children of a node.
package Pod::POM::Node::Head1;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $ERROR );
%ATTRIBS = ( title => undef );
@ACCEPT = qw( head2 over begin for text verbatim );
The add() method can then be called against a node to add a new child
node as part of its content.
$head->add('over', 8);
The first argument indicates the node type. The C<@ACCEPT> list is
examined to ensure that the child node type is acceptable for the
parent node. If valid, the constructor for the relevant child node
class is called passing any remaining arguments as attributes. The
new node is then returned.
my $list = $head->add('over', 8);
The error() method can be called against the I<parent> node to retrieve
any constructor error generated by the I<child> node.
my $list = $head->add('over', 8);
die $head->error() unless defined $list;
If the child node is not acceptable to the parent then the add()
method returns one of the constants IGNORE, REDUCE or REJECT, as
defined in Pod::POM::Constants. These return values are used by the
Pod::POM parser module to implement a simple shift/reduce parser.
In the most common case, IGNORE is returned to indicate that the
parent node doesn't know anything about the new child node. The
parser uses this as an indication that it should back up through the
parse stack until it finds a node which I<will> accept this child node.
Through this mechanism, the parser is able to implicitly terminate
certain POD blocks. For example, a list item initiated by a C<=item>
tag will I<not> accept another C<=item> tag, but will instead return IGNORE.
The parser will back out until it finds the enclosing C<=over> node
which I<will> accept it. Thus, a new C<=item> implicitly terminates any
previous C<=item>.
The C<$EXPECT> package variable can be used to indicate a node type
which a parent expects to terminate itself. An C<=over> node, for
example, should always be terminated by a matching C<=back>. When
such a match is made, the add() method returns REDUCE to indicate
successful termination.
package Pod::POM::Node::Over;
use base qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );
%ATTRIBS = ( indent => 4 );
@ACCEPT = qw( over item begin for text verbatim );
$EXPECT = q( back );
package main;
my $list = Pod::POM::Node::Over->new();
my $item = $list->add('item');
$list->add('back'); # returns REDUCE
If a child node isn't specified in the C<@ACCEPT> list or doesn't match
any C<$EXPECT> specified then REJECT is returned. The parent node sets
an internal error of the form "$type expected a terminating $expect".
The parser uses this to detect missing POD tags. In nearly all cases
the parser is smart enough to fix the incorrect structure and downgrades
any errors to warnings.
# dies with error 'over expected terminating back'
ref $list->add('head1', 'My Title') # returns REJECT
|| die $list->error();
Each node contains a 'type' field which contains a simple string
indicating the node type, e.g. 'head1', 'over', etc. The $NODES and
$NAMES package variables (in the base class) reference hash arrays
which map these names to and from package names (e.g. head1 E<lt>=E<gt>
Pod::POM::Node::Head1).
print $list->{ type }; # 'over'
An AUTOLOAD method is provided to access to such internal items for
those who don't like violating an object's encapsulation.
print $list->type();
Nodes also contain a 'content' list, blessed into the
Pod::POM::Node::Content class, which contains the content (child
elements) for the node. The AUTOLOAD method returns this as a list
reference or as a list of items depending on the context in which it
is called.
my $items = $list->content();
my @items = $list->content();
Each node also contains a content list for each individual child node
type that it may accept.
my @items = $list->item();
my @text = $list->text();
my @vtext = $list->verbatim();
The present() method is used to present a node through a particular view.
This simply maps the node type to a method which is then called against the
view object. This is known as 'double dispatch'.
my $view = 'Pod::POM::View::HTML';
print $list->present($view);
The method name is constructed from the node type prefixed by 'view_'.
Thus the following are roughly equivalent.
$list->present($view);
$view->view_list($list);
The benefit of the former over the latter is, of course, that the
caller doesn't need to know or determine the type of the node. The
node itself is in the best position to determine what type it is.
=head1 AUTHOR
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM> for a general overview and examples of use.
POD_POM_NODE
$fatpacked{"Pod/POM/Node/Begin.pm"} = <<'POD_POM_NODE_BEGIN';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Begin
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Begin.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Begin;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );
%ATTRIBS = ( format => undef );
@ACCEPT = qw( text verbatim code );
$EXPECT = 'end';
1;
=head1 NAME
Pod::POM::Node::Begin - POM '=begin' node class
=head1 SYNOPSIS
=head1 DESCRIPTION
This module implements a specialization of the node class to represent '=begin' elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_BEGIN
$fatpacked{"Pod/POM/Node/Code.pm"} = <<'POD_POM_NODE_CODE';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Code
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Code.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Code;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );
%ATTRIBS = ( text => '' );
sub present {
my ($self, $view) = @_;
$view ||= $Pod::POM::DEFAULT_VIEW;
return $view->view_code($self->{ text });
}
1;
=head1 NAME
Pod::POM::Node::Code -
=head1 SYNOPSIS
=head1 DESCRIPTION
This module implements a specialization of the node class to represent code elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_CODE
$fatpacked{"Pod/POM/Node/Content.pm"} = <<'POD_POM_NODE_CONTENT';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Content
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Content.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Content;
use strict;
use Pod::POM::Constants qw( :all );
use parent qw( Pod::POM::Node );
sub new {
my $class = shift;
return bless [ @_ ], $class;
}
sub present {
my ($self, $view) = @_;
$view ||= $Pod::POM::DEFAULT_VIEW;
return join('', map { ref $_ ? $_->present($view) : $_ } @$self);
}
1;
=head1 NAME
Pod::POM::Node::Content -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_CONTENT
$fatpacked{"Pod/POM/Node/For.pm"} = <<'POD_POM_NODE_FOR';
#============================================================= -*-Perl-*-
#
# Pod::POM::Nodes
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: For.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::For;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );
%ATTRIBS = ( format => undef, text => '' );
sub new {
my $class = shift;
my $pom = shift;
my $text = shift;
return $class->SUPER::new($pom, split(/\s+/, $text, 2));
}
1;
=head1 NAME
Pod::POM::Node::For -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent C<=for> elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_FOR
$fatpacked{"Pod/POM/Node/Head1.pm"} = <<'POD_POM_NODE_HEAD1';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Head1
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Head1.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Head1;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $ERROR );
%ATTRIBS = ( title => undef );
@ACCEPT = qw( head2 head3 head4 over begin for text verbatim code );
sub new {
my ($class, $pom, $title) = @_;
$title = $pom->parse_sequence($title)
|| return $class->error($pom->error())
if length $title;
return $class->SUPER::new($pom, $title);
}
1;
=head1 NAME
Pod::POM::Node::Head1 -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent C<=head1> elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_HEAD1
$fatpacked{"Pod/POM/Node/Head2.pm"} = <<'POD_POM_NODE_HEAD2';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Head2
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Head2.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Head2;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $ERROR );
%ATTRIBS = ( title => undef );
@ACCEPT = qw( head3 head4 over begin for text verbatim code );
sub new {
my ($class, $pom, $title) = @_;
$title = $pom->parse_sequence($title)
|| return $class->error($pom->error())
if length $title;
return $class->SUPER::new($pom, $title);
}
1;
=head1 NAME
Pod::POM::Node::Head2 -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent C<=head2> elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_HEAD2
$fatpacked{"Pod/POM/Node/Head3.pm"} = <<'POD_POM_NODE_HEAD3';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Head3
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Head3.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Head3;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $ERROR );
%ATTRIBS = ( title => undef );
@ACCEPT = qw( head4 over begin for text verbatim code );
sub new {
my ($class, $pom, $title) = @_;
$title = $pom->parse_sequence($title)
|| return $class->error($pom->error())
if length $title;
return $class->SUPER::new($pom, $title);
}
1;
=head1 NAME
Pod::POM::Node::Head3 -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent C<=head3> elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_HEAD3
$fatpacked{"Pod/POM/Node/Head4.pm"} = <<'POD_POM_NODE_HEAD4';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Head4
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Head4.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Head4;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $ERROR );
%ATTRIBS = ( title => undef );
@ACCEPT = qw( over begin for text verbatim code );
sub new {
my ($class, $pom, $title) = @_;
$title = $pom->parse_sequence($title)
|| return $class->error($pom->error())
if length $title;
return $class->SUPER::new($pom, $title);
}
1;
=head1 NAME
Pod::POM::Node::Head4 -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent C<=head4> elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_HEAD4
$fatpacked{"Pod/POM/Node/Item.pm"} = <<'POD_POM_NODE_ITEM';
#============================================================= -*-Perl-*-
#
# Pod::POM::Nodes
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Item.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Item;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $ERROR );
%ATTRIBS = ( title => '*' );
@ACCEPT = qw( over begin for text verbatim code );
sub new {
my ($class, $pom, $title) = @_;
$title = $pom->parse_sequence($title)
|| return $class->error($pom->error())
if length $title;
return $class->SUPER::new($pom, $title);
}
1;
=head1 NAME
Pod::POM::Node::Item -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent C<=item> elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_ITEM
$fatpacked{"Pod/POM/Node/Over.pm"} = <<'POD_POM_NODE_OVER';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Over
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Over.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Over;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );
%ATTRIBS = ( indent => 4 );
@ACCEPT = qw( over item begin for text verbatim code );
$EXPECT = 'back';
sub list_type {
my $self = shift;
my ($first, @rest) = $self->content;
my $first_type = $first->type;
return;
}
1;
=head1 NAME
Pod::POM::Node::Over - POM '=over' node class
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This class implements '=over' Pod nodes. As described by the L<perlpodspec> man page =over/=back regions are
used for various kinds of list-like structures (including blockquote paragraphs).
=item 1.
ordered list
=item *
text paragraph
unordered list
=item text
text paragraph
definition list
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_OVER
$fatpacked{"Pod/POM/Node/Pod.pm"} = <<'POD_POM_NODE_POD';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Pod
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Pod.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Pod;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( @ACCEPT $ERROR );
@ACCEPT = qw( head1 head2 head3 head4 over begin for text verbatim code );
1;
=head1 NAME
Pod::POM::Node::Pod -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent C<=pod> elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_POD
$fatpacked{"Pod/POM/Node/Sequence.pm"} = <<'POD_POM_NODE_SEQUENCE';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Sequence
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Sequence.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Sequence;
use strict;
use Pod::POM::Constants qw( :all );
use parent qw( Pod::POM::Node );
use vars qw( %NAME );
%NAME = (
C => 'code',
B => 'bold',
I => 'italic',
L => 'link',
S => 'space',
F => 'file',
X => 'index',
Z => 'zero',
E => 'entity',
);
sub new {
my ($class, $self) = @_;
local $" = '] [';
return bless \$self, $class;
}
sub add {
return IGNORE;
}
sub present {
my ($self, $view) = @_;
my ($cmd, $method, $result);
$view ||= $Pod::POM::DEFAULT_VIEW;
$self = $$self;
return $self unless ref $self eq 'ARRAY';
my $text = join('',
map { ref $_ ? $_->present($view)
: $view->view_seq_text($_) }
@{ $self->[CONTENT] });
if ($cmd = $self->[CMD]) {
my $method = $NAME{ $cmd } || $cmd;
$method = "view_seq_$method";
return $view->$method($text);
}
else {
return $text;
}
}
1;
=head1 NAME
Pod::POM::Node::Sequence -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent sequence elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_SEQUENCE
$fatpacked{"Pod/POM/Node/Text.pm"} = <<'POD_POM_NODE_TEXT';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Text
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Text.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Text;
use strict;
use Pod::POM::Constants qw( :all );
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );
%ATTRIBS = ( text => '' );
sub new {
my $class = shift;
my $pom = shift;
my $text = shift;
$text = $pom->parse_sequence($text)
|| return $class->error($pom->error())
if length $text && ! $pom->{in_begin};
return $class->SUPER::new($pom, $text);
}
sub add {
return IGNORE;
}
sub present {
my ($self, $view) = @_;
my $text = $self->{ text };
$view ||= $Pod::POM::DEFAULT_VIEW;
$text = $text->present($view)
if ref $text;
return $view->view_textblock($text);
}
1;
=head1 NAME
Pod::POM::Node::Text -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent text elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_TEXT
$fatpacked{"Pod/POM/Node/Verbatim.pm"} = <<'POD_POM_NODE_VERBATIM';
#============================================================= -*-Perl-*-
#
# Pod::POM::Node::Verbatim
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
# Andrew Ford <a.ford@ford-mason.co.uk>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 2009 Andrew Ford. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Verbatim.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Node::Verbatim;
use strict;
use parent qw( Pod::POM::Node );
use vars qw( %ATTRIBS $ERROR );
%ATTRIBS = ( text => '' );
sub present {
my ($self, $view) = @_;
$view ||= $Pod::POM::DEFAULT_VIEW;
return $view->view_verbatim($self->{ text });
}
1;
=head1 NAME
Pod::POM::Node::Verbatim -
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a specialization of the node class to represent verbatim elements.
=head1 AUTHOR
Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
Copyright (C) 2009 Andrew Ford. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM::Node> for a discussion of nodes.
POD_POM_NODE_VERBATIM
$fatpacked{"Pod/POM/Nodes.pm"} = <<'POD_POM_NODES';
#============================================================= -*-Perl-*-
#
# Pod::POM::Nodes
#
# DESCRIPTION
# Module implementing specific nodes in a Pod::POM, subclassed from
# Pod::POM::Node.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Nodes.pm 76 2009-08-20 20:41:33Z ford $
#
#========================================================================
package Pod::POM::Nodes;
require 5.004;
require Exporter;
use strict;
use Pod::POM::Node::Pod;
use Pod::POM::Node::Head1;
use Pod::POM::Node::Head2;
use Pod::POM::Node::Head3;
use Pod::POM::Node::Head4;
use Pod::POM::Node::Over;
use Pod::POM::Node::Item;
use Pod::POM::Node::Begin;
use Pod::POM::Node::For;
use Pod::POM::Node::Verbatim;
use Pod::POM::Node::Code;
use Pod::POM::Node::Text;
use Pod::POM::Node::Sequence;
use Pod::POM::Node::Content;
use vars qw( $VERSION $DEBUG $ERROR @EXPORT_OK @EXPORT_FAIL );
use base qw( Exporter );
$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
1;
=head1 NAME
Pod::POM::Nodes - convenience class to load all node classes
=head1 SYNOPSIS
use Pod::POM::Nodes;
=head1 DESCRIPTION
This module implements a convenience class that simply uses all of the subclasses of Pod::POM::Node.
(It used to include all the individual classes inline, but the node classes have been factored out
into individual modules.)
=head1 AUTHOR
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
Consult L<Pod::POM> for a general overview and examples of use.
POD_POM_NODES
$fatpacked{"Pod/POM/Test.pm"} = <<'POD_POM_TEST';
#============================================================= -*-Perl-*-
#
# Pod::POM::Test
#
# DESCRIPTION
# Module implementing some useful subroutines for testing.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Test.pm 14 2009-03-13 08:19:40Z ford $
#
#========================================================================
package Pod::POM::Test;
require 5.004;
use strict;
use Pod::POM;
use base qw( Exporter );
use vars qw( $VERSION @EXPORT );
$VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
@EXPORT = qw( ntests ok match assert );
my $ok_count;
sub ntests {
my $ntests = shift;
$ok_count = 1;
print "1..$ntests\n";
}
sub ok {
my ($ok, $msg) = @_;
if ($ok) {
print "ok ", $ok_count++, "\n";
}
else {
print "FAILED $ok_count: $msg\n" if defined $msg;
print "not ok ", $ok_count++, "\n";
}
}
sub assert {
my ($ok, $err) = @_;
return ok(1) if $ok;
# failed
my ($pkg, $file, $line) = caller();
$err ||= "assert failed";
$err .= " at $file line $line\n";
ok(0);
die $err;
}
sub match {
my ($result, $expect) = @_;
# force stringification of $result to avoid 'no eq method' overload errors
$result = "$result" if ref $result;
if ($result eq $expect) {
ok(1);
}
else {
print "FAILED $ok_count:\n expect: [$expect]\n result: [$result]\n";
ok(0);
}
}
1;
POD_POM_TEST
$fatpacked{"Pod/POM/View.pm"} = <<'POD_POM_VIEW';
#============================================================= -*-Perl-*-
#
# Pod::POM::View
#
# DESCRIPTION
# Visitor class for creating a view of all or part of a Pod Object
# Model.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
#
# COPYRIGHT
# Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: View.pm 32 2009-03-17 21:08:25Z ford $
#
#========================================================================
package Pod::POM::View;
require 5.004;
use strict;
use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD $INSTANCE );
$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
#------------------------------------------------------------------------
# new($pom)
#------------------------------------------------------------------------
sub new {
my $class = shift;
my $args = ref $_[0] eq 'HASH' ? shift : { @_ };
bless { %$args }, $class;
}
sub print {
my ($self, $item) = @_;
return UNIVERSAL::can($item, 'present')
? $item->present($self) : $item;
}
sub view {
my ($self, $type, $node) = @_;
return $node;
}
sub instance {
my $self = shift;
my $class = ref $self || $self;
no strict 'refs';
my $instance = \${"$class\::_instance"};
defined $$instance
? $$instance
: ($$instance = $class->new(@_));
}
sub visit {
my ($self, $place) = @_;
$self = $self->instance() unless ref $self;
my $visit = $self->{ VISIT } ||= [ ];
push(@$visit, $place);
return $place;
}
sub leave {
my ($self, $place) = @_;
$self = $self->instance() unless ref $self;
my $visit = $self->{ VISIT };
return $self->error('empty VISIT stack') unless @$visit;
pop(@$visit);
}
sub visiting {
my ($self, $place) = @_;
$self = $self->instance() unless ref $self;
my $visit = $self->{ VISIT };
return 0 unless $visit && @$visit;
foreach (reverse @$visit) {
return 1 if $_ eq $place;
}
return 0;
}
sub AUTOLOAD {
my $self = shift;
my $name = $AUTOLOAD;
my $item;
$name =~ s/.*:://;
return if $name eq 'DESTROY';
if ($name =~ s/^view_//) {
return $self->view($name, @_);
}
elsif (! ref $self) {
die "can't access $name in $self\n";
}
else {
die "no such method for $self: $name ($AUTOLOAD)"
unless defined ($item = $self->{ $name });
return wantarray ? ( ref $item eq 'ARRAY' ? @$item : $item ) : $item;
}
}
1;
=head1 NAME
Pod::POM::View
=head1 DESCRIPTION
Visitor class for creating a view of all or part of a Pod Object Model.
=head1 METHODS
=over 4
=item C<new>
=item C<print>
=item C<view>
=item C<instance>
=item C<visit>
=item C<leave>
=item C<visiting>
=back
=head1 AUTHOR
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
POD_POM_VIEW
$fatpacked{"Pod/POM/View/HTML.pm"} = <<'POD_POM_VIEW_HTML';
#============================================================= -*-Perl-*-
#
# Pod::POM::View::HTML
#
# DESCRIPTION
# HTML view of a Pod Object Model.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
#
# COPYRIGHT
# Copyright (C) 2000 Andy Wardley. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: HTML.pm 84 2009-08-20 21:07:00Z ford $
#
#========================================================================
package Pod::POM::View::HTML;
require 5.004;
use strict;
use Pod::POM::View;
use parent qw( Pod::POM::View );
use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD );
use Text::Wrap;
$VERSION = sprintf("%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
my $HTML_PROTECT = 0;
my @OVER;
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_)
|| return;
# initalise stack for maintaining info for nested lists
$self->{ OVER } = [];
return $self;
}
sub view {
my ($self, $type, $item) = @_;
if ($type =~ s/^seq_//) {
return $item;
}
elsif (UNIVERSAL::isa($item, 'HASH')) {
if (defined $item->{ content }) {
return $item->{ content }->present($self);
}
elsif (defined $item->{ text }) {
my $text = $item->{ text };
return ref $text ? $text->present($self) : $text;
}
else {
return '';
}
}
elsif (! ref $item) {
return $item;
}
else {
return '';
}
}
sub view_pod {
my ($self, $pod) = @_;
return "<html>\n<body bgcolor=\"#ffffff\">\n"
. $pod->content->present($self)
. "</body>\n</html>\n";
}
sub view_head1 {
my ($self, $head1) = @_;
my $title = $head1->title->present($self);
return "<h1>$title</h1>\n\n"
. $head1->content->present($self);
}
sub view_head2 {
my ($self, $head2) = @_;
my $title = $head2->title->present($self);
return "<h2>$title</h2>\n"
. $head2->content->present($self);
}
sub view_head3 {
my ($self, $head3) = @_;
my $title = $head3->title->present($self);
return "<h3>$title</h3>\n"
. $head3->content->present($self);
}
sub view_head4 {
my ($self, $head4) = @_;
my $title = $head4->title->present($self);
return "<h4>$title</h4>\n"
. $head4->content->present($self);
}
sub view_over {
my ($self, $over) = @_;
my ($start, $end, $strip);
my $items = $over->item();
if (@$items) {
my $first_title = $items->[0]->title();
if ($first_title =~ /^\s*\*\s*/) {
# '=item *' => <ul>
$start = "<ul>\n";
$end = "</ul>\n";
$strip = qr/^\s*\*\s*/;
}
elsif ($first_title =~ /^\s*\d+\.?\s*/) {
# '=item 1.' or '=item 1 ' => <ol>
$start = "<ol>\n";
$end = "</ol>\n";
$strip = qr/^\s*\d+\.?\s*/;
}
else {
$start = "<ul>\n";
$end = "</ul>\n";
$strip = '';
}
my $overstack = ref $self ? $self->{ OVER } : \@OVER;
push(@$overstack, $strip);
my $content = $over->content->present($self);
pop(@$overstack);
return $start
. $content
. $end;
}
else {
return "<blockquote>\n"
. $over->content->present($self)
. "</blockquote>\n";
}
}
sub view_item {
my ($self, $item) = @_;
my $over = ref $self ? $self->{ OVER } : \@OVER;
my $title = $item->title();
my $strip = $over->[-1];
if (defined $title) {
$title = $title->present($self) if ref $title;
$title =~ s/$strip// if $strip;
if (length $title) {
my $anchor = $title;
$anchor =~ s/^\s*|\s*$//g; # strip leading and closing spaces
$anchor =~ s/\W/_/g;
$title = qq{<a name="item_$anchor"></a><b>$title</b>};
}
}
return '<li>'
. "$title\n"
. $item->content->present($self)
. "</li>\n";
}
sub view_for {
my ($self, $for) = @_;
return '' unless $for->format() =~ /\bhtml\b/;
return $for->text()
. "\n\n";
}
sub view_begin {
my ($self, $begin) = @_;
return '' unless $begin->format() =~ /\bhtml\b/;
$HTML_PROTECT++;
my $output = $begin->content->present($self);
$HTML_PROTECT--;
return $output;
}
sub view_textblock {
my ($self, $text) = @_;
return $HTML_PROTECT ? "$text\n" : "<p>$text</p>\n";
}
sub view_verbatim {
my ($self, $text) = @_;
for ($text) {
s/&/&/g;
s/</</g;
s/>/>/g;
}
return "<pre>$text</pre>\n\n";
}
sub view_seq_bold {
my ($self, $text) = @_;
return "<b>$text</b>";
}
sub view_seq_italic {
my ($self, $text) = @_;
return "<i>$text</i>";
}
sub view_seq_code {
my ($self, $text) = @_;
return "<code>$text</code>";
}
sub view_seq_file {
my ($self, $text) = @_;
return "<i>$text</i>";
}
sub view_seq_space {
my ($self, $text) = @_;
$text =~ s/\s/ /g;
return $text;
}
sub view_seq_entity {
my ($self, $entity) = @_;
return "&$entity;"
}
sub view_seq_index {
return '';
}
sub view_seq_link {
my ($self, $link) = @_;
# view_seq_text has already taken care of L<http://example.com/>
if ($link =~ /^<a href=/ ) {
return $link;
}
# full-blown URL's are emitted as-is
if ($link =~ m{^\w+://}s ) {
return make_href($link);
}
$link =~ s/\n/ /g; # undo line-wrapped tags
my $orig_link = $link;
my $linktext;
# strip the sub-title and the following '|' char
if ( $link =~ s/^ ([^|]+) \| //x ) {
$linktext = $1;
}
# make sure sections start with a /
$link =~ s|^"|/"|;
my $page;
my $section;
if ($link =~ m|^ (.*?) / "? (.*?) "? $|x) { # [name]/"section"
($page, $section) = ($1, $2);
}
elsif ($link =~ /\s/) { # this must be a section with missing quotes
($page, $section) = ('', $link);
}
else {
($page, $section) = ($link, '');
}
# warning; show some text.
$linktext = $orig_link unless defined $linktext;
my $url = '';
if (defined $page && length $page) {
$url = $self->view_seq_link_transform_path($page);
}
# append the #section if exists
$url .= "#$section" if defined $url and
defined $section and length $section;
return make_href($url, $linktext);
}
# should be sub-classed if extra transformations are needed
#
# for example a sub-class may search for the given page and return a
# relative path to it.
#
# META: where this functionality should be documented? This module
# doesn't have docs section
#
sub view_seq_link_transform_path {
my($self, $page) = @_;
# right now the default transform doesn't check whether the link
# is not dead (i.e. whether there is a corresponding file.
# therefore we don't link L<>'s other than L<http://>
# subclass to change the default (and of course add validation)
# this is the minimal transformation that will be required if enabled
# $page = "$page.html";
# $page =~ s|::|/|g;
#print "page $page\n";
return undef;
}
sub make_href {
my($url, $title) = @_;
if (!defined $url) {
return defined $title ? "<i>$title</i>" : '';
}
$title = $url unless defined $title;
#print "$url, $title\n";
return qq{<a href="$url">$title</a>};
}
# this code has been borrowed from Pod::Html
my $urls = '(' . join ('|',
qw{
http
telnet
mailto
news
gopher
file
wais
ftp
} ) . ')';
my $ltrs = '\w';
my $gunk = '/#~:.?+=&%@!\-';
my $punc = '.:!?\-;';
my $any = "${ltrs}${gunk}${punc}";
sub view_seq_text {
my ($self, $text) = @_;
unless ($HTML_PROTECT) {
for ($text) {
s/&/&/g;
s/</</g;
s/>/>/g;
}
}
$text =~ s{
\b # start at word boundary
( # begin $1 {
$urls : # need resource and a colon
(?!:) # Ignore File::, among others.
[$any] +? # followed by one or more of any valid
# character, but be conservative and
# take only what you need to....
) # end $1 }
(?= # look-ahead non-consumptive assertion
[$punc]* # either 0 or more punctuation followed
(?: # followed
[^$any] # by a non-url char
| # or
$ # end of the string
) #
| # or else
$ # then end of the string
)
}{<a href="$1">$1</a>}igox;
return $text;
}
sub encode {
my($self,$text) = @_;
require Encode;
return Encode::encode("ascii",$text,Encode::FB_XMLCREF());
}
1;
=head1 NAME
Pod::POM::View::HTML
=head1 DESCRIPTION
HTML view of a Pod Object Model.
=head1 METHODS
=over 4
=item C<view($self, $type, $item)>
=item C<view_pod($self, $pod)>
=item C<view_head1($self, $head1)>
=item C<view_head2($self, $head2)>
=item C<view_head3($self, $head3)>
=item C<view_head4($self, $head4)>
=item C<view_over($self, $over)>
=item C<view_item($self, $item)>
=item C<view_for($self, $for)>
=item C<view_begin($self, $begin)>
=item C<view_textblock($self, $textblock)>
=item C<view_verbatim($self, $verbatim)>
=item C<view_meta($self, $meta)>
=item C<view_seq_bold($self, $text)>
Returns the text of a C<BE<lt>E<gt>> sequence enclosed in a C<E<lt>b<E<gt>> element.
=item C<view_seq_italic($self, $text)>
Returns the text of a C<IE<lt>E<gt>> sequence enclosed in a C<E<lt>i<E<gt>> element.
=item C<view_seq_code($self, $text)>
Returns the text of a C<CE<lt>E<gt>> sequence enclosed in a C<E<lt>code<E<gt>> element.
=item C<view_seq_file($self, $text)>
=item C<view_seq_entity($self, $text)>
=item C<view_seq_index($self, $text)>
Returns an empty string. Index sequences are suppressed in HTML view.
=item C<view_seq_link($self, $text)>
=back
=head1 AUTHOR
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2000 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
POD_POM_VIEW_HTML
$fatpacked{"Pod/POM/View/Pod.pm"} = <<'POD_POM_VIEW_POD';
#============================================================= -*-Perl-*-
#
# Pod::POM::View::Pod
#
# DESCRIPTION
# Pod view of a Pod Object Model.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
#
# COPYRIGHT
# Copyright (C) 2000 Andy Wardley. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Pod.pm 77 2009-08-20 20:44:14Z ford $
#
#========================================================================
package Pod::POM::View::Pod;
require 5.004;
use strict;
use Pod::POM::Nodes;
use Pod::POM::View;
use parent qw( Pod::POM::View );
use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD $MARKUP );
$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
# create reverse lookup table mapping method name to original sequence
$MARKUP = {
map { ( $Pod::POM::Node::Sequence::NAME{ $_ } => $_ ) }
keys %Pod::POM::Node::Sequence::NAME,
};
sub view {
my ($self, $type, $item) = @_;
# my ($pkg, $file, $line) = caller;
# print STDERR "called view ($type) from $file line $line\n";
if ($type =~ s/^seq_//) {
if ($type eq 'text') {
return "$item";
}
if ($type = $MARKUP->{ $type }) {
if ($item =~ /[<>]/) {
return "$type<< $item >>";
}
else {
return "$type<$item>";
}
}
}
elsif (ref $item eq 'HASH') {
if (defined $item->{ content }) {
return $item->{ content }->present($self);
}
elsif (defined $item->{ text }) {
my $text = $item->{ text };
return ref $text ? $text->present($self) : $text;
}
else {
return '';
}
}
elsif (! ref $item) {
return $item;
}
else {
return '';
}
}
sub view_pod {
my ($self, $pod) = @_;
# return "=pod\n\n" . $pod->content->present($self) . "=cut\n\n";
return $pod->content->present($self);
}
sub view_head1 {
my ($self, $head1) = @_;
return '=head1 '
. $head1->title->present($self)
. "\n\n"
. $head1->content->present($self);
}
sub view_head2 {
my ($self, $head2) = @_;
return '=head2 '
. $head2->title->present($self)
. "\n\n"
. $head2->content->present($self);
}
sub view_head3 {
my ($self, $head3) = @_;
return '=head3 '
. $head3->title->present($self)
. "\n\n"
. $head3->content->present($self);
}
sub view_head4 {
my ($self, $head4) = @_;
return '=head4 '
. $head4->title->present($self)
. "\n\n"
. $head4->content->present($self);
}
sub view_over {
my ($self, $over) = @_;
return '=over '
. $over->indent()
. "\n\n"
. $over->content->present($self)
. "=back\n\n";
}
sub view_item {
my ($self, $item) = @_;
my $title = $item->title();
$title = $title->present($self) if ref $title;
return "=item $title\n\n"
. $item->content->present($self);
}
sub view_for {
my ($self, $for) = @_;
return '=for '
. $for->format . ' '
. $for->text()
. "\n\n"
. $for->content->present($self);
}
sub view_begin {
my ($self, $begin) = @_;
return '=begin '
. $begin->format()
. "\n\n"
. $begin->content->present($self)
. "=end "
. $begin->format()
. "\n\n";
}
sub view_textblock {
my ($self, $text) = @_;
return "$text\n\n";
}
sub view_verbatim {
my ($self, $text) = @_;
return "$text\n\n";
}
sub view_meta {
my ($self, $meta) = @_;
return '=meta '
. $meta->name()
. "\n\n"
. $meta->content->present($self)
. "=end\n\n";
}
1;
=head1 NAME
Pod::POM::View::Pod
=head1 DESCRIPTION
Pod view of a Pod Object Model.
=head1 METHODS
=over 4
=item C<view($self, $type, $item)>
=item C<view_pod($self, $pod)>
=item C<view_head1($self, $head1)>
=item C<view_head2($self, $head2)>
=item C<view_head3($self, $head3)>
=item C<view_head4($self, $head4)>
=item C<view_over($self, $over)>
=item C<view_item($self, $item)>
=item C<view_for($self, $for)>
=item C<view_begin($self, $begin)>
=item C<view_textblock($self, $textblock)>
=item C<view_verbatim($self, $verbatim)>
=item C<view_meta($self, $meta)>
=back
=head1 AUTHOR
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2000 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
POD_POM_VIEW_POD
$fatpacked{"Pod/POM/View/Restructured.pm"} = <<'POD_POM_VIEW_RESTRUCTURED';
# Original authors: don
# $Revision: 1595 $
# Copyright (c) 2010 Don Owens <don@regexguy.com>. All rights reserved.
#
# This is free software; you can redistribute it and/or modify it under
# the Perl Artistic license. You should have received a copy of the
# Artistic license with this distribution, in the file named
# "Artistic". You may also obtain a copy from
# http://regexguy.com/license/Artistic
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.
=pod
=head1 NAME
Pod::POM::View::Restructured - View for Pod::POM that outputs reStructuredText
=head1 SYNOPSIS
use Pod::POM::View::Restructured;
my $view = Pod::POM::View::Restructured->new;
my $parser = Pod::POM->new;
my $pom = $parser->parse_file("$top_dir/lib/Pod/POM/View/Restructured.pm");
my $out = $pom->present($view);
=head1 DESCRIPTION
This module outputs reStructuredText that is expected to be used
with Sphinx. Verbatim sections (indented paragraphs) in the POD
will be output with syntax hilighting for Perl code by default.
See L</"POD commands specifically for reStructuredText"> for how
to change this for a particular block.
For a list of changes in recent versions, see the documentation
for L<Pod::POM::View::Restructured::Changes>.
This module can be downloaded from L<http://www.cpan.org/authors/id/D/DO/DOWENS/>.
=cut
use strict;
use warnings;
use Data::Dumper ();
use Pod::POM;
package Pod::POM::View::Restructured;
our $VERSION = '0.02'; # change in POD below!
use base 'Pod::POM::View::Text';
=pod
=head1 METHODS
=head2 C<new(\%params)>
Constructor. \%params is optional. If present, the following keys are valid:
=over 4
=item C<callbacks>
See documentation below for C<convert_file()>.
=back
=cut
sub new {
my ($class, $params) = @_;
$params = { } unless $params and UNIVERSAL::isa($params, 'HASH');
my $self = bless { seen_something => 0, title_set => 0, params => { } }, ref($class) || $class;
my $callbacks = $params->{callbacks};
$callbacks = { } unless $callbacks;
$self->{callbacks} = $callbacks;
return $self;
}
=pod
=head2 C<convert_file($source_file, $title, $dest_file, $callbacks)>
Converts the POD in C<$source_file> to reStructuredText. If
C<$dest_file> is defined, it writes the output there. If
C<$title> is defined, it is used for the title of the document.
Otherwise, an attempt is made to infer the title from the NAME
section (checks if the body looks like C</\A\s*(\w+(?:::\w+)+)\s+-\s+/s>).
Returns the output as a string.
C<$source_file> and C<$dest_file> can be either file names or file
handles.
=cut
sub convert_file {
my ($self, $source_file, $title, $dest_file, $callbacks) = @_;
my $cb;
if ($callbacks) {
$cb = { %{ $self->{callbacks} }, %$callbacks };
}
else {
$cb = $self->{callbacks};
}
my $view = Pod::POM::View::Restructured->new({ callbacks => $cb });
my $parser = Pod::POM->new;
unless (-r $source_file) {
warn "can't read source file $source_file";
return undef;
}
my $pom = $parser->parse_file($source_file);
$view->{title_set} = 1 if defined($title);
my $out = $pom->present($view);
if (defined($title)) {
$out = $self->_build_header($title, '#', 1) . "\n" . $out;
}
else {
$title = $view->{title};
}
if (defined($dest_file) and $dest_file ne '') {
my $out_fh;
if (UNIVERSAL::isa($dest_file, 'GLOB')) {
$out_fh = $dest_file;
}
else {
unless (open($out_fh, '>', $dest_file)) {
warn "couldn't open output file $dest_file";
return undef;
}
}
print $out_fh $out;
close $out_fh;
}
my $rv = { content => $out, title => $title };
return $rv;
}
=pod
=head2 C<convert_files($file_spec, $index_file, $index_title, $out_dir)>
Converts the files given in C<$file_spec> to reStructuredText.
If C<$index_file> is provided, it is the path to the index file
to be created (with a table of contents pointing to all of the
files created). If C<$index_title> is provided, it is used as
the section title for the index file. C<$out_dir> is the
directory the generated files will be written to.
C<$file_spec> is a reference to an array of hashes specifying
attributes for each file to be converted. The valid keys are:
=over 4
=item C<source_file>
File to convert.
=item C<dest_file>
File to output the reStructuredText. If not provided, a file
name will be generated based on the title.
=item C<title>
Section title for the generated reStructuredText. If not
provided, an attempt will be made to infer the title from the
NAME section in the POD, if it exists. As a last resort, a title
will be generated that looks like "section_(\d+)".
=item C<callbacks>
A reference to a hash containing names and the corresponding callbacks.
Currently the only valid callback is C<link>. It is given the
text inside a LE<lt>E<gt> section from the POD, and is expected to return a
tuple C<($url, $label)>. If the value returned for C<$label> is
undefined, the value of C<$url> is used as the label.
=item C<no_toc>
Causes the item to not be printed to the index or return in the C<toc> field.
=back
This method returns a hash ref with a table of contents (the
C<toc> field) suitable for a reStructuredText table of contents.
E.g.,
my $conv = Pod::POM::View::Restructured->new;
my $files = [
{ source_file => "$base_dir/Restructured.pm" },
{ source_file => "$base_dir/DWIW.pm" },
{ source_file => "$base_dir/Wrapper.pm" },
];
my $rv = $conv->convert_files($files, "$dest_dir/index.rst", 'My Big Test', $dest_dir);
=cut
sub convert_files {
my ($self, $file_spec, $index_file, $index_title, $out_dir) = @_;
my $index_fh = $self->_get_file_handle($index_file, '>');
if ($index_fh and defined($index_title) and $index_title ne '') {
my $header = $self->_build_header($index_title, '#', 1);
# my $line = '#' x length($index_title);
# my $header = $line . "\n" . $index_title . "\n" . $line . "\n\n";
print $index_fh $header;
print $index_fh "\nContents:\n\n";
print $index_fh ".. toctree::\n";
print $index_fh " :maxdepth: 1\n\n";
}
my $count = 0;
my $toc = '';
foreach my $spec (@$file_spec) {
$count++;
my $data = $self->convert_file($spec->{source_file}, $spec->{title},
$spec->{dest_file}, $spec->{callbacks});
my $this_title = $data->{title};
# print STDERR Data::Dumper->Dump([ $this_title ], [ 'this_title' ]) . "\n\n";
unless (defined($this_title) and $this_title !~ /\A\s*\Z/) {
$this_title = 'section_' . $count;
}
my $name = $spec->{dest_file};
if (defined($name)) {
$name =~ s/\.rst\Z//;
}
else {
($name = $this_title) =~ s/\W/_/g;
my $dest_file = $out_dir . '/' . $name . '.rst';
my $out_fh;
unless (open($out_fh, '>', $dest_file)) {
warn "couldn't open output file $dest_file";
return undef;
}
print $out_fh $data->{content};
close $out_fh;
}
unless ($spec->{no_toc}) {
$toc .= ' ' . $name . "\n";
}
if ($index_fh and not $spec->{no_toc}) {
print $index_fh " " . $name . "\n";
}
}
if ($index_fh) {
print $index_fh "\n";
}
return { toc => $toc };
}
sub _get_file_handle {
my ($self, $file, $mode) = @_;
return undef unless defined $file;
if (ref($file) and UNIVERSAL::isa($file, 'GLOB')) {
return $file;
}
$mode = '<' unless $mode;
my $fh;
if ($file ne '') {
unless (open($fh, $mode, $file)) {
warn "couldn't open input file $file: $!";
return undef;
}
}
return $fh;
}
sub view_pod {
my ($self, $node) = @_;
my $content = ".. highlight:: perl\n\n";
return $content . $node->content()->present($self);
}
sub _generic_head {
my ($self, $node, $marker, $do_overline) = @_;
return scalar($self->_generic_head_multi($node, $marker, $do_overline));
}
sub _generic_head_multi {
my ($self, $node, $marker, $do_overline) = @_;
my $title = $node->title()->present($self);
my $content = $node->content()->present($self);
$title = ' ' if $title eq '';
# my $section_line = $marker x length($title);
my $section = $self->_build_header($title, $marker, $do_overline) . "\n" . $content;
# my $section = $title . "\n" . $section_line . "\n\n" . $content;
# if ($do_overline) {
# $section = $section_line . "\n" . $section;
# }
$section .= "\n";
return wantarray ? ($section, $content, $title) : $section;
}
sub _build_header {
my ($self, $text, $marker, $do_overline) = @_;
my $line = $marker x length($text);
my $header = $text . "\n" . $line . "\n";
if ($do_overline) {
$header = $line . "\n" . $header;
}
return "\n" . $header;
}
sub _do_indent {
my ($self, $text, $indent_amount, $dbg) = @_;
my $indent = ' ' x $indent_amount;
# $indent = "'$dbg" . $indent . "'";
my @lines = split /\n/, $text, -1;
foreach my $line (@lines) {
$line = $indent . $line;
}
return join("\n", @lines);
}
sub view_head1 {
my ($self, $node) = @_;
my ($section, $content, $title) = $self->_generic_head_multi($node, '*', 1);
unless ($self->{seen_something} or $self->{title_set}) {
if ($title eq 'NAME') {
$self->{seen_something} = 1;
if ($content =~ /\A\s*(\w+(?:::\w+)+)\s+-\s+/s) {
my $mod_name = $1;
$self->{module_name} = $mod_name;
$self->{title} = $mod_name;
$self->{title_set} = 1;
$section = $self->_build_header($mod_name, '#', 1) . $section;
# my $line = '#' x length($mod_name);
# $section = $line . "\n" . $mod_name . "\n" . $line . "\n\n" . $section;
}
return $section;
}
}
$self->{seen_something} = 1;
return $section;
}
sub view_head2 {
my ($self, $node) = @_;
$self->{seen_something} = 1;
return $self->_generic_head($node, '=');
}
sub view_head3 {
my ($self, $node) = @_;
$self->{seen_something} = 1;
return $self->_generic_head($node, '-');
}
sub view_head4 {
my ($self, $node) = @_;
$self->{seen_something} = 1;
return $self->_generic_head($node, '^');
}
sub view_item {
my ($self, $node) = @_;
$self->{seen_something} = 1;
my $title = $node->title()->present($self);
my $content = $node->content()->present($self);
$title =~ s/\A\s+//;
$title =~ s/\n/ /;
# $content =~ s/\n/\n /g;
# $content = ' ' . $content;
$self->{view_item_count}++;
$content = $self->_do_indent($content, 1, "[[view_item_$self->{view_item_count}]]");
return "\n" . $title . "\n" . $content . "\n\n";
}
sub view_over {
my ($self, $node) = @_;
my $content = $node->content()->present($self);
# my $indent = $node->indent();
return "\n" . $content;
}
sub view_text {
my ($self, $node) = @_;
my @lines = split /\n/, $node;
foreach my $line (@lines) {
$line =~ s/\A\s+//;
}
return join("\n", @lines);
}
sub view_textblock {
my ($self, $text) = @_;
return "\n" . $text . "\n";
}
sub view_verbatim {
my ($self, $node) = @_;
# (my $node_part = ' ' . $node) =~ s/\n/\n /g;
my $node_part = $self->_do_indent($node . '', 1, '[[view_verbatim]]');
my $block_part = ".. code-block:: perl\n\n";
if (defined($self->{next_code_block})) {
my $lang = $self->{next_code_block};
delete $self->{next_code_block};
if ($lang eq 'none') {
# FIXME: need to output a preformatted paragraph here, but no highlighting
$block_part = '';
}
else {
$block_part = ".. code-block:: $lang\n\n";
}
}
my $content = $block_part . $node_part;
return "\n\n" . $content . "\n\n";
}
sub view_for {
my ($self, $node) = @_;
my $fmt = $node->format();
# print STDERR "got for: fmt='$fmt', text='" . $node->text() . "'\n";
if ($fmt eq 'pod2rst') {
my $text = $node->text();
if ($text =~ /\A\s*next-code-block\s*:\s*(\S+)/) {
my $lang = $1;
$self->{next_code_block} = $lang;
return '';
}
return '';
}
return $self->SUPER::view_for($node);
}
sub view_seq_code {
my ($self, $text) = @_;
return '\ ``' . $text . '``\ ';
}
sub view_seq_bold {
my ($self, $text) = @_;
$text =~ s/\*/\\*/g;
$text =~ s/\`/\\`/g;
return '\ **' . $text . '**\ ';
}
sub view_seq_italic {
my ($self, $text) = @_;
$text =~ s/\*/\\*/g;
$text =~ s/\`/\\`/g;
return '\ *' . $text . '*\ ';
}
sub view_seq_file {
my ($self, $text) = @_;
$text =~ s/\*/\\*/g;
$text =~ s/\`/\\`/g;
return '\ *' . $text . '*\ ';
}
sub view_seq_text {
my ($self, $node) = @_;
my $text = $node . '';
$text =~ s/\*/\\*/g;
$text =~ s/\`/\\`/g;
return $text;
}
sub view_seq_zero {
return '';
}
sub view_seq_link {
my ($self, $text) = @_;
# FIXME: determine if has label, if manpage, etc., and pass that info along to the callback,
# instead of just the text, e.g.,
# $link_cb->($label, $name, $sec, $url);
my $link_cb = $self->{callbacks}{link};
if ($link_cb) {
my ($url, $label) = $link_cb->($text);
if (defined($url)) {
if ($url eq '' and defined($label) and $label ne '') {
$text = $label;
}
elsif (defined($label) and $label ne '') {
$text = qq{`$label <$url>`_};
}
else {
$text = qq{`$url <$url>`_};
}
return $text;
}
}
if ($text =~ m{\A/(.+)}) {
(my $section = $1) =~ s/\A"(.+)"/$1/;
$text = qq{`$section`_};
}
elsif ($text =~ m{\Ahttps?://}) {
$text = qq{`$text <$text>`_};
}
elsif ($text =~ /::/) {
my $label = $text;
my $module = $text;
if ($text =~ /\A(.+?)\|(.+::.+)/) {
$label = $1;
$module = $2;
}
$module = $self->_url_encode($module);
my $url = "http://search.cpan.org/search?query=$module&mode=module";
$text = qq{`$label <$url>`_};
}
return $text;
}
sub _url_encode {
my ($self, $str) = @_;
use bytes;
$str =~ s{([^A-Za-z0-9_])}{sprintf("%%%02x", ord($1))}eg;
return $str;
}
=pod
=head1 POD commands specifically for reStructuredText
The following sequences can be used in POD to request actions specifically for this module.
=head2 =Z<>for pod2rst next-code-block: I<lang>
This sets up the next verbatim section, i.e., the next indented
paragraph to be hilighted according to the syntax of the
programming/markup/config language I<lang>. Verbatim sections
are assumed to be Perl code by default. Sphinx uses Pygments to
do syntax hilighting in these sections, so you can use any value
for I<lang> that Pygments supports, e.g., Python, C, C++,
Javascript, SQL, etc.
=head1 EXAMPLES
=over 4
=item Converting a single file using C<pod2rst>
=for pod2rst next-code-block: bash
pod2rst --infile=Restructured.pm --outfile=restructured.rst
=back
B<Need to document:>
=over 4
=item B<Document example of setting up sphinx build, generating rst from pod, and building>
=back
=head1 TODO
=over 4
=item code hilighting
Currently, a verbatim block (indented paragraph) gets output as a
Perl code block by default in reStructuredText. There should be
an option (e.g., in the constructor) to change the language for
hilighting purposes (for all verbatim blocks), or disable syntax
hilighting and just make it a preformatted paragraph. There is a
way to do this in POD (see L</"POD commands specifically for reStructuredText">),
but there should also be an option in the constructor.
=item improve escaping
Text blocks are not escaped properly, so it is currently possible
to invoke a command in reStructuredText by accident.
=back
=head1 DEPENDENCIES
Inherits from L<Pod::POM::View::Text> that comes with the Pod::POM distribution.
=head1 AUTHOR
Don Owens <don@regexguy.com>
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2010 Don Owens <don@regexguy.com>. All rights reserved.
This is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. See perlartistic.
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=head1 SEE ALSO
L<Pod::POM>
L<Pod::POM::View::HTML>
L<pod2rst> (distributed with Pod::POM::View::HTML)
reStructuredText: L<http://docutils.sourceforge.net/rst.html>
Sphinx (uses reStructuredText): L<http://sphinx.pocoo.org/>
Pygments (used by Sphinx for syntax highlighting): L<http://pygments.org/>
=head1 VERSION
0.02
=cut
1;
# Local Variables: #
# mode: perl #
# tab-width: 4 #
# indent-tabs-mode: nil #
# cperl-indent-level: 4 #
# perl-indent-level: 4 #
# End: #
# vim:set ai si et sta ts=4 sw=4 sts=4:
POD_POM_VIEW_RESTRUCTURED
$fatpacked{"Pod/POM/View/Restructured/Changes.pm"} = <<'POD_POM_VIEW_RESTRUCTURED_CHANGES';
# Original authors: don
# $Revision: $
=pod
=head1 NAME
Pod::POM::View::Restructured::Changes - List of major changes in Pod::POM::View::Restructured
=head1 CHANGES
=head2 Version 0.02
=over 4
=item Added documentation for changes.
=item Added C<callbacks> option.
=item Added C<no_toc> option.
=item Fixed bug encountered when no index is being output.
=item Fixed section links.
=back
=head2 Version 0.01
=over 4
=item Initial release.
=back
=cut
1;
POD_POM_VIEW_RESTRUCTURED_CHANGES
$fatpacked{"Pod/POM/View/Text.pm"} = <<'POD_POM_VIEW_TEXT';
#============================================================= -*-Perl-*-
#
# Pod::POM::View::Text
#
# DESCRIPTION
# Text view of a Pod Object Model.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
#
# COPYRIGHT
# Copyright (C) 2000 Andy Wardley. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Text.pm 77 2009-08-20 20:44:14Z ford $
#
#========================================================================
package Pod::POM::View::Text;
require 5.004;
use strict;
use Pod::POM::View;
use parent qw( Pod::POM::View );
use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD $INDENT );
use Text::Wrap;
$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
$INDENT = 0;
sub new {
my $class = shift;
my $args = ref $_[0] eq 'HASH' ? shift : { @_ };
bless {
INDENT => 0,
%$args,
}, $class;
}
sub view {
my ($self, $type, $item) = @_;
if ($type =~ s/^seq_//) {
return $item;
}
elsif (UNIVERSAL::isa($item, 'HASH')) {
if (defined $item->{ content }) {
return $item->{ content }->present($self);
}
elsif (defined $item->{ text }) {
my $text = $item->{ text };
return ref $text ? $text->present($self) : $text;
}
else {
return '';
}
}
elsif (! ref $item) {
return $item;
}
else {
return '';
}
}
sub view_head1 {
my ($self, $head1) = @_;
my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
my $pad = ' ' x $$indent;
local $Text::Wrap::unexpand = 0;
my $title = wrap($pad, $pad,
$head1->title->present($self));
$$indent += 4;
my $output = "$title\n" . $head1->content->present($self);
$$indent -= 4;
return $output;
}
sub view_head2 {
my ($self, $head2) = @_;
my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
my $pad = ' ' x $$indent;
local $Text::Wrap::unexpand = 0;
my $title = wrap($pad, $pad,
$head2->title->present($self));
$$indent += 4;
my $output = "$title\n" . $head2->content->present($self);
$$indent -= 4;
return $output;
}
sub view_head3 {
my ($self, $head3) = @_;
my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
my $pad = ' ' x $$indent;
local $Text::Wrap::unexpand = 0;
my $title = wrap($pad, $pad,
$head3->title->present($self));
$$indent += 4;
my $output = "$title\n" . $head3->content->present($self);
$$indent -= 4;
return $output;
}
sub view_head4 {
my ($self, $head4) = @_;
my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
my $pad = ' ' x $$indent;
local $Text::Wrap::unexpand = 0;
my $title = wrap($pad, $pad,
$head4->title->present($self));
$$indent += 4;
my $output = "$title\n" . $head4->content->present($self);
$$indent -= 4;
return $output;
}
#------------------------------------------------------------------------
# view_over($self, $over)
#
# Present an =over block - this is a blockquote if there are no =items
# within the block.
#------------------------------------------------------------------------
sub view_over {
my ($self, $over) = @_;
if (@{$over->item}) {
return $over->content->present($self);
}
else {
my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
my $pad = ' ' x $$indent;
$$indent += 4;
my $content = $over->content->present($self);
$$indent -= 4;
return $content;
}
}
sub view_item {
my ($self, $item) = @_;
my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
my $pad = ' ' x $$indent;
local $Text::Wrap::unexpand = 0;
my $title = wrap($pad . '* ', $pad . ' ',
$item->title->present($self));
$$indent += 2;
my $content = $item->content->present($self);
$$indent -= 2;
return "$title\n\n$content";
}
sub view_for {
my ($self, $for) = @_;
return '' unless $for->format() =~ /\btext\b/;
return $for->text()
. "\n\n";
}
sub view_begin {
my ($self, $begin) = @_;
return '' unless $begin->format() =~ /\btext\b/;
return $begin->content->present($self);
}
sub view_textblock {
my ($self, $text) = @_;
my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
$text =~ s/\s+/ /mg;
$$indent ||= 0;
my $pad = ' ' x $$indent;
local $Text::Wrap::unexpand = 0;
return wrap($pad, $pad, $text) . "\n\n";
}
sub view_verbatim {
my ($self, $text) = @_;
my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
my $pad = ' ' x $$indent;
$text =~ s/^/$pad/mg;
return "$text\n\n";
}
sub view_seq_bold {
my ($self, $text) = @_;
return "*$text*";
}
sub view_seq_italic {
my ($self, $text) = @_;
return "_${text}_";
}
sub view_seq_code {
my ($self, $text) = @_;
return "'$text'";
}
sub view_seq_file {
my ($self, $text) = @_;
return "_${text}_";
}
my $entities = {
gt => '>',
lt => '<',
amp => '&',
quot => '"',
};
sub view_seq_entity {
my ($self, $entity) = @_;
return $entities->{ $entity } || $entity;
}
sub view_seq_index {
return '';
}
sub view_seq_link {
my ($self, $link) = @_;
if ($link =~ s/^.*?\|//) {
return $link;
}
else {
return "the $link manpage";
}
}
1;
=head1 NAME
Pod::POM::View::Text
=head1 DESCRIPTION
Text view of a Pod Object Model.
=head1 METHODS
=over 4
=item C<view($self, $type, $item)>
=item C<view_pod($self, $pod)>
=item C<view_head1($self, $head1)>
=item C<view_head2($self, $head2)>
=item C<view_head3($self, $head3)>
=item C<view_head4($self, $head4)>
=item C<view_over($self, $over)>
=item C<view_item($self, $item)>
=item C<view_for($self, $for)>
=item C<view_begin($self, $begin)>
=item C<view_textblock($self, $textblock)>
=item C<view_verbatim($self, $verbatim)>
=item C<view_meta($self, $meta)>
=item C<view_seq_bold($self, $text)>
Returns the text of a C<BE<lt>E<gt>> sequence in 'bold' (i.e. surrounded by asterisks, like *this*).
=item C<view_seq_italic($self, $text)>
Returns the text of a C<IE<lt>E<gt>> sequence in 'italics' (i.e. surrounded by underscores, like _this_).
=item C<view_seq_code($self, $text)>
=item C<view_seq_file($self, $text)>
=item C<view_seq_entity($self, $text)>
=item C<view_seq_index($self, $text)>
Returns an empty string. Index sequences are suppressed in text view.
=item C<view_seq_link($self, $text)>
=back
=head1 AUTHOR
Andy Wardley E<lt>abw@kfs.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2000 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
POD_POM_VIEW_TEXT
s/^ //mg for values %fatpacked;
unshift @INC, sub {
if (my $fat = $fatpacked{$_[1]}) {
if ($] < 5.008) {
return sub {
return 0 unless length $fat;
$fat =~ s/^([^\n]*\n?)//;
$_ = $1;
return 1;
};
}
open my $fh, '<', \$fat
or die "FatPacker error loading $_[1] (could be a perl installation issue?)";
return $fh;
}
return
};
} # END OF FATPACK CODE
#!/usr/bin/env perl
use 5.010; # for \K
use strict;
use warnings;
use English qw(-no_match_vars);
use IO::File;
use File::Basename qw(basename);
use Pod::POM::View::Restructured;
my $input_file = shift @ARGV or die "Need an input file";
my $nofix = scalar @ARGV;
my $tool = basename($input_file);
open my $in_fh, q{<:encoding(UTF-8)}, $input_file
or die "Cannot open $input_file: $!";
open my $out_fh, q{>}, \my $out;
my $conv = Pod::POM::View::Restructured->new();
my $output = $conv->convert_file($in_fh, undef, $out_fh, { link => \&format_links });
close $in_fh;
close $out_fh;
if (!defined($output)) {
die "Failed to convert!";
}
my $header =
".. program:: $tool\n\n" .
('=' x (length($tool) + 11)) . "\n" .
":program:`$tool`\n" .
('=' x (length($tool) + 11)) . "\n\n";
open my $in, q{<:encoding(UTF-8)}, \$out;
local $INPUT_RECORD_SEPARATOR = '';
my $in_code_block = 0;
my $section = '';
my $fixed_output = '';
while (my $para = <$in>) {
if ( $nofix ) {
$fixed_output .= $para;
next;
}
next if $para =~ m/^\.\. highlight:: perl/;
$in_code_block = $para =~ m/^\s{2,}/ ? 1 : 0;
if ($para =~ m/^\*{2,}\n([\w\s,-]+)\n\*{2,}$/m) {
$fixed_output .= "$1\n" .
('=' x length $1) .
"\n\n";
$section = $1;
}
elsif ($para =~ m/^Usage: /) {
$para =~ s/^Usage: //;
$fixed_output .= "Usage\n" .
"-----\n\n" .
"::\n\n" .
" $para";
}
elsif ($para =~ m/^Examples:/) {
$fixed_output .= "Examples\n" .
"--------\n\n";
}
else {
$para =~ s/\.\. code-block:: perl/.. code-block:: bash/mg;
$para =~ s/`+$tool`+/$tool/g;
$para =~ s/([^\/])$tool/$1:program:`$tool`/g unless $in_code_block;
$para =~ s/^$tool/:program:`$tool`/gm;
$para =~ s/^--(\S+)$/.. option:: --$1/mg;
$para =~ s/"--(\S+)"/:option:`--$1`/g;
$para =~ s/\\\*/*/g;
$para =~ s/\\ //g;
$para =~ s/^[ ]+$//mg;
$para =~ s/^\n\n/\n/mg;
$para =~ s/code-block:: bash(\s+)CREATE/code-block:: sql$1CREATE/sg;
$para =~ s/\*\*:program/** :program/g;
if ( ($section || '') eq 'OUTPUT' ) {
$para =~ s/^([A-Z_]+)\n\n/$1\n/;
}
$fixed_output .= $para;
}
}
close $in;
if ($nofix) {
print $fixed_output;
}
else {
print $header . $fixed_output;
}
sub format_links {
if ( my ($label, $url) = split /\|/, $_[0] ) {
return $url, $label;
}
else {
local $conv->{callbacks}{link};
return $conv->view_seq_link(@_)
}
}
|