/usr/share/perl5/Rose/DB/Object/Metadata.pm is in librose-db-object-perl 1:0.815-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 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 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 | package Rose::DB::Object::Metadata;
use strict;
use Carp();
use Rose::Object;
our @ISA = qw(Rose::Object);
use Rose::DB::Object::Util qw(lazy_column_values_loaded_key);
use Rose::DB::Object::Constants
qw(PRIVATE_PREFIX STATE_IN_DB MODIFIED_COLUMNS);
use Rose::DB::Object::ConventionManager;
use Rose::DB::Object::ConventionManager::Null;
use Rose::DB::Object::Metadata::PrimaryKey;
use Rose::DB::Object::Metadata::UniqueKey;
use Rose::DB::Object::Metadata::ForeignKey;
use Rose::DB::Object::Metadata::Column::Scalar;
use Rose::DB::Object::Metadata::Relationship::OneToOne;
# Attempt to load Scalar::Util::Clone at runtime and ignore any errors
# to keep it from being a "hard" requirement.
eval { local $@; require Scalar::Util::Clone };
use Clone(); # This is the backup clone method
our $VERSION = '0.799';
our $Debug = 0;
#
# Object data
#
use Rose::Object::MakeMethods::Generic
(
scalar =>
[
'class',
'error',
'pre_init_hook',
'post_init_hook',
'_object_default_manager_base_class',
],
'scalar --get_set_init' =>
[
'db',
'db_id',
'primary_key',
'column_name_to_method_name_mapper',
'original_class',
'auto_prime_caches',
],
boolean =>
[
allow_inline_column_values => { default => 0 },
is_initialized => { default => 0 },
is_auto_initializating => { default => 0 },
allow_auto_initialization => { default => 0 },
was_auto_initialized => { default => 0 },
initialized_foreign_keys => { default => 0 },
default_load_speculative => { default => 0 },
auto_load_related_classes => { default => 1 },
default_update_changes_only => { default => 0 },
default_insert_changes_only => { default => 0 },
default_cascade_save => { default => 0 },
default_smart_modification => { default => 0 },
include_predicated_unique_indexes => { default => 0 },
],
'array --get_set_inited' =>
[
'columns_ordered',
'nonpersistent_columns_ordered',
]
);
#
# Class data
#
use Rose::Class::MakeMethods::Generic
(
inheritable_scalar =>
[
'dbi_prepare_cached',
'default_column_undef_overrides_default',
'_class_default_manager_base_class',
],
inheritable_hash =>
[
column_type_classes => { interface => 'get_set_all' },
column_type_names => { interface => 'keys', hash_key => 'column_type_classes' },
_column_type_class => { interface => 'get_set', hash_key => 'column_type_classes' },
_delete_column_type_class => { interface => 'delete', hash_key => 'column_type_classes' },
auto_helper_classes => { interface => 'get_set_all' },
delete_auto_helper_class => { interface => 'delete', hash_key => 'auto_helper_classes' },
relationship_type_classes => { interface => 'get_set_all' },
relationship_type_class => { interface => 'get_set', hash_key => 'relationship_type_classes' },
delete_relationship_type_class => { interface => 'delete', hash_key => 'relationship_type_classes' },
class_registry => => { interface => 'get_set_all' },
convention_manager_classes => { interface => 'get_set_all' },
convention_manager_class => { interface => 'get_set', hash_key => 'convention_manager_classes' },
delete_convention_manager_class => { interface => 'delete', hash_key => 'convention_manager_classes' },
],
);
__PACKAGE__->default_manager_base_class('Rose::DB::Object::Manager');
__PACKAGE__->dbi_prepare_cached(1);
__PACKAGE__->class_registry({});
__PACKAGE__->auto_helper_classes
(
'informix' => 'Rose::DB::Object::Metadata::Auto::Informix',
'pg' => 'Rose::DB::Object::Metadata::Auto::Pg',
'mysql' => 'Rose::DB::Object::Metadata::Auto::MySQL',
'sqlite' => 'Rose::DB::Object::Metadata::Auto::SQLite',
'oracle' => 'Rose::DB::Object::Metadata::Auto::Oracle',
'generic' => 'Rose::DB::Object::Metadata::Auto::Generic',
);
__PACKAGE__->convention_manager_classes
(
'default' => 'Rose::DB::Object::ConventionManager',
'null' => 'Rose::DB::Object::ConventionManager::Null',
);
__PACKAGE__->column_type_classes
(
'scalar' => 'Rose::DB::Object::Metadata::Column::Scalar',
'char' => 'Rose::DB::Object::Metadata::Column::Character',
'character' => 'Rose::DB::Object::Metadata::Column::Character',
'varchar' => 'Rose::DB::Object::Metadata::Column::Varchar',
'varchar2' => 'Rose::DB::Object::Metadata::Column::Varchar',
'nvarchar' => 'Rose::DB::Object::Metadata::Column::Varchar',
'nvarchar2' => 'Rose::DB::Object::Metadata::Column::Varchar',
'string' => 'Rose::DB::Object::Metadata::Column::Varchar',
'text' => 'Rose::DB::Object::Metadata::Column::Text',
'blob' => 'Rose::DB::Object::Metadata::Column::Blob',
'bytea' => 'Rose::DB::Object::Metadata::Column::Pg::Bytea',
'bits' => 'Rose::DB::Object::Metadata::Column::Bitfield',
'bitfield' => 'Rose::DB::Object::Metadata::Column::Bitfield',
'bool' => 'Rose::DB::Object::Metadata::Column::Boolean',
'boolean' => 'Rose::DB::Object::Metadata::Column::Boolean',
'int' => 'Rose::DB::Object::Metadata::Column::Integer',
'integer' => 'Rose::DB::Object::Metadata::Column::Integer',
'tinyint' => 'Rose::DB::Object::Metadata::Column::Integer',
'smallint' => 'Rose::DB::Object::Metadata::Column::Integer',
'mediumint' => 'Rose::DB::Object::Metadata::Column::Integer',
'bigint' => 'Rose::DB::Object::Metadata::Column::BigInt',
'serial' => 'Rose::DB::Object::Metadata::Column::Serial',
'bigserial' => 'Rose::DB::Object::Metadata::Column::BigSerial',
'enum' => 'Rose::DB::Object::Metadata::Column::Enum',
'num' => 'Rose::DB::Object::Metadata::Column::Numeric',
#'number' => 'Rose::DB::Object::Metadata::Column::Numeric',
'numeric' => 'Rose::DB::Object::Metadata::Column::Numeric',
'decimal' => 'Rose::DB::Object::Metadata::Column::Numeric',
'float' => 'Rose::DB::Object::Metadata::Column::Float',
'float8' => 'Rose::DB::Object::Metadata::Column::DoublePrecision',
'double precision' => 'Rose::DB::Object::Metadata::Column::DoublePrecision',
'time' => 'Rose::DB::Object::Metadata::Column::Time',
'interval' => 'Rose::DB::Object::Metadata::Column::Interval',
'date' => 'Rose::DB::Object::Metadata::Column::Date',
'datetime' => 'Rose::DB::Object::Metadata::Column::Datetime',
'timestamp' => 'Rose::DB::Object::Metadata::Column::Timestamp',
'timestamp with time zone' => 'Rose::DB::Object::Metadata::Column::TimestampWithTimeZone',
'timestamp without time zone' => 'Rose::DB::Object::Metadata::Column::Timestamp',
'datetime year to fraction' => 'Rose::DB::Object::Metadata::Column::DatetimeYearToFraction',
'datetime year to fraction(1)' => 'Rose::DB::Object::Metadata::Column::DatetimeYearToFraction1',
'datetime year to fraction(2)' => 'Rose::DB::Object::Metadata::Column::DatetimeYearToFraction2',
'datetime year to fraction(3)' => 'Rose::DB::Object::Metadata::Column::DatetimeYearToFraction3',
'datetime year to fraction(4)' => 'Rose::DB::Object::Metadata::Column::DatetimeYearToFraction4',
'datetime year to fraction(5)' => 'Rose::DB::Object::Metadata::Column::DatetimeYearToFraction5',
'datetime year to second' => 'Rose::DB::Object::Metadata::Column::DatetimeYearToSecond',
'datetime year to minute' => 'Rose::DB::Object::Metadata::Column::DatetimeYearToMinute',
'datetime year to month' => 'Rose::DB::Object::Metadata::Column::DatetimeYearToMonth',
'epoch' => 'Rose::DB::Object::Metadata::Column::Epoch',
'epoch hires' => 'Rose::DB::Object::Metadata::Column::Epoch::HiRes',
'array' => 'Rose::DB::Object::Metadata::Column::Array',
'set' => 'Rose::DB::Object::Metadata::Column::Set',
'chkpass' => 'Rose::DB::Object::Metadata::Column::Pg::Chkpass',
);
__PACKAGE__->relationship_type_classes
(
'one to one' => 'Rose::DB::Object::Metadata::Relationship::OneToOne',
'one to many' => 'Rose::DB::Object::Metadata::Relationship::OneToMany',
'many to one' => 'Rose::DB::Object::Metadata::Relationship::ManyToOne',
'many to many' => 'Rose::DB::Object::Metadata::Relationship::ManyToMany',
);
#
# Methods
#
sub init_column_name_to_method_name_mapper() { 0 }
our %Objects;
sub new
{
my($this_class, %args) = @_;
my $class = $args{'class'} or Carp::croak "Missing required 'class' parameter";
return $Objects{$class} ||= shift->SUPER::new(@_);
}
sub init
{
my($self) = shift;
# This attribute will be accessed many times, and a default
# of 0 is usually a "faster false" than undef.
$self->sql_qualify_column_names_on_load(0);
$self->SUPER::init(@_);
}
sub init_original_class { ref shift }
sub init_auto_prime_caches { $ENV{'MOD_PERL'} ? 1 : 0 }
sub default_manager_base_class
{
my($self_or_class) = shift;
if(ref($self_or_class))
{
return $self_or_class->_object_default_manager_base_class(@_) ||
ref($self_or_class)->_class_default_manager_base_class;
}
return $self_or_class->_class_default_manager_base_class(@_);
}
sub reset
{
my($self) = shift;
$self->is_initialized(0);
$self->allow_auto_initialization(0);
$self->was_auto_initialized(0);
$self->initialized_foreign_keys(0);
return;
}
sub clone
{
my($self) = shift;
# The easy way: use Scalar::Util::Clone
if(defined $Scalar::Util::Clone::VERSION)
{
return Scalar::Util::Clone::clone($self);
}
# The hard way: Clone.pm plus mucking
my $meta = Clone::clone($self);
# Reset all the parent back-links
foreach my $item (grep { defined } $meta->columns, $meta->primary_key,
$meta->unique_keys, $meta->foreign_keys,
$meta->relationships)
{
$item->parent($meta);
}
return $meta;
}
sub allow_inheritance_from_meta
{
my($class, $meta) = @_;
return $meta->num_columns > 0 ? 1 : 0;
}
sub for_class
{
my($meta_class, $class) = (shift, shift);
return $Objects{$class} if($Objects{$class});
# Clone an ancestor meta object
foreach my $parent_class (__get_parents($class))
{
if(my $parent_meta = $Objects{$parent_class})
{
next unless($meta_class->allow_inheritance_from_meta($parent_meta));
my $meta = $parent_meta->clone;
$meta->reset(0);
$meta->class($class);
return $Objects{$class} = $meta;
}
}
return $Objects{$class} = $meta_class->new(class => $class);
}
sub __get_parents
{
my($class) = shift;
my @parents;
no strict 'refs';
foreach my $sub_class (@{"${class}::ISA"})
{
push(@parents, __get_parents($sub_class)) if($sub_class->isa('Rose::DB::Object'));
}
return $class, @parents;
}
sub clear_all_dbs
{
my($class) = shift;
foreach my $obj_class ($class->registered_classes)
{
$obj_class->meta->db(undef);
}
}
sub error_mode
{
return $_[0]->{'error_mode'} ||= $_[0]->init_error_mode
unless(@_ > 1);
my($self, $mode) = @_;
unless($mode =~ /^(?:return|carp|croak|cluck|confess|fatal)$/)
{
Carp::croak "Invalid error mode: '$mode'";
}
return $self->{'error_mode'} = $mode;
}
sub init_error_mode { 'fatal' }
sub handle_error
{
my($self, $object) = @_;
my $mode = $self->error_mode;
return if($mode eq 'return');
my $level = $Carp::CarpLevel;
local $Carp::CarpLevel = $level + 1;
if($mode eq 'croak' || $mode eq 'fatal')
{
Carp::croak $object->error;
}
elsif($mode eq 'carp')
{
Carp::carp $object->error;
}
elsif($mode eq 'cluck')
{
Carp::cluck $object->error;
}
elsif($mode eq 'confess')
{
Carp::confess $object->error;
}
else
{
Carp::croak "(Invalid error mode set: '$mode') - ", $object->error;
}
return 1;
}
sub setup
{
my($self) = shift;
return 1 if($self->is_initialized);
my $init_args = [];
my $auto_init = 0;
PAIR: while(@_)
{
my $method = shift;
if(ref $method eq 'CODE')
{
$method->($self);
next PAIR;
}
my $args = shift;
if($method =~ /^((?:auto_(?!helper)|(?:default_)?perl_)\w*)$/)
{
$self->init_auto_helper;
}
if($method eq 'initialize')
{
$init_args = ref $args ? $args : [ $args ];
next PAIR;
}
elsif($method eq 'auto_initialize' || $method eq 'auto')
{
unless($method eq 'auto' && !ref $args)
{
$init_args = ref $args ? $args : [ $args ];
}
$auto_init = 1;
next PAIR;
}
elsif($method eq 'helpers')
{
require Rose::DB::Object::Helpers;
Rose::DB::Object::Helpers->import(
'--target-class' => $self->class, (ref $args eq 'ARRAY' ? @$args : $args));
next PAIR;
}
unless($self->can($method))
{
Carp::croak "Invalid parameter name: '$method'";
}
if(ref $args eq 'ARRAY')
{
# Special case for the unique_key and add_unique_key methods
# when the argument is a single array reference containing only
# non-reference values
if(($method eq 'unique_key' || $method eq 'add_unique_key') &&
!grep { ref } @$args)
{
$self->$method($args);
}
else
{
$self->$method(@$args);
}
}
else
{
$self->$method($args);
}
}
if($auto_init)
{
$self->auto_initialize(@$init_args);
}
else
{
$self->initialize(@$init_args);
}
return 1;
}
sub init_db
{
my($self) = shift;
my $class = $self->class or die "Missing class!";
my $db = $self->class->init_db or
Carp::croak "Could not init_db() for class $class - are you sure that ",
"Rose::DB's data sources are set up?";
$self->{'db_id'} = $db->{'id'};
return $db;
}
sub init_db_id
{
my($self) = shift;
$self->init_db;
return $self->{'db_id'};
}
sub init_convention_manager { shift->convention_manager_class('default')->new }
sub convention_manager
{
my($self) = shift;
if(@_)
{
my $mgr = shift;
# Setting to undef means use the null convention manager
if(!defined $mgr)
{
return $self->{'convention_manager'} =
Rose::DB::Object::ConventionManager::Null->new(parent => $self);
}
elsif(!ref $mgr)
{
if(UNIVERSAL::isa($mgr, 'Rose::DB::Object::ConventionManager'))
{
$mgr = $mgr->new;
}
else
{
my $class = $self->convention_manager_class($mgr) or
Carp::croak "No convention manager class registered under the name '$mgr'";
$mgr = $class->new;
}
}
elsif(!UNIVERSAL::isa($mgr, 'Rose::DB::Object::ConventionManager'))
{
Carp::croak "$mgr is not a Rose::DB::Object::ConventionManager-derived object";
}
$mgr->parent($self);
return $self->{'convention_manager'} = $mgr;
}
if(defined $self->{'convention_manager'})
{
return $self->{'convention_manager'};
}
my $mgr = $self->init_convention_manager;
$mgr->parent($self);
return $self->{'convention_manager'} = $mgr;
}
sub cached_objects_expire_in { shift->class->cached_objects_expire_in(@_) }
sub clear_object_cache { shift->class->clear_object_cache(@_) }
sub prepare_select_options
{
@_ > 1 ? $_[0]->{'prepare_select_options'} = $_[1] :
$_[0]->{'prepare_select_options'} ||= {}
}
sub prepare_insert_options
{
@_ > 1 ? $_[0]->{'prepare_insert_options'} = $_[1] :
$_[0]->{'prepare_insert_options'} ||= {}
}
sub prepare_update_options
{
@_ > 1 ? $_[0]->{'prepare_update_options'} = $_[1] :
$_[0]->{'prepare_update_options'} ||= {}
}
sub prepare_delete_options
{
@_ > 1 ? $_[0]->{'prepare_delete_options'} = $_[1] :
$_[0]->{'prepare_delete_options'} ||= {}
}
sub prepare_bulk_delete_options
{
@_ > 1 ? $_[0]->{'prepare_bulk_delete_options'} = $_[1] :
$_[0]->{'prepare_bulk_delete_options'} ||=
$_[0]->prepare_delete_options;
}
sub prepare_bulk_update_options
{
@_ > 1 ? $_[0]->{'prepare_bulk_update_options'} = $_[1] :
$_[0]->{'prepare_bulk_update_options'} ||=
$_[0]->prepare_update_options;
}
sub prepare_options
{
my($self, $options) = @_;
Carp::croak "Missing required hash ref argument to prepare_options()"
unless(ref $options eq 'HASH');
$self->prepare_select_options({ %$options });
$self->prepare_insert_options({ %$options });
$self->prepare_update_options({ %$options });
$self->prepare_delete_options({ %$options });
}
sub table
{
unless(@_ > 1)
{
return $_[0]->{'table'} ||= $_[0]->convention_manager->auto_table_name;
}
$_[0]->_clear_table_generated_values;
return $_[0]->{'table'} = $_[1];
}
sub catalog
{
return $_[0]->{'catalog'} unless(@_ > 1);
$_[0]->_clear_table_generated_values;
return $_[0]->{'catalog'} = $_[1];
}
sub select_catalog
{
my($self, $db) = @_;
return undef if($db && !$db->supports_catalog);
return $self->{'catalog'} || ($db ? $db->catalog : undef);
}
sub schema
{
return $_[0]->{'schema'} unless(@_ > 1);
$_[0]->_clear_table_generated_values;
return $_[0]->{'schema'} = $_[1];
}
sub select_schema
{
my($self, $db) = @_;
return undef if($db && !$db->supports_schema);
return $self->{'schema'} || ($db ? $db->schema : undef);
}
sub sql_qualify_column_names_on_load
{
my($self) = shift;
if(@_)
{
my $value = $_[0] ? 1 : 0;
no warnings 'uninitialized';
if($value != $self->{'sql_qualify_column_names_on_load'})
{
$self->{'sql_qualify_column_names_on_load'} = $value;
$self->_clear_column_generated_values;
$self->prime_caches if($self->is_initialized);
}
}
return $self->{'sql_qualify_column_names_on_load'};
}
sub key_column_names
{
my($self) = shift;
$self->{'key_column_names'} ||=
[ $self->primary_key_columns, $self->unique_keys_column_names ];
return wantarray ? @{$self->{'key_column_names'}} : $self->{'key_column_names'};
}
sub init_primary_key
{
Rose::DB::Object::Metadata::PrimaryKey->new(parent => shift);
}
sub primary_key_generator { shift->primary_key->generator(@_) }
sub primary_key_columns { shift->primary_key->columns(@_) }
sub primary_key_column_names { shift->primary_key->column_names(@_) }
sub pk_columns { shift->primary_key_columns(@_) }
sub primary_key_column_names_or_aliases
{
my($self) = shift;
if($self->{'primary_key_column_names_or_aliases'})
{
return $self->{'primary_key_column_names_or_aliases'};
}
return $self->{'primary_key_column_names_or_aliases'} =
[ map { $_->alias || $_->name } $self->primary_key_columns ];
}
sub init_primary_key_column_info
{
my($self) = shift;
my $pk_position = 0;
foreach my $col_name ($self->primary_key_column_names)
{
$pk_position++;
my $column = $self->column($col_name) or next;
$column->is_primary_key_member(1);
$column->primary_key_position($pk_position);
}
$self->_clear_primary_key_column_generated_values;
# Init these by asking for them
$self->primary_key_column_accessor_names;
$self->primary_key_column_mutator_names;
return;
}
sub add_primary_key_columns
{
my($self) = shift;
$self->primary_key->add_columns(@_);
$self->init_primary_key_column_info;
return;
}
sub add_primary_key_column { shift->add_primary_key_columns(@_) }
sub add_unique_keys
{
my($self) = shift;
if(@_ == 1 && ref $_[0] eq 'ARRAY')
{
push @{$self->{'unique_keys'}},
Rose::DB::Object::Metadata::UniqueKey->new(parent => $self, columns => $_[0]);
}
else
{
push @{$self->{'unique_keys'}}, map
{
UNIVERSAL::isa($_, 'Rose::DB::Object::Metadata::UniqueKey') ?
($_->parent($self), $_) :
ref $_ eq 'HASH' ?
Rose::DB::Object::Metadata::UniqueKey->new(parent => $self, %$_) :
Rose::DB::Object::Metadata::UniqueKey->new(parent => $self, columns => $_)
}
@_;
}
return;
}
sub unique_key_by_name
{
my($self, $name) = @_;
foreach my $uk ($self->unique_keys)
{
return $uk if($uk->name eq $name);
}
return undef;
}
sub add_unique_key { shift->add_unique_keys(@_) }
sub unique_key { \shift->add_unique_keys(@_) }
sub delete_unique_keys { $_[0]->{'unique_keys'} = [] }
sub unique_keys
{
my($self) = shift;
if(@_)
{
$self->delete_unique_keys;
$self->add_unique_keys(@_);
}
wantarray ? @{$self->{'unique_keys'} ||= []} : ($self->{'unique_keys'} ||= []);
}
sub unique_keys_column_names
{
wantarray ? map { scalar $_->column_names } @{shift->{'unique_keys'} ||= []} :
[ map { scalar $_->column_names } @{shift->{'unique_keys'} ||= []} ];
}
sub delete_column
{
my($self, $name) = @_;
delete $self->{'columns'}{$name};
# Remove from ordered list too
my $columns = $self->columns_ordered;
for(my $i = 0; $i < @$columns; $i++)
{
if($columns->[$i]->name eq $name)
{
splice(@$columns, $i, 1);
last;
}
}
return;
}
sub delete_columns
{
my($self, $name) = @_;
$self->{'columns'} = {};
$self->{'columns_ordered'} = [];
return;
}
sub delete_nonpersistent_columns
{
my($self, $name) = @_;
$self->{'nonpersistent_columns'} = {};
$self->{'nonpersistent_columns_ordered'} = [];
return;
}
sub delete_nonpersistent_column
{
my($self, $name) = @_;
delete $self->{'nonpersistent_columns'}{$name};
# Remove from ordered list too
my $columns = $self->nonpersistent_columns_ordered;
for(my $i = 0; $i < @$columns; $i++)
{
if($columns->[$i]->name eq $name)
{
splice(@$columns, $i, 1);
last;
}
}
return;
}
sub first_column { shift->columns_ordered->[0] }
sub sync_keys_to_columns
{
my($self) = shift;
$self->_clear_column_generated_values;
my %columns = map { $_->name => 1 } $self->columns_ordered;
foreach my $col_name ($self->primary_key_column_names)
{
unless($columns{$col_name})
{
Carp::croak "Primary key column '$col_name' is not in the column list for ",
$self->class;
#$self->primary_key(undef);
#last;
}
}
my @valid_uks;
UK: foreach my $uk ($self->unique_keys)
{
foreach my $col_name ($uk->column_names)
{
unless($columns{$col_name})
{
Carp::croak "Column '$col_name' found in unique key is not in the column list for ",
$self->class;
#next UK;
}
}
push(@valid_uks, $uk);
}
$self->unique_keys(@valid_uks);
return;
}
sub replace_column
{
my($self) = shift;
unless(@_ == 2)
{
Carp::croak "Missing column name and value arguments" if(@_ < 2);
Carp::croak "Too many arguments passed to replace_column()" if(@_ < 2);
}
return $self->column(@_);
}
sub column
{
my($self, $name) = (shift, shift);
if(@_)
{
$self->delete_column($name);
$self->add_column($name => @_);
}
return $self->{'columns'}{$name} if($self->{'columns'}{$name});
return undef;
}
sub nonpersistent_column
{
my($self, $name) = (shift, shift);
if(@_)
{
$self->delete_nonpersistent_column($name);
$self->add_nonpersistent_column($name => @_);
}
return $self->{'nonpersistent_columns'}{$name} if($self->{'nonpersistent_columns'}{$name});
return undef;
}
sub columns
{
my($self) = shift;
if(@_)
{
$self->delete_columns;
$self->add_columns(@_);
}
return $self->columns_ordered;
}
sub nonpersistent_columns
{
my($self) = shift;
if(@_)
{
$self->delete_nonpersistent_columns;
$self->add_nonpersistent_columns(@_);
}
return $self->nonpersistent_columns_ordered;
}
sub num_columns
{
my($self) = shift;
return $self->{'num_columns'} ||= scalar(@{$self->columns_ordered});
}
sub nonlazy_columns
{
my($self) = shift;
return wantarray ?
(grep { !$_->lazy } $self->columns_ordered) :
[ grep { !$_->lazy } $self->columns_ordered ];
}
sub lazy_columns
{
my($self) = shift;
return wantarray ?
(grep { $_->lazy } $self->columns_ordered) :
[ grep { $_->lazy } $self->columns_ordered ];
}
# XXX: Super-lame code sharing via dynamically-scoped flag var
our $Nonpersistent;
sub add_nonpersistent_columns
{
local $Nonpersistent = 1;
shift->_add_columns(@_);
}
sub add_nonpersistent_column { shift->add_nonpersistent_columns(@_) }
sub add_columns
{
local $Nonpersistent = 0;
shift->_add_columns(@_);
}
sub add_column { shift->add_columns(@_) }
sub _add_columns
{
my($self) = shift;
my $class = ref $self;
my(@columns, @nonpersistent_columns);
ARG: while(@_)
{
my $name = shift;
if(UNIVERSAL::isa($name, 'Rose::DB::Object::Metadata::Column'))
{
my $column = $name;
Carp::croak "Relationship $column lacks a name()"
unless($column->name =~ /\S/);
$column->parent($self);
$column->nonpersistent(1) if($Nonpersistent);
if($column->nonpersistent)
{
$self->{'nonpersistent_columns'}{$column->name} = $column;
push(@nonpersistent_columns, $column);
}
else
{
$self->{'columns'}{$column->name} = $column;
push(@columns, $column);
}
next;
}
unless(ref $_[0]) # bare column name, persistent only
{
my $column_class = $self->original_class->column_type_class('scalar')
or Carp::croak "No column class set for column type 'scalar'";
#$Debug && warn $self->class, " - adding scalar column $name\n";
$self->{'columns'}{$name} = $column_class->new(name => $name, parent => $self);
push(@columns, $self->{'columns'}{$name});
next;
}
if(UNIVERSAL::isa($_[0], 'Rose::DB::Object::Metadata::Column'))
{
my $column = $_[0];
$column->name($name);
$column->parent($self);
$column->nonpersistent(1) if($Nonpersistent);
if($column->nonpersistent)
{
$self->{'nonpersistent_columns'}{$column->name} = $column;
push(@nonpersistent_columns, $column);
}
else
{
$self->{'columns'}{$column->name} = $column;
push(@columns, $column);
}
}
elsif(ref $_[0] eq 'HASH')
{
my $info = shift;
my $alias = $info->{'alias'};
if($info->{'primary_key'})
{
#$Debug && warn $self->class, " - adding primary key column $name\n";
$self->add_primary_key_column($name);
}
my $methods = delete $info->{'methods'};
my $add_methods = delete $info->{'add_methods'};
if($methods && $add_methods)
{
Carp::croak "Cannot specify both 'methods' and 'add_methods' - ",
"pick one or the other";
}
my $type = $info->{'type'} ||= 'scalar';
my $column_class = $self->original_class->column_type_class($type)
or Carp::croak "No column class set for column type '$type'";
unless($self->column_class_is_loaded($column_class))
{
$self->load_column_class($column_class);
}
my %triggers;
foreach my $event ($column_class->trigger_events)
{
$triggers{$event} = delete $info->{$event} if(exists $info->{$event});
}
if(delete $info->{'temp'}) # coerce temp to nonpersistent
{
$info->{'nonpersistent'} = 1;
}
#$Debug && warn $self->class, " - adding $name $column_class\n";
# XXX: Order of args is important here! Parent must be set first
# because some params rely on it being present when they're set.
my $column =
$column_class->new(parent => $self, %$info, name => $name);
$column->nonpersistent(1) if($Nonpersistent);
if($column->nonpersistent)
{
$self->{'nonpersistent_columns'}{$column->name} = $column;
push(@nonpersistent_columns, $column);
}
else
{
$self->{'columns'}{$column->name} = $column;
push(@columns, $column);
}
# Set or add auto-created method names
if($methods || $add_methods)
{
my $auto_method_name =
$methods ? 'auto_method_types' : 'add_auto_method_types';
my $methods_arg = $methods || $add_methods;
if(ref $methods_arg eq 'HASH')
{
$methods = [ keys %$methods_arg ];
while(my($type, $name) = each(%$methods_arg))
{
next unless(defined $name);
$column->method_name($type => $name);
}
}
else
{
$methods = $methods_arg;
}
$column->$auto_method_name($methods);
}
if(defined $alias)
{
$column->alias($alias);
$self->alias_column($name, $alias);
}
if(%triggers)
{
while(my($event, $value) = each(%triggers))
{
Carp::croak "Missing code reference for $event trigger"
unless($value);
foreach my $code (ref $value eq 'ARRAY' ? @$value : $value)
{
$column->add_trigger(event => $event,
code => $code);
}
}
}
}
else
{
Carp::croak "Invalid column name or specification: $_[0]";
}
}
# Handle as-yet undocumented smart modification defaults.
# Smart modification is only relevant
foreach my $column (@columns)
{
if($column->can('smart_modification') && !defined $column->{'smart_modification'})
{
$column->smart_modification($self->default_smart_modification);
}
}
if(@columns)
{
push(@{$self->{'columns_ordered'}}, @columns);
$self->_clear_column_generated_values;
}
if(@nonpersistent_columns)
{
push(@{$self->{'nonpersistent_columns_ordered'}}, @nonpersistent_columns);
$self->_clear_nonpersistent_column_generated_values;
}
return wantarray ? (@columns, @nonpersistent_columns) : [ @columns, @nonpersistent_columns ];
}
sub relationship
{
my($self, $name) = (shift, shift);
if(@_)
{
$self->delete_relationship($name);
$self->add_relationship($name => $_[0]);
}
return $self->{'relationships'}{$name} if($self->{'relationships'}{$name});
return undef;
}
sub delete_relationship
{
my($self, $name) = @_;
delete $self->{'relationships'}{$name};
return;
}
sub relationships
{
my($self) = shift;
if(@_)
{
$self->delete_relationships;
$self->add_relationships(@_);
}
return wantarray ?
(sort { $a->name cmp $b->name } values %{$self->{'relationships'} ||= {}}) :
[ sort { $a->name cmp $b->name } values %{$self->{'relationships'} ||= {}} ];
}
sub delete_relationships
{
my($self) = shift;
# Delete everything except fk proxy relationships
foreach my $name (keys %{$self->{'relationships'} || {}})
{
delete $self->{'relationships'}{$name}
unless($self->{'relationships'}{$name}->foreign_key);
}
return;
}
sub add_relationships
{
my($self) = shift;
my $class = ref $self;
ARG: while(@_)
{
my $name = shift;
# Relationship object
if(UNIVERSAL::isa($name, 'Rose::DB::Object::Metadata::Relationship'))
{
my $relationship = $name;
Carp::croak "Relationship $relationship lacks a name()"
unless($relationship->name =~ /\S/);
if(defined $self->{'relationships'}{$relationship->name})
{
Carp::croak $self->class, " already has a relationship named '",
$relationship->name, "'";
}
$relationship->parent($self);
$self->{'relationships'}{$relationship->name} = $relationship;
next;
}
# Name and type only: recurse with hashref arg
if(!ref $_[0])
{
my $type = shift;
$self->add_relationships($name => { type => $type });
next ARG;
}
if(UNIVERSAL::isa($_[0], 'Rose::DB::Object::Metadata::Relationship'))
{
my $relationship = shift;
$relationship->name($name);
$relationship->parent($self);
$self->{'relationships'}{$name} = $relationship;
}
elsif(ref $_[0] eq 'HASH')
{
my $info = shift;
if(defined $self->{'relationships'}{$name})
{
Carp::croak $self->class, " already has a relationship named '$name'";
}
my $methods = delete $info->{'methods'};
my $add_methods = delete $info->{'add_methods'};
if($methods && $add_methods)
{
Carp::croak "Cannot specify both 'methods' and 'add_methods' - ",
"pick one or the other";
}
my $type = $info->{'type'} or
Carp::croak "Missing type parameter for relationship '$name'";
my $relationship = $self->{'relationships'}{$name} =
$self->_build_relationship(name => $name,
type => $type,
info => $info);
# Set or add auto-created method names
if($methods || $add_methods)
{
my $auto_method_name =
$methods ? 'auto_method_types' : 'add_auto_method_types';
my $methods_arg = $methods || $add_methods;
if(ref $methods_arg eq 'HASH')
{
$methods = [ keys %$methods_arg ];
while(my($type, $name) = each(%$methods_arg))
{
next unless(defined $name);
$relationship->method_name($type => $name);
}
}
else
{
$methods = $methods_arg;
}
$relationship->$auto_method_name($methods);
}
}
else
{
Carp::croak "Invalid relationship name or specification: $_[0]";
}
}
}
sub _build_relationship
{
my($self, %args) = @_;
my $class = ref $self;
my $name = $args{'name'} or Carp::croak "Missing name parameter";
my $info = $args{'info'} or Carp::croak "Missing info parameter";
my $type = $args{'type'} or
Carp::croak "Missing type parameter for relationship '$name'";
my $relationship_class = $class->relationship_type_class($type)
or Carp::croak "No relationship class set for relationship type '$type'";
unless($self->relationship_class_is_loaded($relationship_class))
{
$self->load_relationship_class($relationship_class);
}
$Debug && warn $self->class, " - adding $name $relationship_class\n";
my $relationship =
$self->convention_manager->auto_relationship($name, $relationship_class, $info) ||
$relationship_class->new(%$info, name => $name);
unless($relationship)
{
Carp::croak "$class - Incomplete relationship specification could not be ",
"completed by convention manager: $name";
}
$relationship->parent($self);
return $relationship;
}
sub add_relationship { shift->add_relationships(@_) }
my %Class_Loaded;
sub load_column_class
{
my($self, $column_class) = @_;
unless(UNIVERSAL::isa($column_class, 'Rose::DB::Object::Metadata::Column'))
{
my $error;
TRY:
{
local $@;
eval "require $column_class";
$error = $@;
}
Carp::croak "Could not load column class '$column_class' - $error"
if($error);
}
$Class_Loaded{$column_class}++;
}
sub column_class_is_loaded { $Class_Loaded{$_[1]} }
sub column_type_class
{
my($class, $type) = (shift, shift);
return $class->_column_type_class(lc $type, @_)
}
sub delete_column_type_class
{
my($class, $type) = (shift, shift);
return $class->_delete_column_type_class(lc $type, @_)
}
sub load_relationship_class
{
my($self, $relationship_class) = @_;
my $error;
TRY:
{
local $@;
eval "require $relationship_class";
$error = $@;
}
Carp::croak "Could not load relationship class '$relationship_class' - $error"
if($error);
$Class_Loaded{$relationship_class}++;
}
sub relationship_class_is_loaded { $Class_Loaded{$_[1]} }
sub add_foreign_keys
{
my($self) = shift;
ARG: while(@_)
{
my $name = shift;
# Foreign key object
if(UNIVERSAL::isa($name, 'Rose::DB::Object::Metadata::ForeignKey'))
{
my $fk = $name;
Carp::croak "Foreign key $fk lacks a name()"
unless($fk->name =~ /\S/);
if(defined $self->{'foreign_keys'}{$fk->name})
{
Carp::croak $self->class, " already has a foreign key named '",
$fk->name, "'";
}
$fk->parent($self);
$self->{'foreign_keys'}{$fk->name} = $fk;
unless(defined $self->relationship($fk->name))
{
$self->add_relationship(
$self->relationship_type_class($fk->relationship_type)->new(
parent => $self,
name => $fk->name,
class => $fk->class,
foreign_key => $fk));
}
next ARG;
}
# Name only: try to get all the other info by convention
if(!ref $_[0])
{
if(my $fk = $self->convention_manager->auto_foreign_key($name))
{
$self->add_foreign_keys($fk);
next ARG;
}
else
{
Carp::croak $self->class,
" - Incomplete foreign key specification could not be ",
"completed by convention manager: $name";
}
}
# Name and hashref spec
if(ref $_[0] eq 'HASH')
{
my $info = shift;
if(defined $self->{'foreign_keys'}{$name})
{
Carp::croak $self->class, " already has a foreign key named '$name'";
}
my $methods = delete $info->{'methods'};
my $add_methods = delete $info->{'add_methods'};
if($methods && $add_methods)
{
Carp::croak "Cannot specify both 'methods' and 'add_methods' - ",
"pick one or the other";
}
$Debug && warn $self->class, " - adding $name foreign key\n";
my $fk = $self->{'foreign_keys'}{$name} =
$self->convention_manager->auto_foreign_key($name, $info) ||
Rose::DB::Object::Metadata::ForeignKey->new(%$info, name => $name);
$fk->parent($self);
# Set or add auto-created method names
if($methods || $add_methods)
{
my $auto_method_name =
$methods ? 'auto_method_types' : 'add_auto_method_types';
my $methods_arg = $methods || $add_methods;
if(ref $methods_arg eq 'HASH')
{
$methods = [ keys %$methods_arg ];
while(my($type, $name) = each(%$methods_arg))
{
next unless(defined $name);
$fk->method_name($type => $name);
}
}
else
{
$methods = $methods_arg;
}
$fk->$auto_method_name($methods);
}
unless(defined $self->relationship($name))
{
$self->add_relationship(
$self->relationship_type_class($fk->relationship_type)->new(
name => $name,
class => $fk->class,
foreign_key => $fk));
}
}
else
{
Carp::croak "Invalid foreign key specification: $_[0]";
}
}
}
sub add_foreign_key { shift->add_foreign_keys(@_) }
sub foreign_key
{
my($self, $name) = (shift, shift);
if(@_)
{
$self->delete_foreign_key($name);
$self->add_foreign_key($name => @_);
}
return $self->{'foreign_keys'}{$name} if($self->{'foreign_keys'}{$name});
return undef;
}
sub delete_foreign_key
{
my($self, $name) = @_;
delete $self->{'foreign_keys'}{$name};
return;
}
sub delete_foreign_keys
{
my($self) = shift;
# Delete fk proxy relationship
foreach my $fk (values %{$self->{'foreign_keys'}})
{
foreach my $rel ($self->relationships)
{
no warnings 'uninitialized';
if($rel->foreign_key eq $fk)
{
$self->delete_relationship($rel->name);
}
}
}
# Delete fks
$self->{'foreign_keys'} = {};
return;
}
sub foreign_keys
{
my($self) = shift;
if(@_)
{
$self->delete_foreign_keys;
$self->add_foreign_keys(@_);
}
return wantarray ?
(sort { $a->name cmp $b->name } values %{$self->{'foreign_keys'} ||= {}}) :
[ sort { $a->name cmp $b->name } values %{$self->{'foreign_keys'} ||= {}} ];
}
sub initialize
{
my($self) = shift;
my(%args) = @_;
$Debug && warn $self->class, " - initialize\n";
if(my $code = $self->pre_init_hook)
{
foreach my $sub (ref $code eq 'ARRAY' ? @$code : $code)
{
$sub->($self, @_);
}
}
my $class = $self->class
or Carp::croak "Missing class for metadata object $self";
$self->sync_keys_to_columns;
my $table = $self->table;
Carp::croak "$class - Missing table name"
unless(defined $table && $table =~ /\S/);
my @pk = $self->primary_key_column_names;
Carp::croak "$class - Missing primary key for table '$table'" unless(@pk);
$self->init_primary_key_column_info;
my @column_names = $self->column_names;
Carp::croak "$class - No columns defined for for table '$table'"
unless(@column_names);
foreach my $name ($self->primary_key_column_names)
{
my $column = $self->column($name) or
Carp::croak "Could not find column for primary key column name '$name'";
if($column->is_lazy)
{
Carp::croak "Column '$name' cannot be lazy: cannot load primary key ",
"columns on demand";
}
}
$self->make_methods(@_);
$self->register_class;
unless($args{'passive'})
{
# Retry deferred stuff
$self->retry_deferred_tasks;
$self->retry_deferred_foreign_keys;
$self->retry_deferred_relationships;
}
$self->refresh_lazy_column_tracking;
unless($args{'stay_connected'})
{
$self->db(undef); # make sure to ditch any db we may have retained
}
$self->is_initialized(1);
$Debug && warn $self->class, " - initialized\n";
if(my $code = $self->post_init_hook)
{
foreach my $sub (ref $code eq 'ARRAY' ? @$code : $code)
{
$sub->($self, @_);
}
}
# Regardless of cache priming, call this to ensure it's initialized,
# since it is very likely to be used.
$self->key_column_accessor_method_names_hash;
$self->prime_caches if($self->auto_prime_caches);
return;
}
use constant NULL_CATALOG => "\0";
use constant NULL_SCHEMA => "\0";
sub register_class
{
my($self) = shift;
my $class = $self->class
or Carp::croak "Missing class for metadata object $self";
my $db = $self->db;
my $catalog = $self->select_catalog($db);
my $schema = $db ? ($db->registration_schema || $self->select_schema($db)) :
$self->select_schema($db);;
$catalog = NULL_CATALOG unless(defined $catalog);
$schema = NULL_SCHEMA unless(defined $schema);
my $default_schema = $db ? $db->default_implicit_schema : undef;
my $table = $self->table
or Carp::croak "Missing table for metadata object $self";
$table = lc $table if($db->likes_lowercase_table_names);
my $reg = $self->registry_key->class_registry;
# Combine keys using $;, which is "\034" (0x1C) by default. But just to
# make sure, I'll localize it. What I'm looking for is a value that
# won't show up in a catalog, schema, or table name, so I'm guarding
# against someone changing it to "-" (or whatever) elsewhere in the code.
local $; = "\034";
# Register with all available information.
# Ug, have to store lowercase versions too because MySQL sometimes returns
# lowercase names for tables that are actually mixed case. Grrr...
$reg->{'catalog-schema-table',$catalog,$schema,$table} =
$reg->{'table',$table} =
$reg->{'lc-catalog-schema-table',$catalog,$schema,lc $table} =
$reg->{'lc-table',lc $table} = $class;
$reg->{'catalog-schema-table',$catalog,$default_schema,$table} = $class
if(defined $default_schema);
push(@{$reg->{'classes'}}, $class);
return;
}
sub registry_key { __PACKAGE__ }
sub registered_classes
{
my($self) = shift;
my $reg = $self->registry_key->class_registry;
return wantarray ? @{$reg->{'classes'} ||= []} : $reg->{'classes'};
}
sub unregister_all_classes
{
my($self) = shift;
$self->registry_key->class_registry({});
return;
}
sub class_for
{
my($self_or_class, %args) = @_;
my $self = ref($self_or_class) ? $self_or_class : undef;
my $class = ref($self) || $self_or_class;
my $db = $self ? $self->db : undef;
my $catalog = $args{'catalog'};
my $schema = $args{'schema'};
$catalog = NULL_CATALOG unless(defined $catalog);
$schema = NULL_SCHEMA unless(defined $schema);
my $default_schema = $db ? $db->default_implicit_schema : undef;
$default_schema = NULL_SCHEMA unless(defined $default_schema);
my $table = $args{'table'}
or Carp::croak "Missing required table parameter";
$table = lc $table if($db && $db->likes_lowercase_table_names);
my $reg = $class->registry_key->class_registry;
# Combine keys using $;, which is "\034" (0x1C) by default. But just to
# make sure, we'll localize it. What we're looking for is a value that
# wont' show up in a catalog, schema, or table name, so I'm guarding
# against someone changing it to "-" elsewhere in the code or whatever.
local $; = "\034";
my $f_class =
$reg->{'catalog-schema-table',$catalog,$schema,$table} ||
$reg->{'catalog-schema-table',$catalog,$default_schema,$table} ||
($schema eq NULL_SCHEMA && $default_schema eq NULL_SCHEMA ? $reg->{'lc-table',$table} : undef);
# Ug, have to check lowercase versions too because MySQL sometimes returns
# lowercase names for tables that are actually mixed case. Grrr...
unless($f_class)
{
$table = lc $table;
return
$reg->{'lc-catalog-schema-table',$catalog,$schema,$table} ||
$reg->{'lc-catalog-schema-table',$catalog,$default_schema,$table} ||
($schema eq NULL_SCHEMA && $default_schema eq NULL_SCHEMA ? $reg->{'lc-table',$table} : undef);
}
return $f_class;
}
#sub made_method_for_column
#{
# (@_ > 2) ? ($_[0]->{'made_methods'}{$_[1]} = $_[2]) :
# $_[0]->{'made_methods'}{$_[1]};
#}
sub make_column_methods
{
my($self) = shift;
my(%args) = @_;
my $class = $self->class;
$args{'target_class'} = $class;
my $aliases = $self->column_aliases;
while(my($column_name, $alias) = each(%$aliases))
{
$self->column($column_name)->alias($alias);
}
foreach my $column ($self->columns_ordered)
{
unless($column->validate_specification)
{
Carp::croak "Column specification for column '", $column->name,
"' in class ", $self->class, " is invalid: ",
$column->error;
}
my $name = $column->name;
my $method;
foreach my $type ($column->auto_method_types)
{
$method = $self->method_name_from_column_name($name, $type)
or Carp::croak "No method name defined for column '$name' ",
"method type '$type'";
if(my $reason = $self->method_name_is_reserved($method, $class))
{
Carp::croak "Cannot create method '$method' - $reason ",
"Use alias_column() to map it to another name."
}
$column->method_name($type => $method);
}
#$Debug && warn $self->class, " - make methods for column $name\n";
$column->make_methods(%args);
# XXX: Re-enabling the ability to alias primary keys
#if($column->is_primary_key_member && $column->alias && $column->alias ne $column->name)
#{
# Carp::croak "Primary key columns cannot be aliased (the culprit: '$name')";
#}
#
#if($method ne $name)
#{
# # Primary key columns can be aliased, but we make a column-named
# # method anyway.
# foreach my $column ($self->primary_key_column_names)
# {
# if($name eq $column)
# {
# if(my $reason = $self->method_name_is_reserved($name, $class))
# {
# Carp::croak
# "Cannot create method for primary key column '$name' ",
# "- $reason Although primary keys may be aliased, doing ",
# "so will not avoid conflicts with reserved method names ",
# "because a method named after the primary key column ",
# "itself must also be created.";
# }
#
# no strict 'refs';
# *{"${class}::$name"} = \&{"${class}::$method"};
# }
# }
#}
}
$self->_clear_column_generated_values;
# Initialize method name hashes
$self->column_accessor_method_names;
$self->column_mutator_method_names;
$self->column_rw_method_names;
# This rule is relaxed for now...
# Must have an rw accessor for every column
#my $columns = $self->columns_ordered;
#
#unless(keys %methods == @$columns)
#{
# Carp::croak "Rose::DB::Object-derived objects are required to have ",
# "a 'get_set' method for every column. This class (",
# $self->class, ") has ", scalar @$columns, "column",
# (@$columns == 1 ? '' : 's'), " and ", scalar keys %methods,
# " method", (scalar keys %methods == 1 ? '' : 's');
#}
return;
}
sub make_nonpersistent_column_methods
{
my($self) = shift;
my(%args) = @_;
my $class = $self->class;
$args{'target_class'} = $class;
foreach my $column ($self->nonpersistent_columns_ordered)
{
unless($column->validate_specification)
{
Carp::croak "Column specification for column '", $column->name,
"' in class ", $self->class, " is invalid: ",
$column->error;
}
my $name = $column->name;
my $method;
foreach my $type ($column->auto_method_types)
{
$method = $self->method_name_from_column_name($name, $type)
or Carp::croak "No method name defined for column '$name' ",
"method type '$type'";
if(my $reason = $self->method_name_is_reserved($method, $class))
{
Carp::croak "Cannot create method '$method' - $reason ",
"Use alias_column() to map it to another name."
}
$column->method_name($type => $method);
}
#$Debug && warn $self->class, " - make methods for column $name\n";
$column->make_methods(%args);
}
$self->_clear_nonpersistent_column_generated_values;
# Initialize method name hashes
$self->nonpersistent_column_accessor_method_names;
return;
}
sub make_foreign_key_methods
{
my($self) = shift;
my(%args) = @_;
#$self->retry_deferred_foreign_keys;
my $class = $self->class;
my $meta_class = ref $self;
$args{'target_class'} = $class;
foreach my $foreign_key ($self->foreign_keys)
{
#next unless($foreign_key->is_ready_to_make_methods);
foreach my $type ($foreign_key->auto_method_types)
{
my $method =
$foreign_key->method_name($type) ||
$foreign_key->build_method_name_for_type($type) ||
Carp::croak "No method name defined for foreign key '",
$foreign_key->name, "' method type '$type'";
if(my $reason = $self->method_name_is_reserved($method, $class))
{
Carp::croak "Cannot create method '$method' - $reason ",
"Choose a different foreign key name."
}
$foreign_key->method_name($type => $method);
}
if($self->auto_load_related_classes && (my $fclass = $foreign_key->class))
{
unless($fclass->isa('Rose::DB::Object'))
{
my $error;
TRY:
{
local $@;
eval "require $fclass";
$error = $@;
}
$Debug && print STDERR "FK REQUIRES $fclass - $error\n";
if($error)
{
# XXX: Need to distinguish recoverable errors from unrecoverable errors
if($error !~ /\.pm in \@INC/ && !UNIVERSAL::isa($error, 'Rose::DB::Object::Exception::ClassNotReady'))
{
Carp::confess "Could not load $fclass - $error";
}
}
}
}
# We may need to defer the creation of some foreign key methods until
# all the required pieces are loaded.
if($foreign_key->is_ready_to_make_methods)
{
if($Debug && !$args{'preserve_existing'})
{
warn $self->class, " - make methods for foreign key ",
$foreign_key->name, "\n";
}
$foreign_key->make_methods(%args);
}
else
{
# Confirm that no info is missing. This prevents an improperly
# configured foreign_key from being deferred "forever"
$foreign_key->sanity_check;
$Debug && warn $self->class, " - defer foreign key ", $foreign_key->name, "\n";
$foreign_key->deferred_make_method_args(\%args);
$meta_class->add_deferred_foreign_key($foreign_key);
}
# Keep foreign keys and their corresponding relationships in sync.
my $fk_id = $foreign_key->id;
my $fk_rel_type = $foreign_key->relationship_type;
foreach my $relationship ($self->relationships)
{
next unless($relationship->type eq $fk_rel_type);
if($fk_id eq $relationship->id)
{
$relationship->foreign_key($foreign_key);
}
}
}
$self->retry_deferred_foreign_keys;
return;
}
our @Deferred_Tasks;
sub deferred_tasks
{
return wantarray ? @Deferred_Tasks : \@Deferred_Tasks;
}
sub add_deferred_tasks
{
my($class) = shift;
ARG: foreach my $arg (@_)
{
foreach my $task (@Deferred_Tasks)
{
next ARG if($arg->{'class'} eq $task->{'class'} &&
$arg->{'method'} eq $task->{'method'});
}
push(@Deferred_Tasks, $arg);
}
}
sub add_deferred_task { shift->add_deferred_tasks(@_) }
sub has_deferred_tasks
{
my($self) = shift;
my $class = $self->class;
my $meta_class = ref $self;
# Search among the deferred tasks too (icky)
foreach my $task ($meta_class->deferred_tasks)
{
if($task->{'class'} eq $class)
{
return 1;
}
}
return 0;
}
sub retry_deferred_tasks
{
my($self) = shift;
my @tasks;
foreach my $task (@Deferred_Tasks)
{
my $code = $task->{'code'};
my $check = $task->{'check'};
$code->();
unless($check->())
{
push(@tasks, $task);
}
}
if(join(',', sort @Deferred_Tasks) ne join(',', sort @tasks))
{
@Deferred_Tasks = @tasks;
}
}
our @Deferred_Foreign_Keys;
sub deferred_foreign_keys
{
return wantarray ? @Deferred_Foreign_Keys : \@Deferred_Foreign_Keys;
}
sub has_deferred_foreign_keys
{
my($self) = shift;
my $class = $self->class;
my $meta_class = ref $self;
foreach my $fk ($meta_class->deferred_foreign_keys)
{
return 1 if($fk->class eq $class);
}
# Search among the deferred tasks too (icky)
foreach my $task ($meta_class->deferred_tasks)
{
if($task->{'class'} eq $class && $task->{'method'} eq 'auto_init_foreign_keys')
{
return 1;
}
}
return 0;
}
sub has_outstanding_metadata_tasks
{
my($self) = shift;
return $self->{'has_outstanding_metadata_tasks'} = shift if(@_);
if(defined $self->{'has_outstanding_metadata_tasks'})
{
return $self->{'has_outstanding_metadata_tasks'};
}
if($self->has_deferred_foreign_keys ||
$self->has_deferred_relationships ||
$self->has_deferred_tasks)
{
return $self->{'has_outstanding_metadata_tasks'} = 1;
}
return $self->{'has_outstanding_metadata_tasks'} = 0;
}
sub add_deferred_foreign_keys
{
my($class) = shift;
my $check = 0;
ARG: foreach my $arg (@_)
{
foreach my $fk (@Deferred_Foreign_Keys)
{
next ARG if($fk->id eq $arg->id);
}
$arg->parent->has_outstanding_metadata_tasks(1);
push(@Deferred_Foreign_Keys, $arg);
}
}
sub add_deferred_foreign_key { shift->add_deferred_foreign_keys(@_) }
sub retry_deferred_foreign_keys
{
my($self) = shift;
my $meta_class = ref $self;
my @foreign_keys;
# Check to see if any deferred foreign keys are ready now
foreach my $foreign_key ($meta_class->deferred_foreign_keys)
{
# XXX: this is not necessary, so it's commented out for now.
# Try to rebuild the relationship using the convention manager, since
# new info may be available now. Otherwise, leave it as-is.
# $foreign_key =
# $self->convention_manager->auto_foreign_key(
# $def_fk->name, scalar $def_fk->spec_hash) ||
# $def_fk;
if($foreign_key->is_ready_to_make_methods)
{
$Debug && warn $foreign_key->parent->class,
" - (Retry) make methods for foreign key ",
$foreign_key->name, "\n";
my $args = $foreign_key->deferred_make_method_args || {};
$foreign_key->make_methods(%$args); #, preserve_existing => 1);
}
else
{
push(@foreign_keys, $foreign_key);
}
}
if(join(',', sort @Deferred_Foreign_Keys) ne join(',', sort @foreign_keys))
{
@Deferred_Foreign_Keys = @foreign_keys;
}
# Retry relationship auto-init for all other classes
foreach my $class ($self->registered_classes)
{
my $meta = $class->meta;
next unless($meta->allow_auto_initialization && $meta->has_outstanding_metadata_tasks);
$meta->auto_init_relationships(%{ $meta->auto_init_args || {} },
restore_types => 1);
}
}
sub make_relationship_methods
{
my($self) = shift;
my(%args) = @_;
#$self->retry_deferred_relationships;
my $meta_class = ref $self;
my $class = $self->class;
$args{'target_class'} = $class;
my $preserve_existing_arg = $args{'preserve_existing'};
REL: foreach my $relationship ($self->relationships)
{
next if($args{'name'} && $relationship->name ne $args{'name'});
#next unless($relationship->is_ready_to_make_methods);
foreach my $type ($relationship->auto_method_types)
{
my $method =
$relationship->method_name($type) ||
$relationship->build_method_name_for_type($type) ||
Carp::croak "No method name defined for relationship '",
$relationship->name, "' method type '$type'";
if(my $reason = $self->method_name_is_reserved($method, $class))
{
Carp::croak "Cannot create method '$method' - $reason ",
"Choose a different relationship name."
}
$relationship->method_name($type => $method);
# Initialize/reset preserve_existing flag
if($self->is_auto_initializating)
{
$args{'preserve_existing'} = $preserve_existing_arg || $self->allow_auto_initialization;
}
delete $args{'replace_existing'} if($args{'preserve_existing'});
# If a corresponding foreign key exists, the preserve any existing
# methods with the same names. This is a crude way to ensure that we
# can have a foreign key and a corresponding relationship without any
# method name clashes.
if($relationship->can('id'))
{
my $rel_id = $relationship->id;
FK: foreach my $fk ($self->foreign_keys)
{
if($rel_id eq $fk->id)
{
$args{'preserve_existing'} = 1;
delete $args{'replace_existing'};
last FK;
}
}
}
}
if($self->auto_load_related_classes)
{
if($relationship->can('class'))
{
my $fclass = $relationship->class;
unless($fclass->isa('Rose::DB::Object') && $fclass->meta->is_initialized)
{
my $error;
TRY:
{
local $@;
eval "require $fclass";
$error = $@;
}
$Debug && print STDERR "REL ", $relationship->name,
" REQUIRES $fclass - $error\n";
if($error)
{
# XXX: Need to distinguish recoverable errors from unrecoverable errors
if($error !~ /\.pm in \@INC/ && !UNIVERSAL::isa($error, 'Rose::DB::Object::Exception::ClassNotReady'))
#if($error =~ /syntax error at |requires explicit package name|not allowed while "strict|already has a relationship named|Can't modify constant item/)
{
Carp::confess "Could not load $fclass - $error";
}
}
}
}
if($relationship->can('map_class'))
{
my $map_class = $relationship->map_class;
unless($map_class->isa('Rose::DB::Object') && $map_class->meta->is_initialized)
{
my $error;
TRY:
{
local $@;
eval "require $map_class";
$error = $@;
}
$Debug && print STDERR "REL ", $relationship->name,
" REQUIRES $map_class - $error\n";
if($error)
{
# XXX: Need to distinguish recoverable errors from unrecoverable errors
if($error !~ /\.pm in \@INC/ && !UNIVERSAL::isa($error, 'Rose::DB::Object::Exception::ClassNotReady'))
#if($error =~ /syntax error at |requires explicit package name|not allowed while "strict|already has a relationship named|Can't modify constant item/)
{
Carp::confess "Could not load $map_class - $error";
}
}
}
}
}
# We may need to defer the creation of some relationship methods until
# all the required pieces are loaded.
if($relationship->is_ready_to_make_methods)
{
if($Debug && !$args{'preserve_existing'})
{
warn $self->class, " - make methods for relationship ",
$relationship->name, "\n";
}
$relationship->make_methods(%args);
}
elsif(!$relationship->can('foreign_key') || !$relationship->foreign_key)
{
# Confirm that no info is missing. This prevents an improperly
# configured relationship from being deferred "forever"
$relationship->sanity_check;
$Debug && warn $self->class, " - defer relationship ", $relationship->name, "\n";
$relationship->deferred_make_method_args(\%args);
$meta_class->add_deferred_relationship($relationship);
}
}
#$self->retry_deferred_relationships;
return;
}
our @Deferred_Relationships;
sub deferred_relationships
{
return wantarray ? @Deferred_Relationships : \@Deferred_Relationships;
}
sub has_deferred_relationships
{
my($self) = shift;
my $class = $self->class;
my $meta_class = ref $self;
foreach my $rel ($meta_class->deferred_relationships)
{
if(($rel->can('class') && $rel->class eq $class) ||
($rel->can('map_class') && $rel->map_class eq $class))
{
return 1;
}
}
# Search among the deferred tasks too (icky)
foreach my $task ($meta_class->deferred_tasks)
{
if($task->{'class'} eq $class && $task->{'method'} eq 'auto_init_relationships')
{
return 1;
}
}
return 0;
}
sub add_deferred_relationships
{
my($class) = shift;
ARG: foreach my $arg (@_)
{
foreach my $rel (@Deferred_Relationships)
{
next ARG if($rel->id eq $arg->id);
}
push(@Deferred_Relationships, $arg);
}
}
sub add_deferred_relationship { shift->add_deferred_relationships(@_) }
sub retry_deferred_relationships
{
my($self) = shift;
my $meta_class = ref $self;
my @relationships;
# Check to see if any deferred relationships are ready now
foreach my $relationship ($self->deferred_relationships)
{
# Try to rebuild the relationship using the convention manager, since
# new info may be available now. Otherwise, leave it as-is.
my $rebuild_rel =
$self->convention_manager->auto_relationship(
$relationship->name, ref $relationship,
scalar $relationship->spec_hash);
if($rebuild_rel)
{
# XXX: This is pretty evil. I need some sort of copy operator, but
# XXX: a straight hash copy will do for now...
%$relationship = %$rebuild_rel;
}
if($relationship->is_ready_to_make_methods)
{
$Debug && warn $relationship->parent->class,
" - (Retry) make methods for relationship ",
$relationship->name, "\n";
my $args = $relationship->deferred_make_method_args || {};
$args->{'preserve_existing'} = 1;
delete $args->{'replace_existing'};
$relationship->make_methods(%$args);
# Reassign to list in case we rebuild above
$relationship->parent->relationship($relationship->name => $relationship);
}
else
{
push(@relationships, $relationship);
}
}
if(join(',', sort @Deferred_Relationships) ne join(',', sort @relationships))
{
@Deferred_Relationships = @relationships;
}
# Retry relationship auto-init for all other classes
#foreach my $class ($self->registered_classes)
#{
# next unless($class->meta->allow_auto_initialization && $meta->has_outstanding_metadata_tasks);
# $self->auto_init_relationships(restore_types => 1);
#}
}
sub make_methods
{
my($self) = shift;
$self->make_column_methods(@_);
$self->make_nonpersistent_column_methods(@_);
$self->make_foreign_key_methods(@_);
$self->make_relationship_methods(@_);
}
sub generate_primary_key_values
{
my($self, $db) = @_;
if(my $code = $self->primary_key_generator)
{
return $code->($self, $db);
}
my @ids;
my $seqs = $self->fq_primary_key_sequence_names(db => $db);
if($seqs && @$seqs)
{
my $i = 0;
foreach my $seq (@$seqs)
{
$i++;
unless(defined $seq)
{
push(@ids, undef);
next;
}
my $id = $db->next_value_in_sequence($seq);
unless($id)
{
$self->error("Could not generate primary key for ", $self->class,
" column '", ($self->primary_key_column_names)[$i],
"' by selecting the next value in the sequence ",
"'$seq' - $@");
return undef;
}
push(@ids, $id);
}
return @ids;
}
else
{
return $db->generate_primary_key_values(scalar @{$self->primary_key_column_names});
}
}
sub generate_primary_key_value
{
my @ids = shift->generate_primary_key_values(@_);
return $ids[0];
}
sub generate_primary_key_placeholders
{
my($self, $db) = @_;
return $db->generate_primary_key_placeholders(scalar @{$self->primary_key_column_names});
}
sub primary_key_column_accessor_names
{
my($self) = shift;
if($self->{'primary_key_column_accessor_names'})
{
return @{$self->{'primary_key_column_accessor_names'}};
}
my @column_names = $self->primary_key_column_names;
my @columns = grep { defined } map { $self->column($_) } @column_names;
return unless(@column_names == @columns); # not ready yet
my @methods = grep { defined } map { $self->column_accessor_method_name($_) }
@column_names;
return unless(@methods);
$self->{'primary_key_column_accessor_names'} = \@methods;
return @methods;
}
sub primary_key_column_mutator_names
{
my($self) = shift;
if($self->{'primary_key_column_mutator_names'})
{
return @{$self->{'primary_key_column_mutator_names'}};
}
my @column_names = $self->primary_key_column_names;
my @columns = grep { defined } map { $self->column($_) } @column_names;
return unless(@column_names == @columns); # not ready yet
my @methods = grep { defined } map { $self->column_mutator_method_name($_) }
@column_names;
return unless(@methods);
$self->{'primary_key_column_mutator_names'} = \@methods;
return @methods;
}
sub fq_primary_key_sequence_names
{
my($self, %args) = @_;
my $db_id = $args{'db'}{'id'} || ($self->{'db_id'} ||= $self->init_db_id);
if(defined $self->{'fq_primary_key_sequence_names'}{$db_id})
{
my $seqs = $self->{'fq_primary_key_sequence_names'}{$db_id} or return;
return wantarray ? @$seqs : $seqs;
}
my $db = $args{'db'} or
die "Cannot generate fully-qualified primary key sequence name without db argument";
my @seqs = $self->primary_key_sequence_names($db);
if(@seqs)
{
$self->primary_key->sequence_names(@seqs);
# Add schema and catalog information only if it isn't present
# XXX: crappy check - just looking for a '.'
foreach my $seq (@seqs)
{
if(defined $seq && index($seq, '.') < 0)
{
$seq = $db->quote_identifier_for_sequence($self->select_catalog($db),
$self->select_schema($db), $seq);
}
}
$self->{'fq_primary_key_sequence_names'}{$db->{'id'}} = \@seqs;
return wantarray ? @seqs : \@seqs;
}
return;
}
sub refresh_primary_key_sequence_names
{
my($self, $db) = @_;
my $db_id = UNIVERSAL::isa($db, 'Rose::DB') ? $db->id : $db;
$self->{'fq_primary_key_sequence_names'}{$db_id} = undef;
$self->{'primary_key_sequence_names'}{$db_id} = undef;
return;
}
sub primary_key_sequence_names
{
my($self) = shift;
my($db, $db_id);
$db = shift if(UNIVERSAL::isa($_[0], 'Rose::DB'));
$db_id = $db ? $db->{'id'} : $self->init_db_id;
# Set pk sequence names
if(@_)
{
# Clear fully-qualified pk values
$self->{'fq_primary_key_sequence_names'}{$db_id} = undef;
my $ret = $self->{'primary_key_sequence_names'}{$db_id} =
(@_ == 1 && ref $_[0]) ? $_[0] : [ @_ ];
# Push down into pk metadata object too
$self->primary_key->sequence_names(($db ? $db : ()), @$ret);
return wantarray ? @$ret : $ret;
}
if($self->{'primary_key_sequence_names'}{$db_id})
{
my $ret = $self->{'primary_key_sequence_names'}{$db_id};
return wantarray ? @$ret : $ret;
}
# Init pk sequence names
# Start by considering the list of sequence names stored in the
# primary key metadata object
my @pks = $self->primary_key_column_names;
my $seqs = $self->primary_key->sequence_names($db);
my @seqs;
if($seqs)
{
# If each pk column has a defined sequence name, accept them as-is
if(@pks == grep { defined } @$seqs)
{
$self->{'primary_key_sequence_names'}{$db_id} = $seqs;
return wantarray ? @$seqs : $seqs;
}
else # otherwise, use them as a starting point
{
@seqs = @$seqs;
}
}
unless($db)
{
die "Cannot generate primary key sequence name without db argument";
}
my $cm = $self->convention_manager;
my $table = $self->table or
Carp::croak "Cannot generate primary key sequence name without table name";
my $i = 0;
foreach my $column ($self->primary_key_columns)
{
my $seq;
# Go the extra mile and look up the sequence name (if any) for scalar
# pk columns. These pk columns were probably set using the columns()
# shortcut $meta->columns(qw(foo bar baz)) rather than the "long way"
# with type information.
if($column->type eq 'scalar')
{
$seq = $self->_sequence_name($db,
$self->select_catalog($db),
$self->select_schema($db),
$table,
$column);
}
# Set auto-created serial column sequence names
elsif($column->type =~ /^(?:big)?serial$/ && $db->use_auto_sequence_name)
{
$seq = $cm->auto_column_sequence_name($table, $column, $db);
}
unless(exists $seqs[$i] && defined $seqs[$i])
{
$seqs[$i] = $seq if(defined $seq);
}
$i++;
}
# Only save if it looks like the class setup is finished
if($self->is_initialized)
{
$self->{'primary_key_sequence_names'}{$db->{'id'}} = \@seqs;
}
return wantarray ? @seqs : \@seqs;
}
sub _sequence_name
{
my($self, $db, $catalog, $schema, $table, $column) = @_;
# XXX: This is only beneficial in PostgreSQL right now
return unless($db->driver eq 'pg');
$table = lc $table if($db->likes_lowercase_table_names);
my($col_info, $error);
TRY:
{
local $@;
eval
{
my $dbh = $db->dbh;
local $dbh->{'RaiseError'} = 0;
local $dbh->{'PrintError'} = 0;
my $sth = $dbh->column_info($catalog, $schema, $table, $column) or return;
$sth->execute;
$col_info = $sth->fetchrow_hashref;
$sth->finish;
};
$error = $@;
}
return if($error || !$col_info);
$db->refine_dbi_column_info($col_info, $self);
my $seq = $col_info->{'rdbo_default_value_sequence_name'};
my $implicit_schema = $db->default_implicit_schema;
# Strip off default implicit schema unless a schema is explicitly specified
if(defined $seq && defined $implicit_schema && !defined $schema)
{
$seq =~ s/^$implicit_schema\.//;
}
return $seq;
}
sub column_names
{
my($self) = shift;
$self->{'column_names'} ||= [ map { $_->name } $self->columns_ordered ];
return wantarray ? @{$self->{'column_names'}} : $self->{'column_names'};
}
sub nonpersistent_column_names
{
my($self) = shift;
$self->{'nonpersistent_column_names'} ||= [ map { $_->name } $self->nonpersistent_columns_ordered ];
return wantarray ? @{$self->{'nonpersistent_column_names'}} : $self->{'nonpersistent_column_names'};
}
sub nonlazy_column_names
{
my($self) = shift;
$self->{'nonlazy_column_names'} ||= [ map { $_->name } $self->nonlazy_columns ];
return wantarray ? @{$self->{'nonlazy_column_names'}} : $self->{'nonlazy_column_names'};
}
sub lazy_column_names
{
my($self) = shift;
$self->{'lazy_column_names'} ||= [ map { $_->name } $self->lazy_columns ];
return wantarray ? @{$self->{'lazy_column_names'}} : $self->{'lazy_column_names'};
}
sub nonlazy_column_names_string_sql
{
my($self, $db) = @_;
return $self->{'nonlazy_column_names_string_sql'}{$db->{'id'}} ||=
join(', ', map { $_->name_sql($db) } $self->nonlazy_columns);
}
sub column_names_string_sql
{
my($self, $db) = @_;
return $self->{'column_names_string_sql'}{$db->{'id'}} ||=
join(', ', map { $_->name_sql($db) } $self->columns_ordered);
}
sub column_names_sql
{
my($self, $db) = @_;
my $list = $self->{'column_names_sql'}{$db->{'id'}} ||=
[ map { $_->name_sql($db) } $self->columns_ordered ];
return wantarray ? @$list : $list;
}
sub select_nonlazy_columns_string_sql
{
my($self, $db) = @_;
return $self->{'select_nonlazy_columns_string_sql'}{$db->{'id'}} ||=
join(', ', @{ scalar $self->select_nonlazy_columns_sql($db) });
}
sub select_columns_string_sql
{
my($self, $db) = @_;
return $self->{'select_columns_string_sql'}{$db->{'id'}} ||=
join(', ', @{ scalar $self->select_columns_sql($db) });
}
sub select_columns_sql
{
my($self, $db) = @_;
my $list = $self->{'select_columns_sql'}{$db->{'id'}};
unless($list)
{
my $table = $self->table;
if($self->sql_qualify_column_names_on_load)
{
$list = [ map { $_->select_sql($db, $table) } $self->columns_ordered ];
}
else
{
$list = [ map { $_->select_sql($db) } $self->columns_ordered ];
}
$self->{'select_columns_sql'}{$db->{'id'}} = $list;
}
return wantarray ? @$list : $list;
}
sub select_nonlazy_columns_sql
{
my($self, $db) = @_;
my $list = $self->{'select_nonlazy_columns_sql'}{$db->{'id'}};
unless($list)
{
my $table = $self->table;
if($self->sql_qualify_column_names_on_load)
{
$list = [ map { $_->select_sql($db, $table) } $self->nonlazy_columns ];
}
else
{
$list = [ map { $_->select_sql($db) } $self->nonlazy_columns ];
}
$self->{'select_nonlazy_columns_sql'}{$db->{'id'}} = $list;
}
return wantarray ? @$list : $list;
}
sub method_column
{
my($self, $method) = @_;
unless(defined $self->{'method_columns'})
{
foreach my $column ($self->columns_ordered)
{
foreach my $type ($column->defined_method_types)
{
if(my $method = $column->method_name($type))
{
$self->{'method_column'}{$method} = $column;
}
}
}
}
return $self->{'method_column'}{$method};
}
sub column_rw_method_names
{
my($self) = shift;
$self->{'column_rw_method_names'} ||=
[ map { $self->column_rw_method_name($_) } $self->column_names ];
return wantarray ? @{$self->{'column_rw_method_names'}} :
$self->{'column_rw_method_names'};
}
sub column_accessor_method_names
{
my($self) = shift;
$self->{'column_accessor_method_names'} ||=
[ map { $self->column_accessor_method_name($_) } $self->column_names ];
return wantarray ? @{$self->{'column_accessor_method_names'}} :
$self->{'column_accessor_method_names'};
}
sub nonpersistent_column_accessor_method_names
{
my($self) = shift;
$self->{'nonpersistent_column_accessor_method_names'} ||=
[ map { $self->nonpersistent_column_accessor_method_name($_) } $self->nonpersistent_column_names ];
return wantarray ? @{$self->{'nonpersistent_column_accessor_method_names'}} :
$self->{'nonpersistent_column_accessor_method_names'};
}
sub nonlazy_column_accessor_method_names
{
my($self) = shift;
$self->{'nonlazy_column_accessor_method_names'} ||=
[ map { $self->column_accessor_method_name($_) } $self->nonlazy_column_names ];
return wantarray ? @{$self->{'nonlazy_column_accessor_method_names'}} :
$self->{'nonlazy_column_accessor_method_names'};
}
sub column_mutator_method_names
{
my($self) = shift;
$self->{'column_mutator_method_names'} ||=
[ map { $self->column_mutator_method_name($_) } $self->column_names ];
return wantarray ? @{$self->{'column_mutator_method_names'}} :
$self->{'column_mutator_method_names'};
}
sub nonpersistent_column_mutator_method_names
{
my($self) = shift;
$self->{'nonpersistent_column_mutator_method_names'} ||=
[ map { $self->nonpersistent_column_mutator_method_name($_) } $self->nonpersistent_column_names ];
return wantarray ? @{$self->{'nonpersistent_column_mutator_method_names'}} :
$self->{'nonpersistent_column_mutator_method_names'};
}
sub nonlazy_column_mutator_method_names
{
my($self) = shift;
$self->{'nonlazy_column_mutator_method_names'} ||=
[ map { $self->column_mutator_method_name($_) } $self->nonlazy_column_names ];
return wantarray ? @{$self->{'nonlazy_column_mutator_method_names'}} :
$self->{'nonlazy_column_mutator_method_names'};
}
sub column_db_value_hash_keys
{
my($self) = shift;
$self->{'column_db_value_hash_keys'} ||=
{ map { $_->mutator_method_name => $_->db_value_hash_key } $self->columns_ordered };
return wantarray ? %{$self->{'column_db_value_hash_keys'}} :
$self->{'column_db_value_hash_keys'};
}
sub nonlazy_column_db_value_hash_keys
{
my($self) = shift;
$self->{'nonlazy_column_db_value_hash_keys'} ||=
{ map { $_->mutator_method_name => $_->db_value_hash_key } $self->nonlazy_columns };
return wantarray ? %{$self->{'nonlazy_column_db_value_hash_keys'}} :
$self->{'nonlazy_column_db_value_hash_keys'};
}
sub primary_key_column_db_value_hash_keys
{
my($self) = shift;
$self->{'primary_key_column_db_value_hash_keys'} ||=
[ map { $_->db_value_hash_key } $self->primary_key_columns ];
return wantarray ? @{$self->{'primary_key_column_db_value_hash_keys'}} :
$self->{'primary_key_column_db_value_hash_keys'};
}
sub alias_column
{
my($self, $name, $new_name) = @_;
Carp::croak "Usage: alias_column(column name, new name)"
unless(@_ == 3);
Carp::croak "No such column '$name' in table ", $self->table
unless($self->{'columns'}{$name});
Carp::cluck "Pointless alias for '$name' to '$new_name' for table ", $self->table
unless($name ne $new_name);
# XXX: Allow primary keys to be aliased
# XXX: Was disabled because the Manager was not happy with this.
#foreach my $column ($self->primary_key_column_names)
#{
# if($name eq $column)
# {
# Carp::croak "Primary key columns cannot be aliased (the culprit: '$name')";
# }
#}
$self->_clear_column_generated_values;
if(my $column = $self->column($name))
{
$column->method_name($new_name);
}
$self->{'column_aliases'}{$name} = $new_name;
}
sub column_aliases
{
return $_[0]->{'column_aliases'} unless(@_ > 1);
return $_[0]->{'column_aliases'} = (ref $_[1] eq 'HASH') ? $_[1] : { @_[1 .. $#_] };
}
sub column_accessor_method_name
{
$_[0]->{'column_accessor_method'}{$_[1]} ||=
($_[0]->column($_[1]) ? $_[0]->column($_[1])->accessor_method_name : undef);
}
sub nonpersistent_column_accessor_method_name
{
$_[0]->{'nonpersistent_column_accessor_method'}{$_[1]} ||=
($_[0]->nonpersistent_column($_[1]) ? $_[0]->nonpersistent_column($_[1])->accessor_method_name : undef);
}
sub column_accessor_method_names_hash { shift->{'column_accessor_method'} }
sub nonpersistent_column_accessor_method_names_hash { shift->{'nonpersistent_column_accessor_method'} }
sub key_column_accessor_method_names_hash
{
my($self) = shift;
return $self->{'key_column_accessor_method'} if($self->{'key_column_accessor_method'});
foreach my $column (grep { ref } $self->primary_key_columns)
{
$self->{'key_column_accessor_method'}{$column->name} = $column->accessor_method_name;
}
foreach my $uk ($self->unique_keys)
{
foreach my $column (grep { ref } $uk->columns)
{
$self->{'key_column_accessor_method'}{$column->name} = $column->accessor_method_name;
}
}
return $self->{'key_column_accessor_method'};
}
sub column_mutator_method_name
{
$_[0]->{'column_mutator_method'}{$_[1]} ||=
($_[0]->column($_[1]) ? $_[0]->column($_[1])->mutator_method_name : undef);
}
sub nonpersistent_column_mutator_method_name
{
$_[0]->{'nonpersistent_column_mutator_method'}{$_[1]} ||=
($_[0]->nonpersistent_column($_[1]) ? $_[0]->nonpersistent_column($_[1])->mutator_method_name : undef);
}
sub column_mutator_method_names_hash { shift->{'column_mutator_method'} }
sub column_rw_method_name
{
$_[0]->{'column_rw_method'}{$_[1]} ||=
$_[0]->column($_[1])->rw_method_name;
}
sub column_rw_method_names_hash { shift->{'column_rw_method'} }
sub fq_table_sql
{
my($self, $db) = @_;
return $self->{'fq_table_sql'}{$db->{'id'}} ||=
join('.', grep { defined } ($self->select_catalog($db),
$self->select_schema($db),
$db->auto_quote_table_name($self->table)));
}
sub fqq_table_sql
{
my($self, $db) = @_;
return $self->{'fq_table_sql'}{$db->{'id'}} ||=
join('.', grep { defined } ($self->select_catalog($db),
$self->select_schema($db),
$db->quote_table_name($self->table)));
}
sub fq_table
{
my($self, $db) = @_;
return $self->{'fq_table'}{$db->{'id'}} ||=
join('.', grep { defined } ($self->select_catalog($db),
$self->select_schema($db),
$self->table));
}
sub load_all_sql
{
my($self, $key_columns, $db) = @_;
$key_columns ||= $self->primary_key_column_names;
no warnings;
return $self->{'load_all_sql'}{$db->{'id'}}{join("\0", @$key_columns)} ||=
'SELECT ' . $self->select_columns_string_sql($db) . ' FROM ' .
$self->fq_table_sql($db) . ' WHERE ' .
join(' AND ', map
{
my $c = $self->column($_);
($self->sql_qualify_column_names_on_load ?
$db->auto_quote_column_with_table($c->name_sql, $self->table) : $c->name_sql($db)) .
' = ' . $c->query_placeholder_sql($db)
}
@$key_columns);
}
sub load_sql
{
my($self, $key_columns, $db) = @_;
$key_columns ||= $self->primary_key_column_names;
no warnings;
return $self->{'load_sql'}{$db->{'id'}}{join("\0", @$key_columns)} ||=
'SELECT ' . $self->select_nonlazy_columns_string_sql($db) . ' FROM ' .
$self->fq_table_sql($db) . ' WHERE ' .
join(' AND ', map
{
my $c = $self->column($_);
($self->sql_qualify_column_names_on_load ?
$db->auto_quote_column_with_table($c->name_sql, $self->table) : $c->name_sql($db)) .
' = ' . $c->query_placeholder_sql($db)
}
@$key_columns);
}
sub load_all_sql_with_null_key
{
my($self, $key_columns, $key_values, $db) = @_;
my $i = 0;
my $fq = $self->sql_qualify_column_names_on_load;
my $table = $self->table;
no warnings;
return
'SELECT ' . $self->select_columns_string_sql($db) . ' FROM ' .
$self->fq_table_sql($db) . ' WHERE ' .
join(' AND ', map
{
my $c = $self->column($_);
($fq ? $db->auto_quote_column_with_table($c->name_sql, $table) : $c->name_sql($db)) .
(defined $key_values->[$i++] ? ' = ' . $c->query_placeholder_sql : ' IS NULL')
}
@$key_columns);
}
sub load_sql_with_null_key
{
my($self, $key_columns, $key_values, $db) = @_;
my $i = 0;
my $fq = $self->sql_qualify_column_names_on_load;
my $table = $self->table;
no warnings;
return
'SELECT ' . $self->select_nonlazy_columns_string_sql($db) . ' FROM ' .
$self->fq_table_sql($db) . ' WHERE ' .
join(' AND ', map
{
my $c = $self->column($_);
($fq ? $db->auto_quote_column_with_table($c->name_sql, $table) : $c->name_sql($db)) .
(defined $key_values->[$i++] ? ' = ' . $c->query_placeholder_sql : ' IS NULL')
}
@$key_columns);
}
sub update_all_sql
{
my($self, $key_columns, $db) = @_;
$key_columns ||= $self->primary_key_column_names;
my $cache_key = "$db->{'id'}:" . join("\0", @$key_columns);
return $self->{'update_all_sql'}{$cache_key}
if($self->{'update_all_sql'}{$cache_key});
my %key = map { ($_ => 1) } @$key_columns;
no warnings;
return $self->{'update_all_sql'}{$cache_key} =
'UPDATE ' . $self->fq_table_sql($db) . " SET \n" .
join(",\n", map
{
' ' . $_->name_sql($db) . ' = ' . $_->update_placeholder_sql($db)
}
grep { !$key{$_->name} } $self->columns_ordered) .
"\nWHERE " .
join(' AND ', map
{
my $c = $self->column($_);
$c->name_sql($db) . ' = ' . $c->query_placeholder_sql
}
@$key_columns);
}
use constant LAZY_LOADED_KEY => lazy_column_values_loaded_key();
sub update_sql
{
my($self, $obj, $key_columns, $db) = @_;
$key_columns ||= $self->primary_key_column_names;
my %key = map { ($_ => 1) } @$key_columns;
no warnings 'uninitialized';
my @columns =
grep { !$key{$_->name} && (!$_->lazy || $obj->{LAZY_LOADED_KEY()}{$_->name}) }
$self->columns_ordered;
my @exec;
unless($self->dbi_requires_bind_param($db))
{
my $method_name = $self->column_accessor_method_names_hash;
foreach my $column (@columns)
{
my $method = $method_name->{$column->{'name'}};
push(@exec, $obj->$method());
}
}
return (($self->{'update_sql_prefix'}{$db->{'id'}} ||
$self->init_update_sql_prefix($db)) .
join(",\n", map
{
' ' . $_->name_sql($db) . ' = ' . $_->update_placeholder_sql($db)
}
@columns) .
"\nWHERE " .
join(' AND ', map
{
my $c = $self->column($_);
$c->name_sql($db) . ' = ' . $c->query_placeholder_sql($db)
}
@$key_columns),
\@exec,
\@columns);
}
sub init_update_sql_prefix
{
my($self, $db) = @_;
return $self->{'update_sql_prefix'}{$db->{'id'}} =
'UPDATE ' . $self->fq_table_sql($db) . " SET \n";
}
sub update_changes_only_sql
{
my($self, $obj, $key_columns, $db) = @_;
$key_columns ||= $self->primary_key_column_names;
my %key = map { ($_ => 1) } @$key_columns;
my @modified = map { $self->column($_) } grep { !$key{$_} } keys %{$obj->{MODIFIED_COLUMNS()} || {}};
return unless(@modified);
no warnings;
return ($self->{'update_sql_prefix'}{$db->{'id'}} ||=
'UPDATE ' . $self->fq_table_sql($db) . " SET \n") .
join(",\n", map
{
' ' . $_->name_sql($db) . ' = ' . $_->update_placeholder_sql($db)
}
@modified) .
"\nWHERE " .
join(' AND ', map
{
my $c = $self->column($_);
$c->name_sql($db) . ' = ' . $c->query_placeholder_sql($db)
}
@$key_columns),
[ map { my $m = $_->accessor_method_name; $obj->$m() } @modified ],
\@modified;
}
# This is nonsensical right now because the primary key always has to be
# non-null, and any update will use the primary key instead of a unique
# key. But I'll leave the code here (commented out) just in case.
#
# sub update_all_sql_with_null_key
# {
# my($self, $key_columns, $key_values, $db) = @_;
#
# my %key = map { ($_ => 1) } @$key_columns;
# my $i = 0;
#
# no warnings;
# return
# 'UPDATE ' . $self->fq_table_sql($db) . " SET \n" .
# join(",\n", map { ' ' . $self->column($_)->name_sql($db) . ' = ?' }
# grep { !$key{$_} } $self->column_names) .
# "\nWHERE " . join(' AND ', map { defined $key_values->[$i++] ? "$_ = ?" : "$_ IS NULL" }
# map { $self->column($_)->name_sql($db) } @$key_columns);
# }
#
# Ditto for this version of update_sql_with_inlining which handles null keys
#
# sub update_sql_with_inlining
# {
# my($self, $obj, $key_columns, $key_values) = @_;
#
# my $db = $obj->db or Carp::croak "Missing db";
#
# $key_columns ||= $self->primary_key_column_names;
#
# my %key = map { ($_ => 1) } @$key_columns;
#
# my @bind;
# my @updates;
#
# foreach my $column (grep { !$key{$_} } $self->columns_ordered)
# {
# my $method = $self->column_method($column->name);
# my $value = $obj->$method();
#
# if($column->should_inline_value($db, $value))
# {
# push(@updates, ' ' . $column->name_sql($db) . " = $value");
# }
# else
# {
# push(@updates, ' ' . $column->name_sql($db) . ' = ?');
# push(@bind, $value);
# }
# }
#
# my $i = 0;
#
# no warnings;
# return
# (
# ($self->{'update_sql_with_inlining_start'} ||=
# 'UPDATE ' . $self->fq_table_sql($db) . " SET \n") .
# join(",\n", @updates) . "\nWHERE " .
# join(' AND ', map { defined $key_values->[$i++] ? "$_ = ?" : "$_ IS NULL" }
# map { $self->column($_)->name_sql($db) } @$key_columns),
# \@bind
# );
# }
sub update_sql_with_inlining
{
my($self, $obj, $key_columns) = @_;
my $db = $obj->db or Carp::croak "Missing db";
$key_columns ||= $self->primary_key_column_names;
my %key = map { ($_ => 1) } @$key_columns;
my(@bind, @updates, @bind_params);
my $do_bind_params = $self->dbi_requires_bind_param($db);
foreach my $column (grep { !$key{$_} && (!$_->{'lazy'} ||
$obj->{LAZY_LOADED_KEY()}{$_->{'name'}}) }
$self->columns_ordered)
{
my $method = $self->column_accessor_method_name($column->name);
my $value = $obj->$method();
if($column->should_inline_value($db, $value))
{
push(@updates, $column->name_sql($db) . " = $value");
}
else
{
push(@updates, $column->name_sql($db) . ' = ' .
$column->update_placeholder_sql($db));
push(@bind, $value);
if($do_bind_params)
{
push(@bind_params, $column->dbi_bind_param_attrs($db));
}
}
}
my $i = 0;
no warnings;
return
(
($self->{'update_sql_with_inlining_start'}{$db->{'id'}} ||
$self->init_update_sql_with_inlining_start($db)) .
join(",\n", @updates) . "\nWHERE " .
join(' AND ', map
{
my $c = $self->column($_);
$c->name_sql($db) . ' = ' . $c->query_placeholder_sql($db)
}
@$key_columns),
\@bind,
($do_bind_params ? \@bind_params : ())
);
}
sub init_update_sql_with_inlining_start
{
my($self, $db) = @_;
return $self->{'update_sql_with_inlining_start'}{$db->{'id'}} =
'UPDATE ' . $self->fq_table_sql($db) . " SET \n";
}
sub update_changes_only_sql_with_inlining
{
my($self, $obj, $key_columns) = @_;
my $db = $obj->db or Carp::croak "Missing db";
$key_columns ||= $self->primary_key_column_names;
my %key = map { ($_ => 1) } @$key_columns;
my $modified = $obj->{MODIFIED_COLUMNS()};
my(@bind, @updates, @bind_params);
my $do_bind_params = $self->dbi_requires_bind_param($db);
foreach my $column (grep { !$key{$_->{'name'}} && $modified->{$_->{'name'}} } $self->columns_ordered)
{
my $method = $self->column_accessor_method_name($column->name);
my $value = $obj->$method();
if($column->should_inline_value($db, $value))
{
push(@updates, ' ' . $column->name_sql($db) . " = $value");
}
else
{
push(@updates, $column->name_sql($db) . ' = ' .
$column->update_placeholder_sql($db));
push(@bind, $value);
if($do_bind_params)
{
push(@bind_params, $column->dbi_bind_param_attrs($db));
}
}
}
return unless(@updates);
my $i = 0;
no warnings;
return
(
($self->{'update_sql_with_inlining_start'}{$db->{'id'}} ||=
'UPDATE ' . $self->fq_table_sql($db) . " SET \n") .
join(",\n", @updates) . "\nWHERE " .
join(' AND ', map
{
my $c = $self->column($_);
$c->name_sql($db) . ' = ' . $c->query_placeholder_sql($db)
}
@$key_columns),
\@bind,
($do_bind_params ? \@bind_params : ())
);
}
sub insert_sql
{
my($self, $db) = @_;
no warnings;
return $self->{'insert_sql'}{$db->{'id'}} ||=
'INSERT INTO ' . $self->fq_table_sql($db) . "\n(\n" .
join(",\n", map { " $_" } $self->column_names_sql($db)) .
"\n)\nVALUES\n(\n" . $self->insert_columns_placeholders_sql($db) .
"\n)";
}
sub insert_changes_only_sql
{
my($self, $obj, $db) = @_;
my $modified = $obj->{MODIFIED_COLUMNS()} || {};
my @modified = grep { $modified->{$_->{'name'}} || $_->default_exists } $self->columns_ordered;
unless(@modified)
{
# Make a last-ditch attempt to insert with no modified columns
# using the DEFAULT keyword on an arbitrary column. This works
# in MySQL and PostgreSQL.
if($db->supports_arbitrary_defaults_on_insert)
{
return
'INSERT INTO ' . $self->fq_table_sql($db) . ' (' .
($self->columns_ordered)[-1]->name_sql($db) . ') VALUES (DEFAULT)',
[];
}
else
{
Carp::croak "Cannot insert row into table '", $self->table,
"' - No columns have modified or default values";
}
}
no warnings;
return ($self->{'insert_changes_only_sql_prefix'}{$db->{'id'}} ||
$self->init_insert_changes_only_sql_prefix($db)) .
join(",\n", map { $_->name_sql($db) } @modified) .
"\n)\nVALUES\n(\n" .
join(",\n", map { $_->insert_placeholder_sql($db) } @modified) . "\n)",
[ map { my $m = $_->accessor_method_name; $obj->$m() } @modified ],
\@modified;
}
sub init_insert_changes_only_sql_prefix
{
my($self, $db) = @_;
return $self->{'insert_changes_only_sql_prefix'}{$db->{'id'}} =
'INSERT INTO ' . $self->fq_table_sql($db) . "\n(\n";
;
}
sub insert_columns_placeholders_sql
{
my($self, $db) = @_;
return $self->{'insert_columns_placeholders_sql'}{$db->{'id'}} ||=
join(",\n", map { ' ' . $_->insert_placeholder_sql($db) } $self->columns_ordered)
}
sub insert_and_on_duplicate_key_update_sql
{
my($self, $obj, $db, $changes_only) = @_;
my(@columns, @names, @bind);
if($obj->{STATE_IN_DB()})
{
my %seen;
@columns = $changes_only ?
(map { $self->column($_) } grep { !$seen{$_}++ }
($self->primary_key_column_names,
keys %{$obj->{MODIFIED_COLUMNS()} || {}})) :
(grep { (!$_->{'lazy'} || $obj->{LAZY_LOADED_KEY()}{$_->{'name'}}) }
$self->columns_ordered);
@names = map { $_->name_sql($db) } @columns;
foreach my $column (@columns)
{
my $method = $self->column_accessor_method_name($column->{'name'});
push(@bind, $obj->$method());
}
}
else
{
my %skip;
my @key_columns = $self->primary_key_column_names;
my @key_methods = $self->primary_key_column_accessor_names;
my @key_values = grep { defined } map { $obj->$_() } @key_methods;
unless(@key_values)
{
@skip{@key_columns} = (1) x @key_columns;
}
foreach my $uk ($self->unique_keys)
{
@key_columns = $uk->columns;
@key_methods = map { $_->accessor_method_name } @key_columns;
@key_values = grep { defined } map { $obj->$_() } @key_methods;
unless(@key_values)
{
@skip{@key_columns} = (1) x @key_columns;
}
}
@columns = $changes_only ?
(map { $self->column($_) } grep { !$skip{"$_"} } keys %{$obj->{MODIFIED_COLUMNS()} || {}}) :
(grep { !$skip{"$_"} && (!$_->{'lazy'} ||
$obj->{LAZY_LOADED_KEY()}{$_->{'name'}}) } $self->columns_ordered);
@names = map { $_->name_sql($db) } @columns;
foreach my $column (@columns)
{
my $method = $self->column_accessor_method_name($column->{'name'});
push(@bind, $obj->$method());
}
}
no warnings;
return
'INSERT INTO ' . $self->fq_table_sql($db) . "\n(\n" .
join(",\n", @names) .
"\n)\nVALUES\n(\n" .
join(",\n", map { $_->insert_placeholder_sql($db) } @columns) .
"\n)\nON DUPLICATE KEY UPDATE\n" .
join(",\n", map
{
$_->name_sql($db) . ' = ' . $_->update_placeholder_sql($db)
}
@columns),
[ @bind, @bind ],
[ @columns, @columns ];
}
sub insert_sql_with_inlining
{
my($self, $obj) = @_;
my $db = $obj->db or Carp::croak "Missing db";
my(@bind, @places, @bind_params);
my $do_bind_params = $self->dbi_requires_bind_param($db);
foreach my $column ($self->columns_ordered)
{
my $method = $self->column_accessor_method_name($column->name);
my $value = $obj->$method();
if($column->should_inline_value($db, $value))
{
push(@places, " $value");
}
else
{
push(@places, $column->insert_placeholder_sql($db));
push(@bind, $value);
if($do_bind_params)
{
push(@bind_params, $column->dbi_bind_param_attrs($db));
}
}
}
return
(
($self->{'insert_sql_with_inlining_start'}{$db->{'id'}} ||
$self->init_insert_sql_with_inlining_start($db)) .
join(",\n", @places) . "\n)",
\@bind,
($do_bind_params ? \@bind_params : ())
);
}
sub init_insert_sql_with_inlining_start
{
my($self, $db) = @_;
$self->{'insert_sql_with_inlining_start'}{$db->{'id'}} =
'INSERT INTO ' . $self->fq_table_sql($db) . "\n(\n" .
join(",\n", map { " $_" } $self->column_names_sql($db)) .
"\n)\nVALUES\n(\n";
}
sub insert_and_on_duplicate_key_update_with_inlining_sql
{
my($self, $obj, $db, $changes_only) = @_;
my(@columns, @names);
my $do_bind_params = $self->dbi_requires_bind_param($db);
if($obj->{STATE_IN_DB()})
{
my %seen;
@columns = $changes_only ?
(map { $self->column($_) } grep { !$seen{$_}++ }
($self->primary_key_column_names,
keys %{$obj->{MODIFIED_COLUMNS()} || {}})) :
(grep { (!$_->{'lazy'} || $obj->{LAZY_LOADED_KEY()}{$_->{'name'}}) }
$self->columns_ordered);
@names = map { $_->name_sql($db) } @columns;
}
else
{
my %skip;
my @key_columns = $self->primary_key_column_names;
my @key_methods = $self->primary_key_column_accessor_names;
my @key_values = grep { defined } map { $obj->$_() } @key_methods;
unless(@key_values)
{
@skip{@key_columns} = (1) x @key_columns;
}
foreach my $uk ($self->unique_keys)
{
@key_columns = $uk->columns;
@key_methods = map { $_->accessor_method_name } @key_columns;
@key_values = grep { defined } map { $obj->$_() } @key_methods;
unless(@key_values)
{
@skip{@key_columns} = (1) x @key_columns;
}
}
@columns = $changes_only ?
(map { $self->column($_) } grep { !$skip{"$_"} } keys %{$obj->{MODIFIED_COLUMNS()} || {}}) :
(grep { !$skip{"$_"} && (!$_->{'lazy'} ||
$obj->{LAZY_LOADED_KEY()}{$_->{'name'}}) } $self->columns_ordered);
@names = map { $_->name_sql($db) } @columns;
}
my(@bind, @places, @bind_params);
foreach my $column (@columns)
{
my $name = $column->{'name'};
my $method = $self->column_accessor_method_name($name);
my $value = $obj->$method();
if($column->should_inline_value($db, $value))
{
push(@places, [ $name, $column->inline_value_sql($value) ]);
}
else
{
push(@places, [ $name, $column->insert_placeholder_sql($_) ]);
push(@bind, $value);
if($do_bind_params)
{
push(@bind_params, $column->dbi_bind_param_attrs($db));
}
}
}
no warnings;
return
'INSERT INTO ' . $self->fq_table_sql($db) . "\n(\n" .
join(",\n", @names) .
"\n)\nVALUES\n(\n" . join(",\n", map { $_->[1] } @places) . "\n)\n" .
"ON DUPLICATE KEY UPDATE\n" .
join(",\n", map { "$_->[0] = $_->[1]" } @places),
[ @bind, @bind ],
($do_bind_params ? \@bind_params : ());
}
sub insert_changes_only_sql_with_inlining
{
my($self, $obj) = @_;
my $db = $obj->db or Carp::croak "Missing db";
my $modified = $obj->{MODIFIED_COLUMNS()} || {};
my @modified = grep { $modified->{$_->{'name'}} || $_->default_exists } $self->columns_ordered;
unless(@modified)
{
# Make a last-ditch attempt to insert with no modified columns
# using the DEFAULT keyword on an arbitrary column. This works
# in MySQL and PostgreSQL.
if($db->supports_arbitrary_defaults_on_insert)
{
return
'INSERT INTO ' . $self->fq_table_sql($db) . ' (' .
($self->columns_ordered)[-1]->name_sql($db) . ') VALUES (DEFAULT)',
[];
}
else
{
Carp::croak "Cannot insert row into table '", $self->table,
"' - No columns have modified or default values";
}
}
my(@bind, @places, @bind_params);
my $do_bind_params = $self->dbi_requires_bind_param($db);
foreach my $column (@modified)
{
my $method = $self->column_accessor_method_name($column->name);
my $value = $obj->$method();
if($column->should_inline_value($db, $value))
{
push(@places, " $value");
}
else
{
push(@places, $column->insert_placeholder_sql($db));
push(@bind, $value);
if($do_bind_params)
{
push(@bind_params, $column->dbi_bind_param_attrs($db));
}
}
}
return
(
'INSERT INTO ' . $self->fq_table_sql($db) . "\n(\n" .
join(",\n", map { $_->name_sql($db) } @modified) .
"\n)\nVALUES\n(\n" . join(",\n", @places) . "\n)",
\@bind,
($do_bind_params ? \@bind_params : ())
);
}
sub delete_sql
{
my($self, $db) = @_;
return $self->{'delete_sql'}{$db->{'id'}} ||=
'DELETE FROM ' . $self->fq_table_sql($db) . ' WHERE ' .
join(' AND ',
map { $_->name_sql($db) . ' = ' . $_->query_placeholder_sql($db) }
$self->primary_key_columns);
}
sub get_column_value
{
my($self, $object, $column) = @_;
my $db = $object->db or Carp::confess $object->error;
my $dbh = $db->dbh or Carp::confess $db->error;
my $sql = $self->{'get_column_sql_tmpl'}{$db->{'id'}} ||
$self->init_get_column_sql_tmpl($db);
$sql =~ s/__COLUMN__/$column->name_sql($db)/e;
my @key_values =
map { $object->$_() }
map { $self->column_accessor_method_name($_) }
$self->primary_key_column_names;
my($value, $error);
TRY:
{
local $@;
eval
{
($Debug || $Rose::DB::Object::Debug) && warn "$sql (@key_values)\n";
my $sth = $dbh->prepare($sql);
$sth->execute(@key_values);
$sth->bind_columns(\$value);
$sth->fetch;
};
$error = $@;
}
if($error)
{
Carp::croak "Could not lazily-load column value for column '",
$column->name, "' - $error";
}
return $value;
}
sub init_get_column_sql_tmpl
{
my($self, $db) = @_;
my $key_columns = $self->primary_key_column_names;
my %key = map { ($_ => 1) } @$key_columns;
return $self->{'get_column_sql_tmpl'}{$db->{'id'}} =
'SELECT __COLUMN__ FROM ' . $self->fq_table_sql($db) . ' WHERE ' .
join(' AND ', map
{
my $c = $self->column($_);
$c->name_sql($db) . ' = ' . $c->query_placeholder_sql($db)
}
@$key_columns);
}
sub refresh_lazy_column_tracking
{
my($self) = shift;
$self->_clear_column_generated_values;
# Initialize method name hashes
$self->column_accessor_method_names;
$self->column_mutator_method_names;
$self->column_rw_method_names;
return $self->{'has_lazy_columns'} = grep { $_->lazy } $self->columns_ordered;
}
sub has_lazy_columns
{
my($self) = shift;
return $self->{'has_lazy_columns'} if(defined $self->{'has_lazy_columns'});
return $self->{'has_lazy_columns'} = grep { $_->lazy } $self->columns_ordered;
}
sub prime_all_caches
{
my($class) = shift;
foreach my $obj_class ($class->registered_classes)
{
$obj_class->meta->prime_caches(@_);
}
}
sub prime_caches
{
my($self, %args) = @_;
my @methods =
qw(column_names num_columns nonlazy_column_names lazy_column_names
column_rw_method_names column_accessor_method_names
nonlazy_column_accessor_method_names column_mutator_method_names
nonlazy_column_mutator_method_names nonlazy_column_db_value_hash_keys
primary_key_column_db_value_hash_keys column_db_value_hash_keys
column_accessor_method_names column_mutator_method_names
column_rw_method_names key_column_accessor_method_names_hash);
foreach my $method (@methods)
{
$self->$method();
}
my $db = $args{'db'} || $self->class->init_db;
$self->method_column('nonesuch');
$self->fq_primary_key_sequence_names(db => $db);
@methods =
qw(dbi_requires_bind_param fq_table fq_table_sql init_get_column_sql_tmpl
delete_sql primary_key_sequence_names insert_sql
init_insert_sql_with_inlining_start
init_insert_changes_only_sql_prefix init_update_sql_prefix
init_update_sql_with_inlining_start column_names_string_sql
nonlazy_column_names_string_sql select_nonlazy_columns_string_sql
select_columns_string_sql select_columns_sql select_nonlazy_columns_sql);
foreach my $method (@methods)
{
$self->$method($db);
}
undef @methods; # reclaim memory?
foreach my $key ($self->primary_key, $self->unique_keys)
{
foreach my $method (qw(update_all_sql load_sql load_all_sql))
{
$self->$method(scalar $key->columns, $db);
}
}
}
sub _clear_table_generated_values
{
my($self) = shift;
$self->{'fq_table'} = undef;
$self->{'fq_table_sql'} = undef;
$self->{'get_column_sql_tmpl'} = undef;
$self->{'load_sql'} = undef;
$self->{'load_all_sql'} = undef;
$self->{'delete_sql'} = undef;
$self->{'fq_primary_key_sequence_names'} = undef;
$self->{'primary_key_sequence_names'} = undef;
$self->{'insert_sql'} = undef;
$self->{'insert_sql_with_inlining_start'} = undef;
$self->{'insert_changes_only_sql_prefix'} = undef;
$self->{'update_sql_prefix'} = undef;
$self->{'update_sql_with_inlining_start'} = undef;
$self->{'update_all_sql'} = undef;
}
sub _clear_column_generated_values
{
my($self) = shift;
$self->{'fq_table'} = undef;
$self->{'fq_table_sql'} = undef;
$self->{'column_names'} = undef;
$self->{'num_columns'} = undef;
$self->{'nonlazy_column_names'} = undef;
$self->{'lazy_column_names'} = undef;
$self->{'column_names_sql'} = undef;
$self->{'get_column_sql_tmpl'} = undef;
$self->{'column_names_string_sql'} = undef;
$self->{'nonlazy_column_names_string_sql'} = undef;
$self->{'column_rw_method_names'} = undef;
$self->{'column_accessor_method_names'} = undef;
$self->{'nonlazy_column_accessor_method_names'} = undef;
$self->{'column_mutator_method_names'} = undef;
$self->{'nonlazy_column_mutator_method_names'} = undef;
$self->{'nonlazy_column_db_value_hash_keys'} = undef;
$self->{'primary_key_column_db_value_hash_keys'}= undef;
$self->{'primary_key_column_names_or_aliases'} = undef
$self->{'column_db_value_hash_keys'} = undef;
$self->{'select_nonlazy_columns_string_sql'} = undef;
$self->{'select_columns_string_sql'} = undef;
$self->{'select_columns_sql'} = undef;
$self->{'select_nonlazy_columns_sql'} = undef;
$self->{'method_columns'} = undef;
$self->{'column_accessor_method'} = undef;
$self->{'key_column_accessor_method'} = undef;
$self->{'column_rw_method'} = undef;
$self->{'load_sql'} = undef;
$self->{'load_all_sql'} = undef;
$self->{'update_all_sql'} = undef;
$self->{'update_sql_prefix'} = undef;
$self->{'insert_sql'} = undef;
$self->{'insert_sql_with_inlining_start'} = undef;
$self->{'update_sql_with_inlining_start'} = undef;
$self->{'insert_changes_only_sql_prefix'} = undef;
$self->{'delete_sql'} = undef;
$self->{'insert_columns_placeholders_sql'} = undef;
$self->{'dbi_requires_bind_param'} = undef;
$self->{'key_column_names'} = undef;
}
sub _clear_nonpersistent_column_generated_values
{
my($self) = shift;
$self->{'nonpersistent_column_names'} = undef;
$self->{'nonpersistent_column_accessor_method_names'} = undef;
$self->{'nonpersistent_column_accessor_method'} = undef;
$self->{'nonpersistent_column_mutator_method_names'} = undef;
$self->{'nonpersistent_column_mutator_method'} = undef;
}
sub _clear_primary_key_column_generated_values
{
my($self) = shift;
$self->{'primary_key_column_accessor_names'} = undef;
$self->{'primary_key_column_mutator_names'} = undef;
$self->{'key_column_accessor_method'} = undef;
$self->{'primary_key_column_names_or_aliases'} = undef;
$self->{'key_column_names'} = undef;
}
sub method_name_is_reserved
{
my($self, $name, $class) = @_;
if(!defined $class && UNIVERSAL::isa($self, __PACKAGE__))
{
$class ||= $self->class or die "Missing class!";
}
Carp::confess "Missing method name argument in call to method_name_is_reserved()"
unless(defined $name);
if(index($name, PRIVATE_PREFIX) == 0)
{
return "The method prefix '", PRIVATE_PREFIX, "' is reserved."
}
elsif($name =~ /^(?:meta|dbh?|_?init_db|error|not_found|load|save|update|insert|delete|DESTROY)$/ ||
($class->isa('Rose::DB::Object::Cached') && $name =~ /^(?:remember|forget(?:_all)?)$/))
{
return "This method name is reserved for use by the $class API."
}
return 0;
}
sub method_name_from_column_name
{
my($self, $column_name, $method_type) = @_;
my $column = $self->column($column_name) || $self->nonpersistent_column($column_name)
or Carp::confess "No such column: $column_name";
return $self->method_name_from_column($column, $method_type);
}
sub method_name_from_column
{
my($self, $column, $method_type) = @_;
my $default_name = $column->build_method_name_for_type($method_type);
my $method_name =
$column->method_name($method_type) ||
$self->convention_manager->auto_column_method_name($method_type, $column, $default_name, $self->class) ||
$default_name;
if(my $code = $self->column_name_to_method_name_mapper)
{
my $column_name = $column->name;
local $_ = $method_name;
$method_name = $code->($self, $column_name, $method_type, $method_name);
unless(defined $method_name)
{
Carp::croak "column_name_to_method_name_mapper() returned undef ",
"for column name '$column_name' method type '$method_type'"
}
}
return $method_name;
}
sub dbi_requires_bind_param
{
my($self, $db) = @_;
return $self->{'dbi_requires_bind_param'}{$db->{'id'}}
if(defined $self->{'dbi_requires_bind_param'}{$db->{'id'}});
foreach my $column ($self->columns_ordered)
{
if($column->dbi_requires_bind_param($db))
{
return $self->{'dbi_requires_bind_param'}{$db->{'id'}} = 1;
}
}
return $self->{'dbi_requires_bind_param'}{$db->{'id'}} = 0;
}
sub make_manager_class
{
my($self) = shift;
my $error;
TRY:
{
local $@;
eval { eval $self->perl_manager_class(@_) };
$error = $@;
}
if($error)
{
Carp::croak "Could not make manager class - $error\nThe Perl code used was:\n\n",
$self->perl_manager_class(@_);
}
}
sub perl_manager_class
{
my($self) = shift;
my %args;
if(@_ == 1)
{
$args{'base_name'} = shift;
}
else
{
%args = @_;
}
$args{'base_name'} ||= $self->convention_manager->auto_manager_base_name;
$args{'class'} ||= $self->convention_manager->auto_manager_class_name;
unless($args{'class'} =~ /^\w+(?:::\w+)*$/)
{
no warnings;
Carp::croak "Missing or invalid class",
(length $args{'class'} ? ": '$args{'class'}'" : '');
}
unless($args{'isa'})
{
my @def = $self->default_manager_base_class; # may return multiple classes
$args{'isa'} = (@def == 1 && ref $def[0]) ? $def[0] : \@def;
}
$args{'isa'} = [ $args{'isa'} ] unless(ref $args{'isa'});
my($isa, $ok);
foreach my $class (@{$args{'isa'}})
{
unless($class =~ /^\w+(?:::\w+)*$/)
{
no warnings;
Carp::croak "Invalid isa class: '$class'";
}
no strict 'refs';
$isa .= "use $class;\n" unless($class !~ /^Rose::DB::/ && %{"${class}::"});
$ok = 1 if(UNIVERSAL::isa($class, 'Rose::DB::Object::Manager'));
}
unless($ok)
{
Carp::croak
"None of these classes inherit from Rose::DB::Object::Manager: ",
join(', ', @{$args{'isa'}});
}
$isa .= "our \@ISA = qw(@{$args{'isa'}});";
no strict 'refs';
if(@{"$args{'class'}::ISA"})
{
Carp::croak "Can't override class $args{'class'} which already ",
"appears to be defined.";
}
my $object_class = $self->class;
return<<"EOF";
package $args{'class'};
use strict;
$isa
sub object_class { '$object_class' }
__PACKAGE__->make_manager_methods('$args{'base_name'}');
1;
EOF
}
#
# Automatic metadata setup
#
our $AUTOLOAD;
sub DESTROY { }
sub AUTOLOAD
{
if($AUTOLOAD =~ /::((?:auto_(?!helper)|(?:default_)?perl_)\w*)$/)
{
my $method = $1;
my $self = shift;
$self->init_auto_helper;
unless($self->can($method))
{
Carp::croak "No such method '$method' in class ", ref($self);
}
return $self->$method(@_);
}
Carp::confess "No such method: $AUTOLOAD";
}
sub auto_helper_class
{
my($self) = shift;
if(@_)
{
my $driver = lc shift;
return $self->auto_helper_classes->{$driver} = shift if(@_);
return $self->auto_helper_classes->{$driver};
}
else
{
my $db = $self->db or die "Missing db";
return $self->auto_helper_classes->{$db->driver} ||
$self->auto_helper_classes->{'generic'} ||
Carp::croak "Don't know how to auto-initialize using driver '",
$db->driver, "'";
}
}
my %Rebless;
sub init_auto_helper
{
my($self) = shift;
unless($self->isa($self->auto_helper_class))
{
my $class = ref($self) || $self;
my $auto_helper_class = $self->auto_helper_class;
no strict 'refs';
unless(@{"${auto_helper_class}::ISA"})
{
my $error;
TRY:
{
local $@;
eval "use $auto_helper_class";
$error = $@;
}
Carp::croak "Could not load '$auto_helper_class' - $error" if($error);
}
$self->original_class($class);
REBLESS: # Do slightly evil re-blessing magic
{
# Check cache
if(my $new_class = $Rebless{$class,$auto_helper_class})
{
bless $self, $new_class;
}
else
{
# Special, simple case for Rose::DB::Object::Metadata
if($class eq __PACKAGE__)
{
bless $self, $auto_helper_class;
}
else # Handle Rose::DB::Object::Metadata subclasses
{
# If this is a default Rose::DB driver class
if(index($auto_helper_class, 'Rose::DB::') == 0)
{
# Make a new metadata class based on the current class
my $new_class = $class . '::__RoseDBObjectMetadataPrivate__::' . $auto_helper_class;
# Pull all the auto-helper's methods up into the new class,
# unless they're already defined by the original class. This
# is ugly, I know, but remember that it's all an implementation
# detail that could change at any time :)
IMPORT:
{
no strict 'refs';
local(*auto_symbol, *existing_symbol);
while(my($name, $value) = each(%{"${auto_helper_class}::"}))
{
no warnings;
next if($name =~ /^[A-Z]+$/); # skip BEGIN, DESTROY, etc.
*auto_symbol = $value;
*existing_symbol = *{"${class}::$name"};
if(defined &auto_symbol && !defined &existing_symbol)
{
$Debug && warn "IMPORT $name INTO $new_class FROM $auto_helper_class\n";
*{"${new_class}::$name"} = \&auto_symbol;
}
}
}
no strict 'refs';
@{"${new_class}::ISA"} = ($class, $auto_helper_class);
bless $self, $new_class;
}
else
{
# Otherwise use the (apparently custom) metadata class
bless $self, $auto_helper_class;
}
}
# Cache value
$Rebless{$class,$auto_helper_class} = ref $self;
}
}
}
return 1;
}
sub map_record_method_key
{
my($self, $method) = (shift, shift);
if(@_)
{
return $self->{'map_record_method_key'}{$method} = shift;
}
return $self->{'map_record_method_key'}{$method};
}
sub column_undef_overrides_default
{
my($self) = shift;
if(@_)
{
return $self->{'column_undef_overrides_default'} = $_[0] ? 1 : 0;
}
return $self->{'column_undef_overrides_default'}
if(defined $self->{'column_undef_overrides_default'});
return $self->{'column_undef_overrides_default'} = ref($self)->default_column_undef_overrides_default;
}
1;
__END__
=head1 NAME
Rose::DB::Object::Metadata - Database object metadata.
=head1 SYNOPSIS
use Rose::DB::Object::Metadata;
$meta = Rose::DB::Object::Metadata->new(class => 'Product');
# ...or...
$meta = Rose::DB::Object::Metadata->for_class('Product');
#
# Auto-initialization
#
$meta->table('products'); # optional if class name ends with "::Product"
$meta->auto_initialize;
#
# ...or manual setup
#
$meta->setup
(
table => 'products',
columns =>
[
id => { type => 'int', primary_key => 1 },
name => { type => 'varchar', length => 255 },
description => { type => 'text' },
category_id => { type => 'int' },
status =>
{
type => 'varchar',
check_in => [ 'active', 'inactive' ],
default => 'inactive',
},
start_date => { type => 'datetime' },
end_date => { type => 'datetime' },
date_created => { type => 'timestamp', default => 'now' },
last_modified => { type => 'timestamp', default => 'now' },
],
unique_key => 'name',
foreign_keys =>
[
category =>
{
class => 'Category',
key_columns =>
{
category_id => 'id',
}
},
],
relationships =>
[
prices =>
{
type => 'one to many',
class => 'Price',
column_map => { id => 'id_product' },
},
],
);
#
# ...or even more verbose manual setup (old-style, not recommended)
#
$meta->table('products');
$meta->columns
(
id => { type => 'int', primary_key => 1 },
name => { type => 'varchar', length => 255 },
description => { type => 'text' },
category_id => { type => 'int' },
status =>
{
type => 'varchar',
check_in => [ 'active', 'inactive' ],
default => 'inactive',
},
start_date => { type => 'datetime' },
end_date => { type => 'datetime' },
date_created => { type => 'timestamp', default => 'now' },
last_modified => { type => 'timestamp', default => 'now' },
);
$meta->unique_key('name');
$meta->foreign_keys
(
category =>
{
class => 'Category',
key_columns =>
{
category_id => 'id',
}
},
);
$meta->relationships
(
prices =>
{
type => 'one to many',
class => 'Price',
column_map => { id => 'id_product' },
},
);
...
=head1 DESCRIPTION
L<Rose::DB::Object::Metadata> objects store information about a single table in a database: the name of the table, the names and types of columns, any foreign or unique keys, etc. These metadata objects are also responsible for supplying information to, and creating object methods for, the L<Rose::DB::Object>-derived objects to which they belong.
L<Rose::DB::Object::Metadata> objects also store information about the L<Rose::DB::Object>s that front the database tables they describe. What might normally be thought of as "class data" for the L<Rose::DB::Object> is stored in the metadata object instead, in order to keep the method namespace of the L<Rose::DB::Object>-derived class uncluttered.
L<Rose::DB::Object::Metadata> objects are per-class singletons; there is one L<Rose::DB::Object::Metadata> object for each L<Rose::DB::Object>-derived class. Metadata objects are almost never explicitly instantiated. Rather, there are automatically created and accessed through L<Rose::DB::Object>-derived objects' L<meta|Rose::DB::Object/meta> method.
Once created, metadata objects can be populated manually or automatically. Both techniques are shown in the L<synopsis|/SYNOPSIS> above. The automatic mode works by asking the database itself for the information. There are some caveats to this approach. See the L<auto-initialization|/"AUTO-INITIALIZATION"> section for more information.
L<Rose::DB::Object::Metadata> objects contain three categories of objects that are responsible for creating object methods in L<Rose::DB::Object>-derived classes: columns, foreign keys, and relationships.
Column objects are subclasses of L<Rose::DB::Object::Metadata::Column>. They are intended to store as much information as possible about each column. The particular class of the column object created for a database column is determined by a L<mapping table|/column_type_classes>. The column class, in turn, is responsible for creating the accessor/mutator method(s) for the column. When it creates these methods, the column class can use (or ignore) any information stored in the column object.
Foreign key objects are of the class L<Rose::DB::Object::Metadata::ForeignKey>. They store information about columns that refer to columns in other tables that are fronted by their own L<Rose::DB::Object>-derived classes. A foreign key object is responsible for creating accessor method(s) to fetch the foreign object from the foreign table.
Relationship objects are subclasses of L<Rose::DB::Object::Metadata::Relationship>. They store information about a table's relationship to other tables that are fronted by their own L<Rose::DB::Object>-derived classes. The particular class of the relationship object created for each relationship is determined by a L<mapping table|/relationship_type_classes>. A relationship object is responsible for creating accessor method(s) to fetch the foreign objects from the foreign table.
=head1 AUTO-INITIALIZATION
Manual population of metadata objects can be tedious and repetitive. Nearly all of the information stored in a L<Rose::DB::Object::Metadata> object exists in the database in some form. It's reasonable to consider simply extracting this information from the database itself, rather than entering it all manually. This automatic metadata extraction and subsequent L<Rose::DB::Object::Metadata> object population is called "auto-initialization."
The example of auto-initialization in the L<synopsis|/SYNOPSIS> above is the most succinct variant:
$meta->auto_initialize;
As you can read in the documentation for the L<auto_initialize|/auto_initialize> method, that's shorthand for individually auto-initializing each part of the metadata object: columns, the primary key, unique keys, and foreign keys. But this brevity comes at a price. There are many caveats to auto-initialization.
=head2 Caveats
=head3 Start-Up Cost
In order to retrieve the information required for auto-initialization, a database connection must be opened and queries must be run. Sometimes these queries include complex joins. All of these queries must be successfully completed before the L<Rose::DB::Object>-derived objects that the L<Rose::DB::Object::Metadata> is associated with can be used.
In an environment like L<mod_perl>, server start-up time is precisely when you want to do any expensive operations. But in a command-line script or other short-lived process, the overhead of auto-initializing many metadata objects may become prohibitive.
Also, don't forget that auto-initialization requires a database connection. L<Rose::DB::Object>-derived objects can sometimes be useful even without a database connection (e.g., to temporarily store information that will never go into the database, or to synthesize data using object methods that have no corresponding database column). When using auto-initialization, this is not possible because the L<Rose::DB::Object>-derived class won't even load if auto-initialization fails because it could not connect to the database.
=head3 Detail
First, auto-initialization cannot generate information that exists only in the mind of the programmer. The most common example is a relationship between two database tables that is either ambiguous or totally unexpressed by the database itself.
For example, if a foreign key constraint does not exist, the relationship between rows in two different tables cannot be extracted from the database, and therefore cannot be auto-initialized.
Even within the realm of information that, by all rights, should be available in the database, there are limitations. Although there is a handy L<DBI> API for extracting metadata from databases, unfortunately, very few DBI drivers support it fully. Some don't support it at all. In almost all cases, some manual work is required to (often painfully) extract information from the database's "system tables" or "catalog."
More troublingly, databases do not always provide all the metadata that a human could extract from the series of SQL statement that created the table in the first place. Sometimes, the information just isn't in the database to be extracted, having been lost in the process of table creation. Here's just one example. Consider this MySQL table definition:
CREATE TABLE mytable
(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
code CHAR(6),
flag BOOLEAN NOT NULL DEFAULT 1,
bits BIT(5) NOT NULL DEFAULT '00101',
name VARCHAR(64)
);
Now look at the metadata that MySQL 4 stores internally for this table:
mysql> describe mytable;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | | PRI | NULL | auto_increment |
| code | varchar(6) | YES | | NULL | |
| flag | tinyint(1) | | | 1 | |
| bits | tinyint(1) | | | 101 | |
| name | varchar(64) | YES | | NULL | |
+-------+------------------+------+-----+---------+----------------+
Note the following divergences from the "CREATE TABLE" statement.
=over 4
=item * B<The "code" column has changed from CHAR(6) to VARCHAR(6).> This is troublesome if you want the traditional semantics of a CHAR type, namely the padding with spaces of values that are less than the column length.
=item * B<The "flag" column has changed from BOOLEAN to TINYINT(1).> The default accessor method created for boolean columns has value coercion and formatting properties that are important to this data type. The default accessor created for integer columns lacks these constraints. The metadata object has no way of knowing that "flag" was supposed to be a boolean column, and thus makes the wrong kind of accessor method. It is thus possible to store, say, a value of "7" in the "flag" column. Oops.
=item * B<The "bits" column has changed from BIT(5) to TINYINT(1).> As in the case of the "flag" column above, this type change prevents the correct accessor method from being created. The default bitfield accessor method auto-inflates column values into L<Bit::Vector> objects, which provide convenient methods for bit manipulation. The default accessor created for integer columns does no such thing.
=back
Remember that the auto-initialization process can only consider the metadata actually stored in the database. It has no access to the original "create table" statement. Thus, the semantics implied by the original table definition are effectively lost.
Again, this is just one example of the kind of detail that can be lost in the process of converting your table definition into metadata that is stored in the database. Admittedly, MySQL is perhaps the worst case-scenario, having a well-deserved reputation for disregarding the wishes of table definitions. (The use of implicit default values for "NOT NULL" columns is yet another example.)
Thankfully, there is a solution to this dilemma. Remember that auto-initialization is actually a multi-step process hiding behind that single call to the L<auto_initialize|/auto_initialize> method. To correct the sins of the database, simply break the auto-initialization process into its components. For example, here's how to correctly auto-initialize the "mytable" example above:
# Make a first pass at column setup
$meta->auto_init_columns;
# Account for inaccuracies in DBD::mysql's column info by
# replacing incorrect column definitions with new ones.
# Fix CHAR(6) column that shows up as VARCHAR(6)
$meta->column(code => { type => 'char', length => 6 });
# Fix BIT(5) column that shows up as TINYINT(1)
$meta->column(bits => { type => 'bits', bits => 5, default => 101 });
# Fix BOOLEAN column that shows up as TINYINT(1)
$meta->column(flag => { type => 'boolean', default => 1 });
# Do everything else
$meta->auto_initialize;
Note that L<auto_initialize|/auto_initialize> was called at the end. Without the C<replace_existing> parameter, this call will preserve any existing metadata, rather than overwriting it, so our "corrections" are safe.
=head3 Maintenance
The price of auto-initialization is eternal vigilance. "What does that mean? Isn't auto-initialization supposed to save time and effort?" Well, yes, but at a cost. In addition to the caveats described above, consider what happens when a table definition changes.
"Ah ha!" you say, "My existing class will automatically pick up the changes the next time it's loaded! Auto-initialization at its finest!" But is it? What if you added a "NOT NULL" column with no default value? Yes, your existing auto-initialized class will pick up the change, but your existing code will no longer be able to L<save|Rose::DB::Object/save> one these objects. Or what if you're using MySQL and your newly added column is one of the types described above that requires manual tweaking in order to get the desired semantics. Will you always remember to make this change?
Auto-initialization is not a panacea. Every time you make a change to your database schema, you must also revisit each affected L<Rose::DB::Object>-derived class to at least consider whether or not the metadata needs to be corrected or updated.
The trade-off may be well worth it, but it's still something to think about. There is, however, a hybrid solution that might be even better. Continue on to the next section to learn more.
=head2 Code Generation
As described in the L<section above|/Caveats>, auto-initializing metadata at runtime by querying the database has many caveats. An alternate approach is to query the database for metadata just once, and then generate the equivalent Perl code which can be pasted directly into the class definition in place of the call to L<auto_initialize|/auto_initialize>.
Like the auto-initialization process itself, perl code generation has a convenient wrapper method as well as separate methods for the individual parts. All of the perl code generation methods begin with "perl_", and they support some rudimentary code formatting options to help the code conform to you preferred style. Examples can be found with the documentation for each perl_* method.
This hybrid approach to metadata population strikes a good balance between upfront effort and ongoing maintenance. Auto-generating the Perl code for the initial class definition saves a lot of tedious typing. From that point on, manually correcting and maintaining the definition is a small price to pay for the decreased start-up cost, the ability to use the class in the absence of a database connection, and the piece of mind that comes from knowing that your class is stable, and won't change behind your back in response to an "action at a distance" (i.e., a database schema update).
=head1 CLASS METHODS
=over 4
=item B<auto_prime_caches [BOOL]>
Get or set a boolean value that indicates whether or not the L<prime_caches|/prime_caches> method will be called from within the L<initialize|/initialize> method. The default is true if the C<MOD_PERL> environment variable (C<$ENV{'MOD_PERL'}>) is set to a true value, false otherwise.
=item B<clear_all_dbs>
Clears the L<db|/db> attribute of the metadata object for each L<registered class|/registered_classes>.
=item B<column_type_class TYPE [, CLASS]>
Given the column type string TYPE, return the name of the L<Rose::DB::Object::Metadata::Column>-derived class used to store metadata and create the accessor method(s) for columns of that type. If a CLASS is passed, the column type TYPE is mapped to CLASS. In both cases, the TYPE argument is automatically converted to lowercase.
=item B<column_type_classes [MAP]>
Get or set the hash that maps column type strings to the names of the L<Rose::DB::Object::Metadata::Column>-derived classes used to store metadata and create accessor method(s) for columns of that type.
This hash is class data. If you want to modify it, I suggest making your own subclass of L<Rose::DB::Object::Metadata> and then setting that as the L<meta_class|Rose::DB::Object/meta_class> of your L<Rose::DB::Object> subclass.
If passed MAP (a list of type/class pairs or a reference to a hash of the same) then MAP replaces the current column type mapping. Returns a list of type/class pairs (in list context) or a reference to the hash of type/class mappings (in scalar context).
The default mapping of type names to class names is:
scalar => Rose::DB::Object::Metadata::Column::Scalar
char => Rose::DB::Object::Metadata::Column::Character
character => Rose::DB::Object::Metadata::Column::Character
varchar => Rose::DB::Object::Metadata::Column::Varchar
varchar2 => Rose::DB::Object::Metadata::Column::Varchar
nvarchar => Rose::DB::Object::Metadata::Column::Varchar
nvarchar2 => Rose::DB::Object::Metadata::Column::Varchar
string => Rose::DB::Object::Metadata::Column::Varchar
text => Rose::DB::Object::Metadata::Column::Text
blob => Rose::DB::Object::Metadata::Column::Blob
bytea => Rose::DB::Object::Metadata::Column::Pg::Bytea
bits => Rose::DB::Object::Metadata::Column::Bitfield
bitfield => Rose::DB::Object::Metadata::Column::Bitfield
bool => Rose::DB::Object::Metadata::Column::Boolean
boolean => Rose::DB::Object::Metadata::Column::Boolean
int => Rose::DB::Object::Metadata::Column::Integer
integer => Rose::DB::Object::Metadata::Column::Integer
tinyint => Rose::DB::Object::Metadata::Column::Integer
smallint => Rose::DB::Object::Metadata::Column::Integer
mediumint => Rose::DB::Object::Metadata::Column::Integer
bigint => Rose::DB::Object::Metadata::Column::BigInt
serial => Rose::DB::Object::Metadata::Column::Serial
bigserial => Rose::DB::Object::Metadata::Column::BigSerial
enum => Rose::DB::Object::Metadata::Column::Enum
num => Rose::DB::Object::Metadata::Column::Numeric
numeric => Rose::DB::Object::Metadata::Column::Numeric
decimal => Rose::DB::Object::Metadata::Column::Numeric
float => Rose::DB::Object::Metadata::Column::Float
float8 => Rose::DB::Object::Metadata::Column::DoublePrecision
'double precision' =>
Rose::DB::Object::Metadata::Column::DoublePrecision
time => Rose::DB::Object::Metadata::Column::Time
interval => Rose::DB::Object::Metadata::Column::Interval
date => Rose::DB::Object::Metadata::Column::Date
datetime => Rose::DB::Object::Metadata::Column::Datetime
timestamp => Rose::DB::Object::Metadata::Column::Timestamp
timestamptz =>
Rose::DB::Object::Metadata::Column::TimestampWithTimeZone
'timestamp with time zone' =>
Rose::DB::Object::Metadata::Column::TimestampWithTimeZone
'datetime year to fraction' =>
Rose::DB::Object::Metadata::Column::DatetimeYearToFraction
'datetime year to fraction(1)' =>
Rose::DB::Object::Metadata::Column::DatetimeYearToFraction1
'datetime year to fraction(2)' =>
Rose::DB::Object::Metadata::Column::DatetimeYearToFraction2
'datetime year to fraction(3)' =>
Rose::DB::Object::Metadata::Column::DatetimeYearToFraction3
'datetime year to fraction(4)' =>
Rose::DB::Object::Metadata::Column::DatetimeYearToFraction4
'datetime year to fraction(5)' =>
Rose::DB::Object::Metadata::Column::DatetimeYearToFraction5
'timestamp with time zone' =>
Rose::DB::Object::Metadata::Column::Timestamp
'timestamp without time zone' =>
Rose::DB::Object::Metadata::Column::Timestamp
'datetime year to second' =>
Rose::DB::Object::Metadata::Column::DatetimeYearToSecond
'datetime year to minute' =>
Rose::DB::Object::Metadata::Column::DatetimeYearToMinute
'datetime year to month' =>
Rose::DB::Object::Metadata::Column::DatetimeYearToMonth
'epoch' => Rose::DB::Object::Metadata::Column::Epoch
'epoch hires' => Rose::DB::Object::Metadata::Column::Epoch::HiRes
array => Rose::DB::Object::Metadata::Column::Array
set => Rose::DB::Object::Metadata::Column::Set
chkpass => Rose::DB::Object::Metadata::Column::Pg::Chkpass
=item B<column_type_names>
Returns the list (in list context) or reference to an array (in scalar context) of registered column type names.
=item B<convention_manager_class NAME [, CLASS]>
Given the string NAME, return the name of the L<Rose::DB::Object::ConventionManager>-derived class L<mapped|/convention_manager_classes> to that name.
If a CLASS is passed, then NAME is mapped to CLASS.
=item B<convention_manager_classes [MAP]>
Get or set the hash that maps names to L<Rose::DB::Object::ConventionManager>-derived class names.
This hash is class data. If you want to modify it, I suggest making your own subclass of L<Rose::DB::Object::Metadata> and then setting that as the L<meta_class|Rose::DB::Object/meta_class> of your L<Rose::DB::Object> subclass.
If passed MAP (a list of name/class pairs or a reference to a hash of the same) then MAP replaces the current mapping. Returns a list of name/class pairs (in list context) or a reference to the hash of name/class mappings (in scalar context).
The default mapping of names to classes is:
default => Rose::DB::Object::ConventionManager
null => Rose::DB::Object::ConventionManager::Null
=item B<dbi_prepare_cached [BOOL]>
Get or set a boolean value that indicates whether or not the L<Rose::DB::Object>-derived L<class|/class> will use L<DBI>'s L<prepare_cached|DBI/prepare_cached> method by default (instead of the L<prepare|DBI/prepare> method) when L<loading|Rose::DB::Object/load>, L<saving|Rose::DB::Object/save>, and L<deleting|Rose::DB::Object/delete> objects. The default value is true.
=item B<default_column_undef_overrides_default [BOOL]>
Get or set the default value of the L<column_undef_overrides_default|/column_undef_overrides_default> attribute. Defaults to undef.
=item B<default_manager_base_class [CLASS]>
Get or set the default name of the base class used by this metadata class when generating a L<manager|Rose::DB::Object::Manager> classes. The default value is C<Rose::DB::Object::Manager>. See the C<default_manager_base_class()> L<object method|/OBJECT METHODS> to override this value for a specific metadata object.
=item B<for_class CLASS>
Returns (or creates, if needed) the single L<Rose::DB::Object::Metadata> object associated with CLASS, where CLASS is the name of a L<Rose::DB::Object>-derived class.
=item B<init_column_name_to_method_name_mapper>
This class method should return a reference to a subroutine that maps column names to method names, or false if it does not want to do any custom mapping. The default implementation returns zero (0).
If defined, the subroutine should take four arguments: the metadata object, the column name, the column method type, and the method name that would be used if the mapper subroutine did not exist. It should return a method name.
=item B<prime_all_caches [PARAMS]>
Call L<prime_caches|/prime_caches> on all L<registered_classes|/registered_classes>, passing PARAMS to each call. PARAMS are name/value pairs. Valid parameters are:
=over 4
=item B<db DB>
A L<Rose::DB>-derived object used to determine which data source the cached metadata will be generated on behalf of. (Each data source has its own set of cached metadata.) This parameter is optional. If it is not passed, then the L<Rose::DB>-derived object returned by the L<init_db|Rose::DB::Object/init_db> method for each L<class|/class> will be used instead.
=back
=item B<relationship_type_class TYPE>
Given the relationship type string TYPE, return the name of the L<Rose::DB::Object::Metadata::Relationship>-derived class used to store metadata and create the accessor method(s) for relationships of that type.
=item B<relationship_type_classes [MAP]>
Get or set the hash that maps relationship type strings to the names of the L<Rose::DB::Object::Metadata::Relationship>-derived classes used to store metadata and create object methods fetch and/or manipulate objects from foreign tables.
This hash is class data. If you want to modify it, I suggest making your own subclass of L<Rose::DB::Object::Metadata> and then setting that as the L<meta_class|Rose::DB::Object/meta_class> of your L<Rose::DB::Object> subclass.
If passed MAP (a list of type/class pairs or a reference to a hash of the same) then MAP replaces the current relationship type mapping. Returns a list of type/class pairs (in list context) or a reference to the hash of type/class mappings (in scalar context).
The default mapping of type names to class names is:
'one to one' => Rose::DB::Object::Metadata::Relationship::OneToOne
'one to many' => Rose::DB::Object::Metadata::Relationship::OneToMany
'many to one' => Rose::DB::Object::Metadata::Relationship::ManyToOne
'many to many' => Rose::DB::Object::Metadata::Relationship::ManyToMany
=item B<registered_classes>
Return a list (in list context) or reference to an array (in scalar context) of the names of all L<Rose::DB::Object>-derived classes registered under this metadata class's L<registry_key|/registry_key>.
=item B<registry_key>
Returns the string used to group L<Rose::DB::Object>-derived class names in the class registry. The default is "Rose::DB::Object::Metadata".
=back
=head1 CONSTRUCTOR
=over 4
=item B<new PARAMS>
Returns (or creates, if needed) the single L<Rose::DB::Object::Metadata> associated with a particular L<Rose::DB::Object>-derived class, modifying or initializing it according to PARAMS, where PARAMS are name/value pairs.
Any object method is a valid parameter name, but PARAMS I<must> include a value for the C<class> parameter, since that's how L<Rose::DB::Object::Metadata> objects are mapped to their corresponding L<Rose::DB::Object>-derived class.
=back
=head1 OBJECT METHODS
=over 4
=item B<add_column ARGS>
This is an alias for the L<add_columns|/add_columns> method.
=item B<add_columns ARGS>
Add the columns specified by ARGS to the list of columns for the table. Returns the list of columns added in list context, or a reference to an array of columns added in scalar context. Columns can be specified in ARGS in several ways.
If an argument is a subclass of L<Rose::DB::Object::Metadata::Column>, it is added as-is.
If an argument is a plain scalar, it is taken as the name of a scalar column. A column object of the class returned by the method call C<$obj-E<gt>column_type_class('scalar')> is constructed and then added.
Otherwise, only name/value pairs are considered, where the name is taken as the column name and the value must be a reference to a hash.
If the hash contains the key "primary_key" with a true value, then the column is marked as a L<primary_key_member|Rose::DB::Object::Metadata::Column/is_primary_key_member> and the column name is added to the list of primary key columns by calling the L<add_primary_key_column|/add_primary_key_column> method with the column name as its argument.
If the hash contains the key "alias", then the value of that key is used as the alias for the column. This is a shorthand equivalent to explicitly calling the L<alias_column|/alias_column> column method.
If the hash contains the key "temp" and its value is true, then the column is actually added to the list of L<non-persistent columns|/nonpersistent_columns>.
If the hash contains a key with the same name as a L<column trigger event type|Rose::DB::Object::Metadata::Column/TRIGGERS> (e.g., "on_set", "on_load", "inflate") then the value of that key must be a code reference or a reference to an array of code references, which will be L<added|Rose::DB::Object::Metadata::Column/add_trigger> to the list of the column's L<triggers|Rose::DB::Object::Metadata::Column/TRIGGERS> for the specified event type.
If the hash contains the key "methods", then its value must be a reference to an array or a reference to a hash. The L<auto_method_types|Rose::DB::Object::Metadata::Column/auto_method_types> of the column are then set to the values of the referenced array, or the keys of the referenced hash. The values of the referenced hash are used to set the L<method_name|Rose::DB::Object::Metadata::Column/method_name> for their corresponding method types.
If the hash contains the key "add_methods", then its value must be a reference to an array or a reference to a hash. The values of the referenced array or the keys of the referenced hash are added to the column's L<auto_method_types|Rose::DB::Object::Metadata::Column/auto_method_types>. The values of the referenced hash are used to set the L<method_name|Rose::DB::Object::Metadata::Column/method_name> for their corresponding method types.
If the "methods" and "add_methods" keys are both set, a fatal error will occur.
Then the L<column_type_class|/column_type_class> method is called with the value of the "type" hash key as its argument (or "scalar" if that key is missing), returning the name of a column class. Finally, a new column object of that class is constructed and is passed all the remaining pairs in the hash reference, along with the name and type of the column. That column object is then added to the list of columns.
This is done until there are no more arguments to be processed, or until an argument does not conform to one of the required formats, in which case a fatal error occurs.
Example:
$meta->add_columns
(
# Add a scalar column
'name',
# which is roughly equivalent to:
#
# $class = $meta->column_type_class('scalar');
# $col = $class->new(name => 'name');
# (then add $col to the list of columns)
# Add by name/hashref pair with explicit method types
age => { type => 'int', default => 5, methods => [ 'get', 'set' ] },
# which is roughly equivalent to:
#
# $class = $meta->column_type_class('int');
# $col = $class->new(name => 'age',
# type => 'int',
# default => 5);
# $col->auto_method_types('get', 'set');
# (then add $col to the list of columns)
# Add by name/hashref pair with additional method type and name
size => { type => 'int', add_methods => { 'set' => 'set_my_size' } },
# which is roughly equivalent to:
#
# $class = $meta->column_type_class('int');
# $col = $class->new(name => 'size',
# type => 'int',);
# $col->add_auto_method_types('set');
# $col->method_name(set => 'set_my_size');
# (then add $col to the list of columns)
# Add a column object directly
Rose::DB::Object::Metadata::Column::Date->new(
name => 'start_date'),
);
=item B<add_nonpersistent_column ARGS>
This is an alias for the L<add_nonpersistent_columns|/add_nonpersistent_columns> method.
=item B<add_nonpersistent_columns ARGS>
This method behaves like the L<add_columns|/add_columns> method, except that it adds to the list of L<non-persistent columns|/nonpersistent_columns>. See the documentation for the L<nonpersistent_columns|/nonpersistent_columns> method for more information.
=item B<add_foreign_keys ARGS>
Add foreign keys as specified by ARGS. Each foreign key must have a L<name|Rose::DB::Object::Metadata::ForeignKey/name> that is unique among all other foreign keys in this L<class|/class>.
Foreign keys can be specified in ARGS in several ways.
If an argument is a L<Rose::DB::Object::Metadata::ForeignKey> object (or subclass thereof), it is added as-is.
Otherwise, only name/value pairs are considered, where the name is taken as the foreign key name and the value must be a reference to a hash.
If the hash contains the key "methods", then its value must be a reference to an array or a reference to a hash. The L<auto_method_types|Rose::DB::Object::Metadata::ForeignKey/auto_method_types> of the foreign key are then set to the values of the referenced array, or the keys of the referenced hash. The values of the referenced hash are used to set the L<method_name|Rose::DB::Object::Metadata::ForeignKey/method_name> for their corresponding method types.
If the hash contains the key "add_methods", then its value must be a reference to an array or a reference to a hash. The values of the referenced array or the keys of the referenced hash are added to the foreign key's L<auto_method_types|Rose::DB::Object::Metadata::ForeignKey/auto_method_types>. The values of the referenced hash are used to set the L<method_name|Rose::DB::Object::Metadata::ForeignKey/method_name> for their corresponding method types.
If the "methods" and "add_methods" keys are both set, a fatal error will occur.
A new L<Rose::DB::Object::Metadata::ForeignKey> object is constructed and is passed all the remaining pairs in the hash reference, along with the name of the foreign key as the value of the "name" parameter. That foreign key object is then added to the list of foreign keys.
This is done until there are no more arguments to be processed, or until an argument does not conform to one of the required formats, in which case a fatal error occurs.
Example:
$meta->add_foreign_keys
(
# Add by name/hashref pair with explicit method type
category =>
{
class => 'Category',
key_columns => { category_id => 'id' },
methods => [ 'get' ],
},
# which is roughly equivalent to:
#
# $fk = Rose::DB::Object::Metadata::ForeignKey->new(
# class => 'Category',
# key_columns => { category_id => 'id' },
# name => 'category');
# $fk->auto_method_types('get');
# (then add $fk to the list of foreign keys)
# Add by name/hashref pair with additional method type and name
color =>
{
class => 'Color',
key_columns => { color_id => 'id' },
add_methods => { set => 'set_my_color' },
},
# which is roughly equivalent to:
#
# $fk = Rose::DB::Object::Metadata::ForeignKey->new(
# class => 'Color',
# key_columns => { color_id => 'id' },
# name => 'color');
# $fk->add_auto_method_types('set');
# $fk->method_name(set => 'set_my_color');
# (then add $fk to the list of foreign keys)
# Add a foreign key object directly
Rose::DB::Object::Metadata::ForeignKey->new(...),
);
For each foreign key added, a corresponding relationship with the same name is added if it does not already exist. The relationship type is determined by the value of the foreign key object's L<relationship|Rose::DB::Object::Metadata::ForeignKey/relationship_type> attribute. The default is "many to one". The class of the relationship is chosen by calling L<relationship_type_class|/relationship_type_class> with the relationship type as an argument.
=item B<add_primary_key_column COLUMN>
This method is an alias for L<add_primary_key_columns|/add_primary_key_columns>.
=item B<add_primary_key_columns COLUMNS>
Add COLUMNS to the list of columns that make up the primary key. COLUMNS can be a list or reference to an array of column names.
=item B<add_relationship ARGS>
This is an alias for the L<add_relationships|/add_relationships> method.
=item B<add_relationships ARGS>
Add relationships as specified by ARGS. Each relationship must have a L<name|Rose::DB::Object::Metadata::Relationship/name> that is unique among all other relationships in this L<class|/class>.
Relationships can be specified in ARGS in several ways.
If an argument is a subclass of L<Rose::DB::Object::Metadata::Relationship>, it is added as-is.
Otherwise, only name/value pairs are considered, where the name is taken as the relationship name and the value must be a reference to a hash.
If the hash contains the key "methods", then its value must be a reference to an array or a reference to a hash. The L<auto_method_types|Rose::DB::Object::Metadata::Relationship/auto_method_types> of the relationship are then set to the values of the referenced array, or the keys of the referenced hash. The values of the referenced hash are used to set the L<method_name|Rose::DB::Object::Metadata::Relationship/method_name> for their corresponding method types.
If the hash contains the key "add_methods", then its value must be a reference to an array or a reference to a hash. The values of the referenced array or the keys of the referenced hash are added to the relationship's L<auto_method_types|Rose::DB::Object::Metadata::Relationship/auto_method_types>. The values of the referenced hash are used to set the L<method_name|Rose::DB::Object::Metadata::Relationship/method_name> for their corresponding method types.
If the "methods" and "add_methods" keys are both set, a fatal error will occur.
Then the L<relationship_type_class|/relationship_type_class> method is called with the value of the C<type> hash key as its argument, returning the name of a relationship class.
Finally, a new relationship object of that class is constructed and is passed all the remaining pairs in the hash reference, along with the name and type of the relationship. That relationship object is then added to the list of relationships.
This is done until there are no more arguments to be processed, or until an argument does not conform to one of the required formats, in which case a fatal error occurs.
Example:
$meta->add_relationships
(
# Add by name/hashref pair with explicit method type
category =>
{
type => 'many to one',
class => 'Category',
column_map => { category_id => 'id' },
methods => [ 'get' ],
},
# which is roughly equivalent to:
#
# $class = $meta->relationship_type_class('many to one');
# $rel = $class->new(class => 'Category',
# column_map => { category_id => 'id' },
# name => 'category');
# $rel->auto_method_types('get');
# (then add $rel to the list of relationships)
# Add by name/hashref pair with additional method type and name
color =>
{
type => 'many to one',
class => 'Color',
column_map => { color_id => 'id' },
add_methods => { set => 'set_my_color' },
},
# which is roughly equivalent to:
#
# $class = $meta->relationship_type_class('many to one');
# $rel = $class->new(class => 'Color',
# column_map => { color_id => 'id' },
# name => 'color');
# $rel->add_auto_method_types('set');
# $fk->method_name(set => 'set_my_color');
# (rel add $fk to the list of foreign keys)
# Add a relationship object directly
Rose::DB::Object::Metadata::Relationship::OneToOne->new(...),
);
=item B<add_unique_key KEY>
This method is an alias for L<add_unique_keys|/add_unique_keys>.
=item B<add_unique_keys KEYS>
Add new unique keys specified by KEYS. Unique keys can be specified in KEYS in two ways.
If an argument is a L<Rose::DB::Object::Metadata::UniqueKey> object (or subclass thereof), then its L<parent|Rose::DB::Object::Metadata::UniqueKey/parent> is set to the metadata object itself, and it is added.
Otherwise, an argument must be a single column name or a reference to an array of column names that make up a unique key. A new L<Rose::DB::Object::Metadata::UniqueKey> is created, with its L<parent|Rose::DB::Object::Metadata::UniqueKey/parent> set to the metadata object itself, and then the unique key object is added to this list of unique keys for this L<class|/class>.
=item B<alias_column NAME, ALIAS>
Set the L<alias|Rose::DB::Object::Metadata::Column/alias> for the column named NAME to ALIAS. It is sometimes necessary to use an alias for a column because the column name conflicts with an existing L<Rose::DB::Object> method name.
For example, imagine a column named "save". The L<Rose::DB::Object> API already defines a method named L<save|Rose::DB::Object/save>, so obviously that name can't be used for the accessor method for the "save" column. To solve this, make an alias:
$meta->alias_column(save => 'save_flag');
See the L<Rose::DB::Object> documentation or call the L<method_name_is_reserved|/method_name_is_reserved> method to determine if a method name is reserved.
=item B<allow_inline_column_values [BOOL]>
Get or set the boolean flag that indicates whether or not the associated L<Rose::DB::Object>-derived class should try to inline column values that L<DBI> does not handle correctly when they are bound to placeholders using L<bind_columns|DBI/bind_columns>. The default value is false.
Enabling this flag reduces the performance of the L<update|Rose::DB::Object/update> and L<insert|Rose::DB::Object/insert> operations on the L<Rose::DB::Object>-derived object. But it is sometimes necessary to enable the flag because some L<DBI> drivers do not (or cannot) always do the right thing when binding values to placeholders in SQL statements. For example, consider the following SQL for the Informix database:
CREATE TABLE test (d DATETIME YEAR TO SECOND);
INSERT INTO test (d) VALUES (CURRENT);
This is valid Informix SQL and will insert a row with the current date and time into the "test" table.
Now consider the following attempt to do the same thing using L<DBI> placeholders (assume the table was already created as per the CREATE TABLE statement above):
$sth = $dbh->prepare('INSERT INTO test (d) VALUES (?)');
$sth->execute('CURRENT'); # Error!
What you'll end up with is an error like this:
DBD::Informix::st execute failed: SQL: -1262: Non-numeric
character in datetime or interval.
In other words, L<DBD::Informix> has tried to quote the string "CURRENT", which has special meaning to Informix only when it is not quoted.
In order to make this work, the value "CURRENT" must be "inlined" rather than bound to a placeholder when it is the value of a "DATETIME YEAR TO SECOND" column in an Informix database.
=item B<auto_load_related_classes [BOOL]>
Get or set a flag that indicates whether or not classes related to this L<class|/class> through a L<foreign key|/foreign_keys> or other L<relationship|/relationships> will be automatically loaded when this L<class|/class> is L<initialize|/initialize>d. The default value is true.
=item B<cached_objects_expire_in [DURATION]>
This method is only applicable if this metadata object is associated with a L<Rose::DB::Object::Cached>-derived class. It simply calls the class method of the same name that belongs to the L<Rose::DB::Object::Cached>-derived L<class|/class> associated with this metadata object.
=item B<catalog [CATALOG]>
Get or set the database catalog for this L<class|/class>. This setting will B<override> any L<setting|Rose::DB/catalog> in the L<db|Rose::DB::Object/db> object. Use this method only if you know that the L<class|/class> will always point to a specific catalog, regardless of what the L<Rose::DB>-derived database handle object specifies.
=item B<class [CLASS]>
Get or set the L<Rose::DB::Object>-derived class associated with this metadata object. This is the class where the accessor methods for each column will be created (by L<make_methods|/make_methods>).
=item B<class_for PARAMS>
Returns the name of the L<Rose::DB::Object>-derived class associated with the C<catalog>, C<schema>, and C<table> specified by the name/value paris in PARAMS. Catalog and/or schema maybe omitted if unknown or inapplicable, and the "best" match will be returned. Returns undef if there is no class name registered under the specified PARAMS.
Note: This method may also be called as a class method, but may require explicit C<catalog> and/or C<schema> arguments when dealing with databases that support these concepts I<and> have default implicit values for them.
=item B<clear_object_cache>
This method is only applicable if this metadata object is associated with a L<Rose::DB::Object::Cached>-derived class. It simply calls the class method of the same name that belongs to the L<Rose::DB::Object::Cached>-derived L<class|/class> associated with this metadata object.
=item B<column NAME [, COLUMN | HASHREF]>
Get or set the column named NAME. If just NAME is passed, the L<Rose::DB::Object::Metadata::Column>-derived column object for the column of that name is returned. If no such column exists, undef is returned.
If both NAME and COLUMN are passed, then COLUMN must be a L<Rose::DB::Object::Metadata::Column>-derived object. COLUMN has its L<name|Rose::DB::Object::Metadata::Column/name> set to NAME, and is then stored as the column metadata object for NAME, replacing any existing column.
If both NAME and HASHREF are passed, then the combination of NAME and HASHREF must form a name/value pair suitable for passing to the L<add_columns|/add_columns> method. The new column specified by NAME and HASHREF replaces any existing column.
=item B<columns [ARGS]>
Get or set the full list of columns. If ARGS are passed, the column list is cleared and then ARGS are passed to the L<add_columns|/add_columns> method.
Returns a list of column objects in list context, or a reference to an array of column objects in scalar context.
=item B<column_accessor_method_name NAME>
Returns the name of the "get" method for the column named NAME. This is just a shortcut for C<$meta-E<gt>column(NAME)-E<gt>accessor_method_name>.
=item B<column_accessor_method_names>
Returns a list (in list context) or a reference to the array (in scalar context) of the names of the "set" methods for all the columns, in the order that the columns are returned by L<column_names|/column_names>.
=item B<column_aliases [MAP]>
Get or set the hash that maps column names to their aliases. If passed MAP (a list of name/value pairs or a reference to a hash) then MAP replaces the current alias mapping. Returns a reference to the hash that maps column names to their aliases.
Note that modifying this map has no effect if L<initialize|/initialize>, L<make_methods|/make_methods>, or L<make_column_methods|/make_column_methods> has already been called for the current L<class|/class>.
=item B<column_mutator_method_name NAME>
Returns the name of the "set" method for the column named NAME. This is just a shortcut for C<$meta-E<gt>column(NAME)-E<gt>mutator_method_name>.
=item B<column_mutator_method_names>
Returns a list (in list context) or a reference to the array (in scalar context) of the names of the "set" methods for all the columns, in the order that the columns are returned by L<column_names|/column_names>.
=item B<column_names>
Returns a list (in list context) or a reference to an array (in scalar context) of column names.
=item B<column_name_to_method_name_mapper [CODEREF]>
Get or set the code reference to the subroutine used to map column names to method names. If undefined, then the L<init_column_name_to_method_name_mapper|/init_column_name_to_method_name_mapper> class method is called in order to initialize it. If still undefined or false, then the "default" method name is used.
If defined, the subroutine should take four arguments: the metadata object, the column name, the column method type, and the method name that would be used if the mapper subroutine did not exist. It should return a method name.
=item B<column_rw_method_name NAME>
Returns the name of the "get_set" method for the column named NAME. This is just a shortcut for C<$meta-E<gt>column(NAME)-E<gt>rw_method_name>.
=item B<column_rw_method_names>
Returns a list (in list context) or a reference to the array (in scalar context) of the names of the "get_set" methods for all the columns, in the order that the columns are returned by L<column_names|/column_names>.
=item B<column_undef_overrides_default [BOOL]>
Get or set a boolean value that influences the default value of the L<undef_overrides_default|Rose::DB::Object::Metadata::Column/undef_overrides_default> attribute for each L<column|/columns> in this L<class|/class>. See the documentation for L<Rose::DB::Object::Metadata::Column>'s L<undef_overrides_default|Rose::DB::Object::Metadata::Column/undef_overrides_default> attribute for more information.
Defaults to the value returned by the L<default_column_undef_overrides_default|/default_column_undef_overrides_default> class method.
=item B<convention_manager [ OBJECT | CLASS | NAME ]>
Get or set the convention manager for this L<class|/class>. Defaults to the return value of the L<init_convention_manager|/init_convention_manager> method.
If undef is passed, then a L<Rose::DB::Object::ConventionManager::Null> object is stored instead.
If a L<Rose::DB::Object::ConventionManager>-derived object is passed, its L<meta|Rose::DB::Object::ConventionManager/meta> attribute set to this metadata object and then it is used as the convention manager for this L<class|/class>.
If a L<Rose::DB::Object::ConventionManager>-derived class name is passed, a new object of that class is created with its L<meta|Rose::DB::Object::ConventionManager/meta> attribute set to this metadata object. Then it is used as the convention manager for this L<class|/class>.
If a convention manager name is passed, then the corresponding class is looked up in the L<convention manager class map|convention_manager_classes>, a new object of that class is constructed, its L<meta|Rose::DB::Object::ConventionManager/meta> attribute set to this metadata object, and it is used as the convention manager for this L<class|/class>. If there is no class mapped to NAME, a fatal error will occur.
See the L<Rose::DB::Object::ConventionManager> documentation for more information on convention managers.
=item B<db>
Returns the L<Rose::DB>-derived object associated with this metadata object's L<class|/class>. A fatal error will occur if L<class|/class> is undefined or if the L<Rose::DB> object could not be created.
=item B<default_cascade_save [BOOL]>
Get or set a boolean value that indicates whether or not the L<class|/class> associated with this metadata object will L<save|Rose::DB::Object/save> related objects when the parent object is L<saved|Rose::DB::Object/save>. See the documentation for L<Rose::DB::Object>'s L<save()|Rose::DB::Object/save> method for details. The default value is false.
=item B<default_load_speculative [BOOL]>
Get or set a boolean value that indicates whether or not the L<class|/class> associated with this metadata object will L<load|Rose::DB::Object/load> speculatively by default. See the documentation for L<Rose::DB::Object>'s L<load()|Rose::DB::Object/load> method for details. The default value is false.
=item B<default_update_changes_only [BOOL]>
Get or set a boolean value that indicates whether or not the L<class|/class> associated with this metadata object will L<update|Rose::DB::Object/update> only an object's modified columns by default (instead of updating all columns). See the documentation for L<Rose::DB::Object>'s L<update()|Rose::DB::Object/update> method for details. The default value is false.
=item B<delete_column NAME>
Delete the column named NAME.
=item B<delete_columns>
Delete all of the L<columns|/columns>.
=item B<delete_column_type_class TYPE>
Delete the type/class L<mapping|/column_type_classes> entry for the column type TYPE.
=item B<delete_convention_manager_class NAME>
Delete the name/class L<mapping|/convention_manager_classes> entry for the convention manager class mapped to NAME.
=item B<delete_nonpersistent_column NAME>
Delete the L<non-persistent column|/nonpersistent_columns> named NAME.
=item B<delete_nonpersistent_columns>
Delete all of the L<nonpersistent_columns|/nonpersistent_columns>.
=item B<delete_relationship NAME>
Delete the relationship named NAME.
=item B<delete_relationships>
Delete all of the relationships.
=item B<delete_relationship_type_class TYPE>
Delete the type/class mapping entry for the relationship type TYPE.
=item B<delete_unique_keys>
Delete all of the unique key definitions.
=item B<error_mode [MODE]>
Get or set the error mode of the L<Rose::DB::Object> that fronts the table described by this L<Rose::DB::Object::Metadata> object. If the error mode is false, then it defaults to the return value of the C<init_error_mode> method, which is "fatal" by default.
The error mode determines what happens when a L<Rose::DB::Object> method encounters an error. The "return" error mode causes the methods to behave as described in the L<Rose::DB::Object> documentation. All other error modes cause an action to be performed before (possibly) returning as per the documentation (depending on whether or not the "action" is some variation on "throw an exception.")
Valid values of MODE are:
=over 4
=item carp
Call L<Carp::carp|Carp/carp> with the value of the object L<error|Rose::DB::Object/error> as an argument.
=item cluck
Call L<Carp::cluck|Carp/cluck> with the value of the object L<error|Rose::DB::Object/error> as an argument.
=item confess
Call L<Carp::confess|Carp/confess> with the value of the object L<error|Rose::DB::Object/error> as an argument.
=item croak
Call L<Carp::croak|Carp/croak> with the value of the object L<error|Rose::DB::Object/error> as an argument.
=item fatal
An alias for the "croak" mode.
=item return
Return a value that indicates that an error has occurred, as described in the L<documentation|Rose::DB::Object/"OBJECT METHODS"> for each method.
=back
In all cases, the object's L<error|Rose::DB::Object/error> attribute will also contain the error message.
=item B<first_column>
Returns the first column, determined by the order that columns were L<added|/add_columns>, or undef if there are no columns.
=item B<foreign_key NAME [, FOREIGNKEY | HASHREF ]>
Get or set the foreign key named NAME. NAME should be the name of the thing being referenced by the foreign key, I<not> the name of any of the columns that make up the foreign key. If called with just a NAME argument, the foreign key stored under that name is returned. Undef is returned if there is no such foreign key.
If both NAME and FOREIGNKEY are passed, then FOREIGNKEY must be a L<Rose::DB::Object::Metadata::ForeignKey>-derived object. FOREIGNKEY has its L<name|Rose::DB::Object::Metadata::ForeignKey/name> set to NAME, and is then stored, replacing any existing foreign key with the same name.
If both NAME and HASHREF are passed, then the combination of NAME and HASHREF must form a name/value pair suitable for passing to the L<add_foreign_keys|/add_foreign_keys> method. The new foreign key specified by NAME and HASHREF replaces any existing foreign key with the same name.
=item B<foreign_keys [ARGS]>
Get or set the full list of foreign keys. If ARGS are passed, the foreign key list is cleared and then ARGS are passed to the L<add_foreign_keys|/add_foreign_keys> method.
Returns a list of foreign key objects in list context, or a reference to an array of foreign key objects in scalar context.
=item B<generate_primary_key_value DB>
This method is the same as L<generate_primary_key_values|/generate_primary_key_values> except that it only returns the generated value for the first primary key column, rather than the entire list of values. Use this method only when there is a single primary key column (or not at all).
=item B<generate_primary_key_values DB>
Given the L<Rose::DB>-derived object DB, generate and return a list of new primary key column values for the table described by this metadata object.
If a L<primary_key_generator|/primary_key_generator> is defined, it will be called (passed this metadata object and the DB) and its value returned.
If no L<primary_key_generator|/primary_key_generator> is defined, new primary key values will be generated, if possible, using the native facilities of the current database. Note that this may not be possible for databases that auto-generate such values only after an insertion. In that case, undef will be returned.
=item B<include_predicated_unique_indexes [BOOL]>
Get or set a boolean value that indicates whether or not the L<auto_init_unique_keys|/auto_init_unique_keys> method will create L<unique keys|/add_unique_keys> for unique indexes that have predicates. The default value is false. This feature is currently only supported for PostgreSQL.
Here's an example of a unique index that has a predicate:
CREATE UNIQUE INDEX my_idx ON mytable (mycolumn) WHERE mycolumn > 123;
The predicate in this case is C<WHERE mycolumn E<gt> 123>.
Predicated unique indexes differ semantically from unpredicated unique indexes in that predicates generally cause the index to only apply to part of a table. L<Rose::DB::Object> expects L<unique indexes|Rose::DB::Object::Metadata::UniqueKey> to uniquely identify a row within a table. Predicated indexes that fail to do so due to their predicates should therefore not have L<Rose::DB::Object::Metadata::UniqueKey> objects created for them, thus the false default for this attribute.
=item B<init_convention_manager>
Returns the default L<Rose::DB::Object::ConventionManager>-derived object used as the L<convention manager|/convention_manager> for this L<class|/class>. This object will be of the class returned by L<convention_manager_class('default')|/convention_manager_class>.
Override this method in your L<Rose::DB::Object::Metadata> subclass, or L<re-map|/convention_manager_class> the "default" convention manager class, in order to use a different convention manager class. See the L<tips and tricks|Rose::DB::Object::ConventionManager/"TIPS AND TRICKS"> section of the L<Rose::DB::Object::ConventionManager> documentation for an example of the subclassing approach.
=item B<initialize [ARGS]>
Initialize the L<Rose::DB::Object>-derived class associated with this metadata object by creating accessor methods for each column and foreign key. The L<table|/table> name and the L<primary_key_columns|/primary_key_columns> must be defined or a fatal error will occur.
If any column name in the primary key or any of the unique keys does not exist in the list of L<columns|/columns>, then that primary or unique key is deleted. (As per the above, this will trigger a fatal error if any column in the primary key is not in the column list.)
ARGS, if any, are passed to the call to L<make_methods|/make_methods> that actually creates the methods.
If L<auto_prime_caches|/auto_prime_caches> is true, then the L<prime_caches|/prime_caches> method will be called at the end of the initialization process.
=item B<is_initialized [BOOL]>
Get or set a boolean value that indicates whether or not this L<class|/class> was L<initialize|/initialize>d. A successful call to the L<initialize|/initialize> method will automatically set this flag to true.
=item B<make_manager_class [PARAMS | CLASS]>
This method creates a L<Rose::DB::Object::Manager>-derived class to manage objects of this L<class|/class>. To do so, it simply calls L<perl_manager_class|/perl_manager_class>, passing all arguments, and then L<eval|perlfunc/eval>uates the result. See the L<perl_manager_class|/perl_manager_class> documentation for more information.
=item B<make_methods [ARGS]>
Create object methods in L<class|/class> for each L<column|/columns>, L<foreign key|/foreign_keys>, and L<relationship|/relationship>. This is done by calling L<make_column_methods|/make_column_methods>, L<make_nonpersistent_column_methods|/make_nonpersistent_column_methods>, L<make_foreign_key_methods|/make_foreign_key_methods>, and L<make_relationship_methods|/make_relationship_methods>, in that order.
ARGS are name/value pairs which are passed on to the other C<make_*_methods> calls. They are all optional. Valid ARGS are:
=over 4
=item * C<preserve_existing>
If set to a true value, a method will not be created if there is already an existing method with the same named.
=item * C<replace_existing>
If set to a true value, override any existing method with the same name.
=back
In the absence of one of these parameters, any method name that conflicts with an existing method name will cause a fatal error.
=item B<make_column_methods [ARGS]>
Create accessor/mutator methods in L<class|/class> for each L<column|/columns>. ARGS are name/value pairs, and are all optional. Valid ARGS are:
=over 4
=item * C<preserve_existing>
If set to a true value, a method will not be created if there is already an existing method with the same named.
=item * C<replace_existing>
If set to a true value, override any existing method with the same name.
=back
For each L<auto_method_type|Rose::DB::Object::Metadata::Column/auto_method_types> in each column, the method name is determined by passing the column name and the method type to L<method_name_from_column_name|/method_name_from_column_name>. If the resulting method name is reserved (according to L<method_name_is_reserved|/method_name_is_reserved>, a fatal error will occur. The object methods for each column are created by calling the column object's L<make_methods|Rose::DB::Object::Metadata::Column/make_methods> method.
=item B<make_foreign_key_methods [ARGS]>
Create object methods in L<class|/class> for each L<foreign key|/foreign_keys>. ARGS are name/value pairs, and are all optional. Valid ARGS are:
=over 4
=item * C<preserve_existing>
If set to a true value, a method will not be created if there is already an existing method with the same named.
=item * C<replace_existing>
If set to a true value, override any existing method with the same name.
=back
For each L<auto_method_type|Rose::DB::Object::Metadata::ForeignKey/auto_method_types> in each foreign key, the method name is determined by passing the method type to the L<method_name|Rose::DB::Object::Metadata::ForeignKey/method_name> method of the foreign key object, or the L<build_method_name_for_type|Rose::DB::Object::Metadata::ForeignKey/build_method_name_for_type> method if the L<method_name|Rose::DB::Object::Metadata::ForeignKey/method_name> call returns a false value. If the method name is reserved (according to L<method_name_is_reserved|/method_name_is_reserved>), a fatal error will occur. The object methods for each foreign key are created by calling the foreign key object's L<make_methods|Rose::DB::Object::Metadata::ForeignKey/make_methods> method.
Foreign keys and relationships with the L<type|Rose::DB::Object::Metadata::Relationship/type> "one to one" or "many to one" both encapsulate essentially the same information. They are kept in sync when this method is called by setting the L<foreign_key|Rose::DB::Object::Metadata::Relationship::ManyToOne/foreign_key> attribute of each "L<one to one|Rose::DB::Object::Metadata::Relationship::OneToOne>" or "L<many to one|Rose::DB::Object::Metadata::Relationship::ManyToOne>" relationship object to be the corresponding foreign key object.
=item B<make_nonpersistent_column_methods [ARGS]>
This method behaves like the L<make_column_methods|/make_column_methods> method, except that it works with L<non-persistent columns|/nonpersistent_columns>. See the documentation for the L<nonpersistent_columns|/nonpersistent_columns> method for more information on non-persistent columns.
=item B<make_relationship_methods [ARGS]>
Create object methods in L<class|/class> for each L<relationship|/relationships>. ARGS are name/value pairs, and are all optional. Valid ARGS are:
=over 4
=item * C<preserve_existing>
If set to a true value, a method will not be created if there is already an existing method with the same named.
=item * C<replace_existing>
If set to a true value, override any existing method with the same name.
=back
For each L<auto_method_type|Rose::DB::Object::Metadata::Relationship/auto_method_types> in each relationship, the method name is determined by passing the method type to the L<method_name|Rose::DB::Object::Metadata::Relationship/method_name> method of the relationship object, or the L<build_method_name_for_type|Rose::DB::Object::Metadata::Relationship/build_method_name_for_type> method if the L<method_name|Rose::DB::Object::Metadata::Relationship/method_name> call returns a false value. If the method name is reserved (according to L<method_name_is_reserved|/method_name_is_reserved>), a fatal error will occur. The object methods for each relationship are created by calling the relationship object's L<make_methods|Rose::DB::Object::Metadata::Relationship/make_methods> method.
Foreign keys and relationships with the L<type|Rose::DB::Object::Metadata::Relationship/type> "one to one" or "many to one" both encapsulate essentially the same information. They are kept in sync when this method is called by setting the L<foreign_key|Rose::DB::Object::Metadata::Relationship::ManyToOne/foreign_key> attribute of each "L<one to one|Rose::DB::Object::Metadata::Relationship::OneToOne>" or "L<many to one|Rose::DB::Object::Metadata::Relationship::ManyToOne>" relationship object to be the corresponding foreign key object.
If a relationship corresponds exactly to a foreign key, and that foreign key already made an object method, then the relationship is not asked to make its own method.
=item B<default_manager_base_class [CLASS]>
Get or set the default name of the base class used by this specific metadata object when generating a L<manager|Rose::DB::Object::Manager> class, using either the L<perl_manager_class|/perl_manager_class> or L<make_manager_class|/make_manager_class> methods. The default value is determined by the C<default_manager_base_class|/default_manager_base_class()> L<class method|/CLASS METHODS>.
=item B<method_column METHOD>
Returns the name of the column manipulated by the method named METHOD.
=item B<method_name_from_column_name NAME, TYPE>
Looks up the column named NAME and calls L<method_name_from_column|/method_name_from_column> with the column and TYPE as argument. If no such column exists, a fatal error will occur.
=item B<method_name_from_column COLUMN, TYPE>
Given a L<Rose::DB::Object::Metadata::Column>-derived column object and a column L<type|Rose::DB::Object::Metadata::Column/type> name, return the corresponding method name that should be used for it. Several entities are given an opportunity to determine the name. They are consulted in the following order.
=over 4
=item 1. If a custom-defined L<column_name_to_method_name_mapper|/column_name_to_method_name_mapper> exists, then it is used to generate the method name and this name is returned.
=item 2. If a method name has been L<explicitly set|Rose::DB::Object::Metadata::Column/method_name>, for this type in the column object itself, then this name is returned.
=item 3. If the L<convention manager|/convention_manager>'s L<auto_column_method_name|Rose::DB::Object::ConventionManager/auto_column_method_name> method returns a defined value, then this name is returned.
=item 4. Otherwise, the default naming rules as defined in the column class itself are used.
=back
=item B<method_name_is_reserved NAME, CLASS>
Given the method name NAME and the class name CLASS, returns true if the method name is reserved (i.e., is used by the CLASS API), false otherwise.
=item B<nonpersistent_column NAME [, COLUMN | HASHREF]>
This method behaves like the L<column|/column> method, except that it works with L<non-persistent columns|/nonpersistent_columns>. See the documentation for the L<nonpersistent_columns|/nonpersistent_columns> method for more information on non-persistent columns.
=item B<nonpersistent_columns [ARGS]>
Get or set the full list of non-persistent columns. If ARGS are passed, the non-persistent column list is cleared and then ARGS are passed to the L<add_nonpersistent_columns|/add_nonpersistent_columns> method.
Returns a list of non-persistent column objects in list context, or a reference to an array of non-persistent column objects in scalar context.
Non-persistent columns allow the creation of object attributes and associated accessor/mutator methods exactly like those associated with L<columns|/columns>, but I<without> ever sending any of these attributes to (or pulling any these attributes from) the database.
Non-persistent columns are tracked entirely separately from L<columns|/columns>. L<Adding|/add_nonpersistent_columns>, L<deleting|/delete_nonpersistent_column>, and listing non-persistent columns has no affect on the list of normal (i.e., "persistent") L<columns|/column>.
You cannot query the database (e.g., using L<Rose::DB::Object::Manager>) and filter on a non-persistent column; non-persistent columns do not exist in the database. This feature exists solely to leverage the method creation abilities of the various column classes.
=item B<nonpersistent_column_accessor_method_name NAME>
Returns the name of the "get" method for the L<non-persistent|/nonpersistent_columns> column named NAME. This is just a shortcut for C<$meta-E<gt>nonpersistent_column(NAME)-E<gt>accessor_method_name>.
=item B<nonpersistent_column_accessor_method_names>
Returns a list (in list context) or a reference to the array (in scalar context) of the names of the "set" methods for all the L<non-persistent|/nonpersistent_columns> columns, in the order that the columns are returned by L<nonpersistent_column_names|/nonpersistent_column_names>.
=item B<nonpersistent_column_mutator_method_name NAME>
Returns the name of the "set" method for the L<non-persistent|/nonpersistent_columns> column named NAME. This is just a shortcut for C<$meta-E<gt>nonpersistent_column(NAME)-E<gt>mutator_method_name>.
=item B<nonpersistent_column_mutator_method_names>
Returns a list (in list context) or a reference to the array (in scalar context) of the names of the "set" methods for all the L<non-persistent columns|/nonpersistent_columns>, in the order that the columns are returned by L<nonpersistent_column_names|/nonpersistent_column_names>.
=item B<nonpersistent_column_names>
Returns a list (in list context) or a reference to an array (in scalar context) of L<non-persistent|/nonpersistent_columns> column names.
=item B<pk_columns [COLUMNS]>
This is an alias for the L<primary_key_columns|/primary_key_columns> method.
=item B<post_init_hook [ CODEREF | ARRAYREF ]>
Get or set a reference to a subroutine or a reference to an array of code references that will be called just after the L<initialize|/initialize> method runs. Each referenced subroutine will be passed the metadata object itself and any arguments passed to the call to L<initialize|/initialize>.
=item B<pre_init_hook [ CODEREF | ARRAYREF ]>
Get or set a reference to a subroutine or a reference to an array of code references that will be called just before the L<initialize|/initialize> method runs. Each referenced subroutine will be passed the metadata object itself and any arguments passed to the call to L<initialize|/initialize>.
=item B<primary_key [PK]>
Get or set the L<Rose::DB::Object::Metadata::PrimaryKey> object that stores the list of column names that make up the primary key for this table.
=item B<primary_key_columns [COLUMNS]>
Get or set the list of columns that make up the primary key. COLUMNS should be a list of column names or L<Rose::DB::Object::Metadata::Column>-derived objects.
Returns all of the columns that make up the primary key. Each column is a L<Rose::DB::Object::Metadata::Column>-derived column object if a L<column|/column> object with the same name exists, or just the column name otherwise. In scalar context, a reference to an array of columns is returned. In list context, a list is returned.
This method is just a shortcut for the code:
$meta->primary_key->columns(...);
See the L<primary_key|/primary_key> method and the L<Rose::DB::Object::Metadata::PrimaryKey> class for more information.
=item B<primary_key_column_names [NAMES]>
Get or set the names of the columns that make up the table's primary key. NAMES should be a list or reference to an array of column names.
Returns the list of column names (in list context) or a reference to the array of column names (in scalar context).
This method is just a shortcut for the code:
$meta->primary_key->column_names(...);
See the L<primary_key|/primary_key> method and the L<Rose::DB::Object::Metadata::PrimaryKey> class for more information.
=item B<primary_key_generator [CODEREF]>
Get or set the subroutine used to generate new primary key values for the primary key columns of this table. The subroutine will be passed two arguments: the current metadata object and the L<Rose::DB>-derived object that points to the current database.
The subroutine is expected to return a list of values, one for each primary key column. The values must be in the same order as the corresponding columns returned by L<primary_key_columns|/primary_key_columns>. (i.e., the first value belongs to the first column returned by L<primary_key_columns|/primary_key_columns>, the second value belongs to the second column, and so on.)
=item B<primary_key_sequence_names [NAMES]>
Get or set the list of database sequence names used to populate the primary key columns. The sequence names must be in the same order as the L<primary_key_columns|/primary_key_columns>. NAMES may be a list or reference to an array of sequence names. Returns a list (in list context) or reference to the array (in scalar context) of sequence names.
If you do not set this value, it will be derived for you based on the name of the primary key columns. In the common case, you do not need to be concerned about this method. If you are using the built-in SERIAL or AUTO_INCREMENT types in your database for your primary key columns, everything should just work.
=item B<prime_caches [PARAMS]>
By default, secondary metadata derived from the attributes of this object is created and cached on demand. Call this method to pre-cache this metadata all at once. This method is useful when running in an environment like L<mod_perl> where it's advantageous to load as much data as possible on start-up.
PARAMS are name/value pairs. Valid parameters are:
=over 4
=item B<db DB>
A L<Rose::DB>-derived object used to determine which data source the cached metadata will be generated on behalf of. (Each data source has its own set of cached metadata.) This parameter is optional. If it is not passed, then the L<Rose::DB>-derived object returned by the L<init_db|Rose::DB::Object/init_db> method for this L<class|/class> will be used instead.
=back
=item B<relationship NAME [, RELATIONSHIP | HASHREF]>
Get or set the relationship named NAME. If just NAME is passed, the L<Rose::DB::Object::Metadata::Relationship>-derived relationship object for that NAME is returned. If no such relationship exists, undef is returned.
If both NAME and RELATIONSHIP are passed, then RELATIONSHIP must be a L<Rose::DB::Object::Metadata::Relationship>-derived object. RELATIONSHIP has its L<name|Rose::DB::Object::Metadata::Relationship/name> set to NAME, and is then stored as the relationship metadata object for NAME, replacing any existing relationship.
If both NAME and HASHREF are passed, then the combination of NAME and HASHREF must form a name/value pair suitable for passing to the L<add_relationships|/add_relationships> method. The new relationship specified by NAME and HASHREF replaces any existing relationship.
=item B<relationships [ARGS]>
Get or set the full list of relationships. If ARGS are passed, the relationship list is cleared and then ARGS are passed to the L<add_relationships|/add_relationships> method.
Returns a list of relationship objects in list context, or a reference to an array of relationship objects in scalar context.
=item B<replace_column NAME, [COLUMN | HASHREF]>
Replace the column named NAME with a newly constructed column. This method is equivalent to L<deleting|/delete_column> any existing column named NAME and then L<adding|/add_column> a new one. In other words, this:
$meta->replace_column($name => $value);
is equivalent to this:
$meta->delete_column($name);
$meta->add_column($name => $value);
The value of the new column may be a L<Rose::DB::Object::Metadata::Column>-derived object or a reference to a hash suitable for passing to the L<add_columns|/add_columns> method.
=item B<schema [SCHEMA]>
Get or set the database schema for this L<class|/class>. This setting will B<override> any L<setting|Rose::DB/schema> in the L<db|Rose::DB::Object/db> object. Use this method only if you know that the L<class|/class> will always point to a specific schema, regardless of what the L<Rose::DB>-derived database handle object specifies.
=item B<setup PARAMS>
Set up all the metadata for this L<class|/class> in a single method call. This method is a convenient shortcut. It does its work by delegating to other methods.
The L<setup()|/setup> method does nothing if the metadata object is already initialized (according to the L<is_initialized|/is_initialized> method).
PARAMS are method/arguments pairs. In general, the following transformations apply.
Given a method/arrayref pair:
METHOD => [ ARG1, ARG2 ]
The arguments will be removed from their array reference and passed to METHOD like this:
$meta->METHOD(ARG1, ARG2);
Given a method/value pair:
METHOD => ARG
The argument will be passed to METHOD as-is:
$meta->METHOD(ARG);
There are two exceptions to these transformation rules.
If METHOD is "L<unique_key|/unique_key>" or "L<add_unique_key|/add_unique_key>" and the argument is a reference to an array containing only non-reference values, then the array reference itself is passed to the method. For example, this pair:
unique_key => [ 'name', 'status' ]
will result in this method call:
$meta->unique_key([ 'name', 'status' ]);
(Note that these method names are I<singular>. This exception does I<not> apply to the I<plural> variants, "L<unique_keys|/unique_keys>" and "L<add_unique_keys|/add_unique_keys>".)
If METHOD is "helpers", then the argument is dereferenced (if it's an array reference) and passed on to L<Rose::DB::Object::Helpers>. That is, this:
helpers => [ 'load_or_save', { load_or_insert => 'find_or_create' } ],
Is equivalent to having this in your L<class|/class>:
use Rose::DB::Object::Helpers
'load_or_save', { load_or_insert => 'find_or_create' };
Method names may appear more than once in PARAMS. The methods are called in the order that they appear in PARAMS, with the exception of the L<initialize|/initialize> (or L<auto_initialize|/auto_initialize>) method, which is always called last.
If "initialize" is not one of the method names, then it will be called automatically (with no arguments) at the end. If you do not want to pass any arguments to the L<initialize|/initialize> method, standard practice is to omit it.
If "auto_initialize" is one of the method names, then the L<auto_initialize|/auto_initialize> method will be called instead of the L<initialize|/initialize> method. This is useful if you want to manually set up a few pieces of metadata, but want the auto-initialization system to set up the rest.
The name "auto" is considered equivalent to "auto_initialize", but any arguments are ignored unless they are encapsulated in a reference to an array. For example, these are equivalent:
$meta->setup(
table => 'mytable',
# Call auto_initialize() with no arguments
auto_initialize => [],
);
# This is another way of writing the same thing as the above
$meta->setup(
table => 'mytable',
# The value "1" is ignored because it's not an arrayref,
# so auto_initialize() will be called with no arguments.
auto => 1,
);
Finally, here's a full example of a L<setup()|/setup> method call followed by the equivalent "long-hand" implementation.
$meta->setup
(
table => 'colors',
columns =>
[
code => { type => 'character', length => 3, not_null => 1 },
name => { type => 'varchar', length => 255 },
],
primary_key_columns => [ 'code' ],
unique_key => [ 'name' ],
);
The L<setup()|/setup> method call above is equivalent to the following code:
unless($meta->is_initialized)
{
$meta->table('colors');
$meta->columns(
[
code => { type => 'character', length => 3, not_null => 1 },
name => { type => 'varchar', length => 255 },
]);
$meta->primary_key_columns('code');
$meta->unique_key([ 'name' ]),
$meta->initialize;
}
=item B<sql_qualify_column_names_on_load [BOOL]>
Get or set a boolean value that indicates whether or not to prefix the columns with the table name in the SQL used to L<load()|Rose::DB::Object/load> an object. The default value is false.
For example, here is some SQL that might be used to L<load|Rose::DB::Object/load> an object, as generated with L<sql_qualify_column_names_on_load|/sql_qualify_column_names_on_load> set to false:
SELECT id, name FROM dogs WHERE id = 5;
Now here's how it would look with L<sql_qualify_column_names_on_load|/sql_qualify_column_names_on_load> set to true:
SELECT dogs.id, dogs.name FROM dogs WHERE dogs.id = 5;
=item B<table [TABLE]>
Get or set the name of the database table. The table name should not include any sort of prefix to indicate the L<schema|Rose::DB/schema> or L<catalog|Rose::DB/catalog>.
=item B<unique_key KEY>
This method is an alias for L<add_unique_keys|/add_unique_keys>.
=item B<unique_keys KEYS>
Get or set the list of unique keys for this table. If KEYS is passed, any existing keys will be deleted and KEYS will be passed to the L<add_unique_keys|/add_unique_keys> method.
Returns the list (in list context) or reference to an array (in scalar context) of L<Rose::DB::Object::Metadata::UniqueKey> objects.
=item B<unique_key_by_name NAME>
Return the unique key L<named|Rose::DB::Object::Metadata::UniqueKey/name> NAME, or undef if no such key exists.
=item B<unique_keys_column_names>
Returns a list (in list context) or a reference to an array (in scalar context) or references to arrays of the column names that make up each unique key. That is:
# Example of a scalar context return value
[ [ 'id', 'name' ], [ 'code' ] ]
# Example of a list context return value
([ 'id', 'name' ], [ 'code' ])
=back
=head1 AUTO-INITIALIZATION METHODS
These methods are associated with the L<auto-initialization|/"AUTO-INITIALIZATION"> process. Calling any of them will cause the auto-initialization code to be loaded, which costs memory. This should be considered an implementation detail for now.
Regardless of the implementation details, you should still avoid calling any of these methods unless you plan to do some auto-initialization. No matter how generic they may seem (e.g., L<default_perl_indent|/default_perl_indent>), rest assured that none of these methods are remotely useful I<unless> you are doing auto-initialization.
=head2 CLASS METHODS
=over 4
=item B<default_perl_braces [STYLE]>
Get or set the default brace style used in the Perl code generated by the perl_* object methods. STYLE must be either "k&r" or "bsd". The default value is "k&r".
=item B<default_perl_indent [INT]>
Get or set the default integer number of spaces used for each level of indenting in the Perl code generated by the perl_* object methods. The default value is 4.
=item B<default_perl_unique_key_style [STYLE]>
Get or set the default style of the unique key initialization used in the Perl code generated by the L<perl_unique_keys_definition|/perl_unique_keys_definition> method. STYLE must be "array" or "object". The default value is "array". See the L<perl_unique_keys_definition|/perl_unique_keys_definition> method for examples of the two styles.
=back
=head2 OBJECT METHODS
=over 4
=item B<auto_generate_columns>
Auto-generate L<Rose::DB::Object::Metadata::Column>-derived objects for each column in the table. Note that this method does not modify the metadata object's list of L<columns|/columns>. It simply returns a list of column objects. Calling this method in void context will cause a fatal error.
Returns a list of column objects (in list context) or a reference to a hash of column objects, keyed by column name (in scalar context). The hash reference return value is intended to allow easy modification of the auto-generated column objects. Example:
$columns = $meta->auto_generate_columns; # hash ref return value
# Make some changes
$columns->{'name'}->length(10); # set different length
$columns->{'age'}->default(5); # set different default
...
# Finally, set the column list
$meta->columns(values %$columns);
If you do not want to modify the auto-generated columns, you should use the L<auto_init_columns|/auto_init_columns> method instead.
A fatal error will occur unless at least one column was auto-generated.
=item B<auto_generate_foreign_keys [PARAMS]>
Auto-generate L<Rose::DB::Object::Metadata::ForeignKey> objects for each foreign key in the table. Note that this method does not modify the metadata object's list of L<foreign_keys|/foreign_keys>. It simply returns a list of foreign key objects. Calling this method in void context will cause a fatal error. A warning will be issued if a foreign key could not be generated because no L<Rose::DB::Object>-derived class was found for the foreign table.
PARAMS are optional name/value pairs. If a C<no_warnings> parameter is passed with a true value, then the warning described above will not be issued.
Returns a list of foreign key objects (in list context) or a reference to an array of foreign key objects (in scalar context).
If you do not want to inspect or modify the auto-generated foreign keys, but just want them to populate the metadata object's L<foreign_keys|/foreign_keys> list, you should use the L<auto_init_foreign_keys|/auto_init_foreign_keys> method instead.
B<Note:> This method works with MySQL only when using the InnoDB storage type.
=item B<auto_generate_unique_keys>
Auto-generate L<Rose::DB::Object::Metadata::UniqueKey> objects for each unique key in the table. Note that this method does not modify the metadata object's list of L<unique_keys|/unique_keys>. It simply returns a list of unique key objects. Calling this method in void context will cause a fatal error.
Returns a list of unique key objects (in list context) or a reference to an array of unique key objects (in scalar context).
If you do not want to inspect or modify the auto-generated unique keys, but just want them to populate the metadata object's L<unique_keys|/unique_keys> list, you should use the L<auto_init_unique_keys|/auto_init_unique_keys> method instead.
=item B<auto_retrieve_primary_key_column_names>
Returns a list (in list context) or a reference to an array (in scalar context) of the names of the columns that make up the primary key for this table. Note that this method does not modify the metadata object's L<primary_key|/primary_key>. It simply returns a list of column names. Calling this method in void context will cause a fatal error.
This method is rarely called explicitly. Usually, you will use the L<auto_init_primary_key_columns|/auto_init_primary_key_columns> method instead.
A fatal error will occur unless at least one column name can be retrieved.
(This method uses the word "retrieve" instead of "generate" like its sibling methods above because it does not generate objects; it simply returns column names.)
=item B<auto_initialize [PARAMS]>
Auto-initialize the entire metadata object. This is a wrapper for the individual "auto_init_*" methods, and is roughly equivalent to this:
$meta->auto_init_columns(...);
$meta->auto_init_primary_key_columns;
$meta->auto_init_unique_keys(...);
$meta->auto_init_foreign_keys(...);
$meta->auto_init_relationships(...);
$meta->initialize;
PARAMS are optional name/value pairs. When applicable, these parameters are passed on to each of the "auto_init_*" methods. Valid parameters are:
=over 4
=item B<include_map_class_relationships BOOL>
By default, if a class is a L<map class|Rose::DB::Object::Metadata::Relationship::ManyToMany/map_class> (according to the L<is_map_class|Rose::DB::Object::ConventionManager/is_map_class> method of the L<convention manager|/convention_manager>), then relationships directly between that class and the current L<class|/class> will not be created. Set this parameter to true to allow such relationships to be created.
B<Note:> If some classes that are not actually map classes are being skipped, you should not use this parameter to force them to be included. It's more appropriate to make your own custom L<convention manager|Rose::DB::Object::ConventionManager> subclass and then override the L<is_map_class|Rose::DB::Object::ConventionManager/is_map_class> method to make the correct determination.
=item B<replace_existing BOOL>
If true, then the auto-generated columns, unique keys, foreign keys, and relationships entirely replace any existing columns, unique keys, foreign keys, and relationships, respectively.
=item B<stay_connected BOOL>
If true, then any database connections retained by the metadata objects belonging to the various L<Rose::DB::Object>-derived classes participating in the auto-initialization process will remain connected until an explicit call to the L<clear_all_dbs|/clear_all_dbs> class method.
=item B<with_foreign_keys BOOL>
A boolean value indicating whether or not foreign key metadata will be auto-initialized. Defaults to true.
=item B<with_relationships [ BOOL | ARRAYREF ]>
A boolean value or a reference to an array of relationship L<type|Rose::DB::Object::Metadata::Relationship/type> names. If set to a simple boolean value, then the all types of relationships will be considered for auto-initialization. If set to a list of relationship type names, then only relationships of those types will be considered. Defaults to true.
=item B<with_unique_keys BOOL>
A boolean value indicating whether or not unique key metadata will be auto-initialized. Defaults to true.
=back
During initialization, if one of the columns has a method name that clashes with a L<reserved method name|Rose::DB::Object/"RESERVED METHODS">, then the L<column_alias_generator|/column_alias_generator> will be called to remedy the situation by aliasing the column. If the name still conflicts, then a fatal error will occur.
A fatal error will occur if auto-initialization fails.
=item B<auto_init_columns [PARAMS]>
Auto-generate L<Rose::DB::Object::Metadata::Column> objects for this table, then populate the list of L<columns|/columns>. PARAMS are optional name/value pairs. If a C<replace_existing> parameter is passed with a true value, then the auto-generated columns replace any existing columns. Otherwise, any existing columns are left as-is.
=item B<auto_init_foreign_keys [PARAMS]>
Auto-generate L<Rose::DB::Object::Metadata::ForeignKey> objects for this table, then populate the list of L<foreign_keys|/foreign_keys>. PARAMS are optional name/value pairs. If a C<replace_existing> parameter is passed with a true value, then the auto-generated foreign keys replace any existing foreign keys. Otherwise, any existing foreign keys are left as-is.
B<Note:> This method works with MySQL only when using the InnoDB storage type.
=item B<auto_init_primary_key_columns>
Auto-retrieve the names of the columns that make up the primary key for this table, then populate the list of L<primary_key_column_names|/primary_key_column_names>. A fatal error will occur unless at least one primary key column name could be retrieved.
=item B<auto_init_relationships [PARAMS]>
Auto-populate the list of L<relationships|/relationships> for this L<class|/class>. PARAMS are optional name/value pairs.
=over 4
=item B<include_map_class_relationships BOOL>
By default, if a class is a L<map class|Rose::DB::Object::Metadata::Relationship::ManyToMany/map_class> (according to the L<is_map_class|Rose::DB::Object::ConventionManager/is_map_class> method of the L<convention manager|/convention_manager>), then relationships directly between that class and the current L<class|/class> will not be created. Set this parameter to true to allow such relationships to be created.
B<Note:> If some classes that are not actually map classes are being skipped, you should not use this parameter to force them to be included. It's more appropriate to make your own custom L<convention manager|Rose::DB::Object::ConventionManager> subclass and then override the L<is_map_class|Rose::DB::Object::ConventionManager/is_map_class> method to make the correct determination.
=item B<replace_existing BOOL>
If true, then the auto-generated relationships replace any existing relationships. Otherwise, any existing relationships are left as-is.
=item B<relationship_types ARRAYREF>
A reference to an array of relationship L<type|Rose::DB::Object::Metadata::Relationship/type> names. Only relationships of these types will be created. If omitted, relationships of L<all types|/relationship_type_classes> will be created. If passed a reference to an empty array, no relationships will be created.
=item B<types ARRAYREF>
This is an alias for the C<relationship_types> parameter.
=item B<with_relationships [ BOOL | ARRAYREF ]>
This is the same as the C<relationship_types> parameter except that it also accepts a boolean value. If true, then relationships of L<all types|/relationship_type_classes> will be created. If false, then none will be created.
=back
Assume that this L<class|/class> is called C<Local> and any hypothetical foreign class is called C<Remote>. Relationships are auto-generated according to the following rules.
=over 4
=item * A L<one-to-many|Rose::DB::Object::Metadata::Relationship::OneToMany> relationship is created between C<Local> and C<Remote> if C<Remote> has a foreign key that points to C<Local>. This is not done, however, if C<Local> has a L<one-to-one|Rose::DB::Object::Metadata::Relationship::OneToOne> relationship pointing to C<Remote> that references the same columns as the foreign key in C<Remote> that points to C<Local>, or if C<Local> is a map class (according to the L<convention manager|/convention_manager>'s L<is_map_class|Rose::DB::Object::ConventionManager/is_map_class> method). The relationship name is generated by the L<convention manager|/convention_manager>'s L<auto_relationship_name_one_to_many|Rose::DB::Object::ConventionManager/auto_relationship_name_one_to_many> method.
=item * A L<many-to-many|Rose::DB::Object::Metadata::Relationship::ManyToMany> relationship is created between C<Local> and C<Remote> if there exists a L<map class|Rose::DB::Object::Metadata::Relationship::ManyToMany/map_class> (according to the convention manager's L<is_map_class|Rose::DB::Object::ConventionManager/is_map_class> method) with exactly two foreign keys, one pointing to L<Local> and on pointing to C<Remote>. The relationship name is generated by creating a L<plural|Rose::DB::Object::ConventionManager/singular_to_plural> version of the name of the foreign key in the map class that points to C<Remote>.
=back
In all cases, if there is an existing, semantically identical relationship, then a new relationship is not auto-generated. Similarly, any existing methods with the same names are not overridden by methods associated with auto-generated relationships.
=item B<auto_init_unique_keys [PARAMS]>
Auto-generate L<Rose::DB::Object::Metadata::UniqueKey> objects for this table, then populate the list of L<unique_keys|/unique_keys>. PARAMS are name/value pairs. If a C<replace_existing> parameter is passed with a true value, then the auto-generated unique keys replace any existing unique keys. Otherwise, any existing unique keys are left as-is.
=item B<column_alias_generator [CODEREF]>
Get or set the code reference to the subroutine used to alias columns have, or would generate, one or more method names that clash with L<reserved method names|Rose::DB::Object/"RESERVED METHODS">.
The subroutine should take two arguments: the metadata object and the column name. The C<$_> variable will also be set to the column name at the time of the call. The subroutine should return an L<alias|Rose::DB::Object::Metadata::Column/alias> for the column.
The default column alias generator simply appends the string "_col" to the end of the column name and returns that as the alias.
=item B<foreign_key_name_generator [CODEREF]>
Get or set the code reference to the subroutine used to generate L<foreign key|Rose::DB::Object::Metadata::ForeignKey> names. B<Note:> This code will only be called if the L<convention_manager|/convention_manager>'s L<auto_foreign_key_name|Rose::DB::Object::ConventionManager/auto_foreign_key_name> method fails to (or declines to) produce a defined foreign key name.
The subroutine should take two arguments: a metadata object and a L<Rose::DB::Object::Metadata::ForeignKey> object. It should return a name for the foreign key.
Each foreign key must have a name that is unique within the class. By default, this name will also be the name of the method generated to access the object referred to by the foreign key, so it must be unique among method names in the class as well.
The default foreign key name generator uses the following algorithm:
If the foreign key has only one column, and if the name of that column ends with an underscore and the name of the referenced column, then that part of the column name is removed and the remaining string is used as the foreign key name. For example, given the following tables:
CREATE TABLE categories
(
id SERIAL PRIMARY KEY,
...
);
CREATE TABLE products
(
category_id INT REFERENCES categories (id),
...
);
The foreign key name would be "category", which is the name of the referring column ("category_id") with an underscore and the name of the referenced column ("_id") removed from the end of it.
If the foreign key has only one column, but it does not meet the criteria described above, then "_object" is appended to the name of the referring column and the resulting string is used as the foreign key name.
If the foreign key has more than one column, then the foreign key name is generated by replacing double colons and case-transitions in the referenced class name with underscores, and then converting to lowercase. For example, if the referenced table is fronted by the class My::TableOfStuff, then the generated foreign key name would be "my_table_of_stuff".
In all of the scenarios above, if the generated foreign key name is still not unique within the class, then a number is appended to the end of the name. That number is incremented until the name is unique.
In practice, rather than setting a custom foreign key name generator, it's usually easier to simply set the foreign key name(s) manually after auto-initializing the foreign keys (but I<before> calling L<initialize|/initialize> or L<auto_initialize|/auto_initialize>, of course).
=item B<perl_class_definition [PARAMS]>
Auto-initialize the columns, primary key, foreign keys, and unique keys, then return the Perl source code for a complete L<Rose::DB::Object>-derived class definition. PARAMS are optional name/value pairs that may include the following:
=over 4
=item B<braces STYLE>
The brace style to use in the generated Perl code. STYLE must be either "k&r" or "bsd". The default value is determined by the return value of the L<default_perl_braces|/default_perl_braces> class method.
=item B<indent INT>
The integer number of spaces to use for each level of indenting in the generated Perl code. The default value is determined by the return value of the L<default_perl_indent|/default_perl_indent> class method.
=item B<isa CLASSES>
The list of base classes to use in the generated class definition. CLASSES should be a single class name, or a reference to an array of class names. The default base class is L<Rose::DB::Object>.
=item B<use_setup BOOL>
If true, then the generated class definition will include a call to the L<setup|/setup> method. Otherwise, the generated code will contain individual methods calls. The default value for this parameter is B<true>; the L<setup|/setup> method is the recommended way to initialize a class.
=back
This method is simply a wrapper (with some glue) for the following methods: L<perl_columns_definition|/perl_columns_definition>, L<perl_primary_key_columns_definition|/perl_primary_key_columns_definition>, L<perl_unique_keys_definition|/perl_unique_keys_definition>, L<perl_foreign_keys_definition|/perl_foreign_keys_definition>, and L<perl_relationships_definition|/perl_relationships_definition>. The "braces" and "indent" parameters are passed on to these other methods.
Here's a complete example, which also serves as an example of the individual "perl_*" methods that this method wraps. First, the table definitions.
CREATE TABLE topics
(
id SERIAL PRIMARY KEY,
name VARCHAR(32)
);
CREATE TABLE codes
(
k1 INT NOT NULL,
k2 INT NOT NULL,
k3 INT NOT NULL,
name VARCHAR(32),
PRIMARY KEY(k1, k2, k3)
);
CREATE TABLE products
(
id SERIAL PRIMARY KEY,
name VARCHAR(32) NOT NULL,
flag BOOLEAN NOT NULL DEFAULT 't',
status VARCHAR(32) DEFAULT 'active',
topic_id INT REFERENCES topics (id),
fk1 INT,
fk2 INT,
fk3 INT,
last_modified TIMESTAMP,
date_created TIMESTAMP,
FOREIGN KEY (fk1, fk2, fk3) REFERENCES codes (k1, k2, k3)
);
CREATE TABLE prices
(
id SERIAL PRIMARY KEY,
product_id INT REFERENCES products (id),
price DECIMAL(10,2) NOT NULL DEFAULT 0.00,
region CHAR(2) NOT NULL DEFAULT 'US'
);
First we'll auto-initialize the classes.
package Code;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->auto_initialize;
package Category;
use base qw(Rose::DB::Object);
# Explicit table name required because the class name
# does not match up with the table name in this case.
__PACKAGE__->meta->table('topics');
__PACKAGE__->meta->auto_initialize;
package Product;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->auto_initialize;
package Price;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->auto_initialize;
Now we'll print the C<Product> class definition;
print Product->meta->perl_class_definition(braces => 'bsd',
indent => 2);
The output looks like this:
package Product;
use strict;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->setup
(
table => 'products',
columns =>
[
id => { type => 'integer', not_null => 1 },
name => { type => 'varchar', length => 32, not_null => 1 },
flag => { type => 'boolean', default => 'true', not_null => 1 },
status => { type => 'varchar', default => 'active', length => 32 },
topic_id => { type => 'integer' },
fk1 => { type => 'integer' },
fk2 => { type => 'integer' },
fk3 => { type => 'integer' },
last_modified => { type => 'timestamp' },
date_created => { type => 'timestamp' },
],
primary_key_columns => [ 'id' ],
foreign_keys =>
[
code =>
{
class => 'Code',
key_columns =>
{
fk1 => 'k1',
fk2 => 'k2',
fk3 => 'k3',
},
},
topic =>
{
class => 'Category',
key_columns =>
{
topic_id => 'id',
},
},
],
relationships =>
[
prices =>
{
class => 'Price',
key_columns => { id => 'product_id' },
type => 'one to many',
},
],
);
1;
Here's the output when the C<use_setup> parameter is explicitly set to false.
print Product->meta->perl_class_definition(braces => 'bsd',
indent => 2,
use_setup => 0);
Note that this approach is not recommended, but exists for historical reasons.
package Product;
use strict;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->table('products');
__PACKAGE__->meta->columns
(
id => { type => 'integer', not_null => 1 },
name => { type => 'varchar', length => 32, not_null => 1 },
flag => { type => 'boolean', default => 'true', not_null => 1 },
status => { type => 'varchar', default => 'active', length => 32 },
topic_id => { type => 'integer' },
fk1 => { type => 'integer' },
fk2 => { type => 'integer' },
fk3 => { type => 'integer' },
last_modified => { type => 'timestamp' },
date_created => { type => 'timestamp' },
);
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
__PACKAGE__->meta->foreign_keys
(
code =>
{
class => 'Code',
key_columns =>
{
fk1 => 'k1',
fk2 => 'k2',
fk3 => 'k3',
},
},
topic =>
{
class => 'Category',
key_columns =>
{
topic_id => 'id',
},
},
);
__PACKAGE__->meta->relationships
(
prices =>
{
class => 'Price',
key_columns => { id => 'product_id' },
type => 'one to many',
},
);
__PACKAGE__->meta->initialize;
1;
See the L<auto-initialization|AUTO-INITIALIZATION> section for more discussion of Perl code generation.
=item B<perl_columns_definition [PARAMS]>
Auto-initialize the columns (if necessary), then return the Perl source code that is equivalent to the auto-initialization. PARAMS are optional name/value pairs that may include the following:
=over 4
=item B<braces STYLE>
The brace style to use in the generated Perl code. STYLE must be either "k&r" or "bsd". The default value is determined by the return value of the L<default_perl_braces|/default_perl_braces> class method.
=item B<for_setup BOOL>
If true, then the generated Perl code will be a method/arguments pair suitable for use as a parameter to L<setup|/setup> method. The default is false.
=item B<indent INT>
The integer number of spaces to use for each level of indenting in the generated Perl code. The default value is determined by the return value of the L<default_perl_indent|/default_perl_indent> class method.
=back
To see examples of the generated code, look in the documentation for the L<perl_class_definition|/perl_class_definition> method.
=item B<perl_foreign_keys_definition [PARAMS]>
Auto-initialize the foreign keys (if necessary), then return the Perl source code that is equivalent to the auto-initialization. PARAMS are optional name/value pairs that may include the following:
=over 4
=item B<braces STYLE>
The brace style to use in the generated Perl code. STYLE must be either "k&r" or "bsd". The default value is determined by the return value of the L<default_perl_braces|/default_perl_braces> class method.
=item B<for_setup BOOL>
If true, then the generated Perl code will be a method/arguments pair suitable for use as a parameter to L<setup|/setup> method. The default is false.
=item B<indent INT>
The integer number of spaces to use for each level of indenting in the generated Perl code. The default value is determined by the return value of the L<default_perl_indent|/default_perl_indent> class method.
=back
To see examples of the generated code, look in the documentation for the L<perl_class_definition|/perl_class_definition> method.
=item B<perl_manager_class [ PARAMS | BASE_NAME ]>
Returns a Perl class definition for a L<Rose::DB::Object::Manager>-derived class to manage objects of this L<class|/class>. If a single string is passed, it is taken as the value of the C<base_name> parameter. PARAMS are optional name/value pairs that may include the following:
=over 4
=item B<base_name NAME>
The value of the L<base_name|Rose::DB::Object::Manager/base_name> parameter that will be passed to the call to L<Rose::DB::Object::Manager>'s L<make_manager_methods|Rose::DB::Object::Manager/make_manager_methods> method. Defaults to the return value of the L<convention manager|/convention_manager>'s L<auto_manager_base_name|Rose::DB::Object::ConventionManager/auto_manager_base_name> method.
=item B<class CLASS>
The name of the manager class. Defaults to the return value of the L<convention manager|/convention_manager>'s L<auto_manager_class_name|Rose::DB::Object::ConventionManager/auto_manager_class_name> method.
=item B<isa [ LIST | ARRAYREF ]>
The name of a single class or a reference to an array of class names to be included in the C<@ISA> array for the manager class. One of these classes must inherit from L<Rose::DB::Object::Manager>. Defaults to the return value of the C<default_manager_base_class()> L<object method|/OBJECT METHODS>.
=back
For example, given this class:
package Product;
use Rose::DB::Object;
our @ISA = qw(Rose::DB::Object);
...
print Product->meta->perl_manager_class(
class => 'Prod::Mgr',
base_name => 'prod');
The following would be printed:
package Prod::Mgr;
use Rose::DB::Object::Manager;
our @ISA = qw(Rose::DB::Object::Manager);
sub object_class { 'Product' }
__PACKAGE__->make_manager_methods('prod');
1;
=item B<perl_primary_key_columns_definition>
Auto-initialize the primary key column names (if necessary), then return the Perl source code that is equivalent to the auto-initialization.
See the larger example in the documentation for the L<perl_class_definition|/perl_class_definition> method to see what the generated Perl code looks like.
=item B<perl_relationships_definition [PARAMS]>
Auto-initialize the relationships (if necessary), then return the Perl source code that is equivalent to the auto-initialization. PARAMS are optional name/value pairs that may include the following:
=over 4
=item B<braces STYLE>
The brace style to use in the generated Perl code. STYLE must be either "k&r" or "bsd". The default value is determined by the return value of the L<default_perl_braces|/default_perl_braces> class method.
=item B<for_setup BOOL>
If true, then the generated Perl code will be a method/arguments pair suitable for use as a parameter to L<setup|/setup> method. The default is false.
=item B<indent INT>
The integer number of spaces to use for each level of indenting in the generated Perl code. The default value is determined by the return value of the L<default_perl_indent|/default_perl_indent> class method.
=back
To see examples of the generated code, look in the documentation for the L<perl_class_definition|/perl_class_definition> method.
=item B<perl_table_definition [PARAMS]>
Auto-initialize the table name (if necessary), then return the Perl source code that is equivalent to the auto-initialization. PARAMS are optional name/value pairs that may include the following:
=over 4
=item B<braces STYLE>
The brace style to use in the generated Perl code. STYLE must be either "k&r" or "bsd". The default value is determined by the return value of the L<default_perl_braces|/default_perl_braces> class method.
=item B<for_setup BOOL>
If true, then the generated Perl code will be a method/arguments pair suitable for use as a parameter to L<setup|/setup> method. The default is false.
=item B<indent INT>
The integer number of spaces to use for each level of indenting in the generated Perl code. The default value is determined by the return value of the L<default_perl_indent|/default_perl_indent> class method.
=back
To see examples of the generated code, look in the documentation for the L<perl_class_definition|/perl_class_definition> method.
=item B<perl_unique_keys_definition [PARAMS]>
Auto-initialize the unique keys, then return the Perl source code that is equivalent to the auto-initialization. PARAMS are optional name/value pairs that may include the following:
=over 4
=item B<braces STYLE>
The brace style to use in the generated Perl code. STYLE must be either "k&r" or "bsd". The default value is determined by the return value of the L<default_perl_braces|/default_perl_braces> class method.
=item B<for_setup BOOL>
If true, then the generated Perl code will be a method/arguments pair suitable for use as a parameter to L<setup|/setup> method. The default is false.
=item B<indent INT>
The integer number of spaces to use for each level of indenting in the generated Perl code. The default value is determined by the return value of the L<default_perl_indent|/default_perl_indent> class method.
=item B<style STYLE>
Determines the style the initialization used in the generated Perl code. STYLE must be "array" or "object". The default is determined by the return value of the class method L<default_perl_unique_key_style|/default_perl_unique_key_style>.
The "array" style passes references to arrays of column names:
__PACKAGE__->meta->unique_keys
(
[ 'id', 'name' ],
[ 'flag', 'status' ],
);
The "object" style sets unique keys using calls to the L<Rose::DB::Object::Metadata::UniqueKey> constructor:
__PACKAGE__->meta->unique_keys
(
Rose::DB::Object::Metadata::UniqueKey->new(
name => 'products_id_key',
columns => [ 'id', 'name' ]),
Rose::DB::Object::Metadata::UniqueKey->new(
name => 'products_flag_key',
columns => [ 'flag', 'status' ]),
);
=back
=back
=head1 AUTHOR
John C. Siracusa (siracusa@gmail.com)
=head1 LICENSE
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is
free software; you can redistribute it and/or modify it under the same terms
as Perl itself.
|