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
|
package Rose::Class::MakeMethods::Generic;
use strict;
use Carp();
our $VERSION = '0.854';
use Rose::Object::MakeMethods;
our @ISA = qw(Rose::Object::MakeMethods);
our %Scalar;
# (
# class_name =>
# {
# some_attr_name1 => ...,
# some_attr_name2 => ...,
# ...
# },
# ...
# );
sub scalar
{
my($class, $name, $args, $options) = @_;
my %methods;
my $interface = $args->{'interface'} || 'get_set';
if($interface eq 'get_set')
{
$methods{$name} = sub
{
return $Scalar{$_[0]}{$name} = $_[1] if(@_ > 1);
return $Scalar{$_[0]}{$name};
};
}
elsif($interface eq 'get_set_init')
{
my $init_method = $args->{'init_method'} || "init_$name";
$methods{$name} = sub
{
return $Scalar{$_[0]}{$name} = $_[1] if(@_ > 1);
return defined $Scalar{$_[0]}{$name} ?
$Scalar{$_[0]}{$name} : ($Scalar{$_[0]}{$name} = $_[0]->$init_method())
};
}
return \%methods;
}
our %Inheritable_Scalar;
# (
# class_name =>
# {
# some_attr_name1 => ...,
# some_attr_name2 => ...,
# ...
# },
# ...
# );
sub inheritable_scalar
{
my($class, $name, $args, $options) = @_;
my %methods;
my $interface = $args->{'interface'} || 'get_set';
if($interface eq 'get_set')
{
$methods{$name} = sub
{
my($class) = ref($_[0]) ? ref(shift) : shift;
if(@_)
{
return $Inheritable_Scalar{$class}{$name} = shift;
}
return $Inheritable_Scalar{$class}{$name}
if(exists $Inheritable_Scalar{$class}{$name});
my @parents = ($class);
while(my $parent = shift(@parents))
{
no strict 'refs';
foreach my $subclass (@{$parent . '::ISA'})
{
push(@parents, $subclass);
if(exists $Inheritable_Scalar{$subclass}{$name})
{
return $Inheritable_Scalar{$subclass}{$name}
}
}
}
return undef;
};
}
else { Carp::croak "Unknown interface: $interface" }
return \%methods;
}
our %Inheritable_Boolean;
sub inheritable_boolean
{
my($class, $name, $args, $options) = @_;
my %methods;
my $interface = $args->{'interface'} || 'get_set';
if($interface eq 'get_set')
{
$methods{$name} = sub
{
my($class) = ref($_[0]) ? ref(shift) : shift;
if(@_)
{
return $Inheritable_Boolean{$class}{$name} = $_[0] ? 1 : 0;
}
return $Inheritable_Boolean{$class}{$name}
if(exists $Inheritable_Boolean{$class}{$name});
my @parents = ($class);
while(my $parent = shift(@parents))
{
no strict 'refs';
foreach my $subclass (@{$parent . '::ISA'})
{
push(@parents, $subclass);
if(exists $Inheritable_Boolean{$subclass}{$name})
{
return $Inheritable_Boolean{$subclass}{$name}
}
}
}
return undef;
};
}
else { Carp::croak "Unknown interface: $interface" }
return \%methods;
}
our %Hash;
# (
# class_name =>
# {
# key =>
# {
# some_attr_name1 => ...,
# some_attr_name2 => ...,
# ...
# },
# ...
# },
# ...
# );
sub hash
{
my($class, $name, $args) = @_;
my %methods;
my $key = $args->{'hash_key'} || $name;
my $interface = $args->{'interface'} || 'get_set';
if($interface eq 'get_set_all')
{
$methods{$name} = sub
{
my($class) = ref $_[0] ? ref shift : shift;
# If called with no arguments, return hash contents
return wantarray ? %{$Hash{$class}{$key} || {}} : $Hash{$class}{$key} unless(@_);
# Set hash to arguments
if(@_ == 1 && ref $_[0] eq 'HASH')
{
$Hash{$class}{$key} = $_[0];
}
else
{
# Push on new values and return complete set
Carp::croak "Odd number of items in assigment to $name" if(@_ % 2);
while(@_)
{
local $_ = shift;
$Hash{$class}{$key}{$_} = shift;
}
}
return wantarray ? %{$Hash{$class}{$key} || {}} : $Hash{$class}{$key};
}
}
elsif($interface eq 'clear')
{
$methods{$name} = sub
{
$Hash{$_[0]}{$key} = {}
}
}
elsif($interface eq 'reset')
{
$methods{$name} = sub
{
$Hash{$_[0]}{$key} = undef
}
}
elsif($interface eq 'delete')
{
$methods{($interface eq 'manip' ? 'delete_' : '') . $name} = sub
{
Carp::croak "Missing key(s) to delete" unless(@_ > 1);
delete @{$Hash{$_[0]}{$key}}{@_[1 .. $#_]};
}
}
elsif($interface eq 'exists')
{
$methods{$name . ($interface eq 'manip' ? '_exists' : '')} = sub
{
Carp::croak "Missing key argument" unless(@_ == 2);
defined $Hash{$_[0]}{$key} ? exists $Hash{$_[0]}{$key}{$_[1]} : undef;
}
}
elsif($interface =~ /^(?:keys|names)$/)
{
$methods{$name} = sub
{
wantarray ? (defined $Hash{$_[0]}{$key} ? keys %{$Hash{$_[0]}{$key}} : ()) :
(defined $Hash{$_[0]}{$key} ? [ keys %{$Hash{$_[0]}{$key}} ] : []);
}
}
elsif($interface eq 'values')
{
$methods{$name} = sub
{
wantarray ? (defined $Hash{$_[0]}{$key} ? values %{$Hash{$_[0]}{$key}} : ()) :
(defined $Hash{$_[0]}{$key} ? [ values %{$Hash{$_[0]}{$key}} ] : []);
}
}
elsif($interface eq 'get_set')
{
$methods{$name} = sub
{
my($class) = ref $_[0] ? ref shift : shift;
# If called with no arguments, return hash contents
unless(@_)
{
return wantarray ? (defined $Hash{$class}{$key} ? %{$Hash{$class}{$key}} : ()) : $Hash{$class}{$key}
}
# If called with a hash ref, set value
if(@_ == 1 && ref $_[0] eq 'HASH')
{
$Hash{$class}{$key} = $_[0];
}
else
{
# If called with an index, get that value, or a slice for array refs
if(@_ == 1)
{
return ref $_[0] eq 'ARRAY' ? @{$Hash{$class}{$key}}{@{$_[0]}} :
$Hash{$class}{$key}{$_[0]};
}
# Push on new values and return complete set
Carp::croak "Odd number of items in assigment to $name" if(@_ % 2);
while(@_)
{
local $_ = shift;
$Hash{$class}{$key}{$_} = shift;
}
}
return wantarray ? %{$Hash{$class}{$key} || {}} : $Hash{$class}{$key};
};
}
else { Carp::croak "Unknown interface: $interface" }
return \%methods;
}
our %Inheritable_Hash;
# (
# class_name =>
# {
# key =>
# {
# some_attr_name1 => ...,
# some_attr_name2 => ...,
# ...
# },
# ...
# },
# ...
# );
sub inheritable_hash
{
my($class, $name, $args) = @_;
my %methods;
my $key = $args->{'hash_key'} || $name;
my $interface = $args->{'interface'} || 'get_set';
my $init_method = sub
{
my($class) = ref $_[0] ? ref shift : shift;
# Inherit shallow copy from subclass
my @parents = ($class);
SEARCH: while(my $parent = shift(@parents))
{
no strict 'refs';
foreach my $subclass (@{$parent . '::ISA'})
{
push(@parents, $subclass);
if(exists $Inheritable_Hash{$subclass}{$key})
{
$Inheritable_Hash{$class}{$key} = { %{$Inheritable_Hash{$subclass}{$key}} };
last SEARCH;
}
}
}
};
if($interface eq 'get_set_all')
{
$methods{$name} = sub
{
my($class) = ref $_[0] ? ref shift : shift;
defined $Inheritable_Hash{$class}{$key} || $init_method->($class);
# If called with no arguments, return hash contents
return wantarray ? %{$Inheritable_Hash{$class}{$key} || {}} : $Inheritable_Hash{$class}{$key} unless(@_);
# Set hash to arguments
if(@_ == 1 && ref $_[0] eq 'HASH')
{
$Inheritable_Hash{$class}{$key} = $_[0];
}
else
{
# Push on new values and return complete set
Carp::croak "Odd number of items in assigment to $name" if(@_ % 2);
while(@_)
{
local $_ = shift;
$Inheritable_Hash{$class}{$key}{$_} = shift;
}
}
return wantarray ? %{$Inheritable_Hash{$class}{$key} || {}} : $Inheritable_Hash{$class}{$key};
}
}
elsif($interface eq 'clear')
{
$methods{$name} = sub
{
$Inheritable_Hash{$_[0]}{$key} = {}
}
}
elsif($interface eq 'reset')
{
$methods{$name} = sub
{
$Inheritable_Hash{$_[0]}{$key} = undef;
}
}
elsif($interface eq 'delete')
{
$methods{($interface eq 'manip' ? 'delete_' : '') . $name} = sub
{
Carp::croak "Missing key(s) to delete" unless(@_ > 1);
defined $Inheritable_Hash{$_[0]}{$key} || $init_method->($_[0]);
delete @{$Inheritable_Hash{$_[0]}{$key}}{@_[1 .. $#_]};
}
}
elsif($interface eq 'exists')
{
$methods{$name . ($interface eq 'manip' ? '_exists' : '')} = sub
{
Carp::croak "Missing key argument" unless(@_ == 2);
defined $Inheritable_Hash{$_[0]}{$key} || $init_method->($_[0]);
defined $Inheritable_Hash{$_[0]}{$key} ? exists $Inheritable_Hash{$_[0]}{$key}{$_[1]} : undef;
}
}
elsif($interface =~ /^(?:keys|names)$/)
{
$methods{$name} = sub
{
defined $Inheritable_Hash{$_[0]}{$key} || $init_method->($_[0]);
wantarray ? (defined $Inheritable_Hash{$_[0]}{$key} ? keys %{$Inheritable_Hash{$_[0]}{$key} || {}} : ()) :
(defined $Inheritable_Hash{$_[0]}{$key} ? [ keys %{$Inheritable_Hash{$_[0]}{$key} || {}} ] : []);
}
}
elsif($interface eq 'values')
{
$methods{$name} = sub
{
defined $Inheritable_Hash{$_[0]}{$key} || $init_method->($_[0]);
wantarray ? (defined $Inheritable_Hash{$_[0]}{$key} ? values %{$Inheritable_Hash{$_[0]}{$key} || {}} : ()) :
(defined $Inheritable_Hash{$_[0]}{$key} ? [ values %{$Inheritable_Hash{$_[0]}{$key} || {}} ] : []);
}
}
elsif($interface eq 'get_set')
{
$methods{$name} = sub
{
my($class) = ref $_[0] ? ref shift : shift;
defined $Inheritable_Hash{$class}{$key} || $init_method->($class);
# If called with no arguments, return hash contents
unless(@_)
{
return wantarray ? (defined $Inheritable_Hash{$class}{$key} ? %{$Inheritable_Hash{$class}{$key} || {}} : ()) : $Inheritable_Hash{$class}{$key}
}
# If called with a hash ref, set value
if(@_ == 1 && ref $_[0] eq 'HASH')
{
$Inheritable_Hash{$class}{$key} = $_[0];
}
else
{
# If called with an index, get that value, or a slice for array refs
if(@_ == 1)
{
return ref $_[0] eq 'ARRAY' ? @{$Inheritable_Hash{$class}{$key}}{@{$_[0]}} :
$Inheritable_Hash{$class}{$key}{$_[0]};
}
# Push on new values and return complete set
Carp::croak "Odd number of items in assigment to $name" if(@_ % 2);
while(@_)
{
local $_ = shift;
$Inheritable_Hash{$class}{$key}{$_} = shift;
}
}
return wantarray ? %{$Inheritable_Hash{$class}{$key} || {}} : $Inheritable_Hash{$class}{$key};
};
}
else { Carp::croak "Unknown interface: $interface" }
return \%methods;
}
use constant CLASS_VALUE => 1;
use constant INHERITED_VALUE => 2;
use constant DELETED_VALUE => 3;
our %Inherited_Hash;
# (
# some_name =>
# {
# class1 =>
# {
# meta => { ... },
# cache =>
# {
# meta =>
# {
# attr1 => CLASS_VALUE,
# attr2 => DELETED_VALUE,
# ...
# },
# attrs =>
# {
# attr1 => value1,
# attr2 => value2,
# ...
# },
# },
# },
# class2 => ...,
# ...
# },
# ...
# );
# Used as array indexes to replace {'meta'}, {'attrs'}, and {'cache'}
use constant META => 0;
use constant CACHE => 1;
use constant ATTRS => 1;
# XXX: This implementation is space-inefficient and pretty silly
sub inherited_hash
{
my($class, $name, $args) = @_;
my %methods;
# Interface example:
# name: object_type_class
# plural_name: object_type_classes
#
# get_set: object_type_class
# get_set_all_method: object_type_classes
# keys_method: object_type_class_keys
# cache_method: object_type_classes_cache
# exists_method: object_type_class_exists
# add_method: add_object_type_class
# adds_method: add_object_type_classes
# delete_method: delete_object_type_class
# deletes_method: delete_object_type_classes
# clear_method clear_object_type_classes
# inherit_method: inherit_object_type_class
# inherits_method: inherit_object_type_classes
my $plural_name = $args->{'plural_name'} || $name . 's';
my $get_set_method = $name;
my $get_set_all_method = $args->{'get_set_all_method'} || $args->{'hash_method'} || $plural_name;
my $keys_method = $args->{'keys_method'} || $name . '_keys';
my $cache_method = $args->{'cache_method'} || $plural_name . '_cache';
my $exists_method = $args->{'exists_method'} || $args->{'exists_method'} || $name . '_exists';
my $add_method = $args->{'add_method'} || 'add_' . $name;
my $adds_method = $args->{'adds_method'} || 'add_' . $plural_name;
my $delete_method = $args->{'delete_method'} || 'delete_' . $name;
my $deletes_method = $args->{'deletes_method'} || 'delete_' . $plural_name;
my $clear_method = $args->{'clear_method'} || 'clear_' . $plural_name;
my $inherit_method = $args->{'inherit_method'} || 'inherit_' . $name;
my $inherits_method = $args->{'inherits_method'} || 'inherit_' . $plural_name;
my $interface = $args->{'interface'} || 'all';
my $add_implies = $args->{'add_implies'};
my $delete_implies = $args->{'delete_implies'};
my $inherit_implies = $args->{'inherit_implies'};
$add_implies = [ $add_implies ]
if(defined $add_implies && !ref $add_implies);
$delete_implies = [ $delete_implies ]
if(defined $delete_implies && !ref $delete_implies);
$inherit_implies = [ $inherit_implies ]
if(defined $inherit_implies && !ref $inherit_implies);
$methods{$cache_method} = sub
{
my($class) = ref($_[0]) || $_[0];
if($Inherited_Hash{$name}{$class}[META]{'cache_is_valid'})
{
return
wantarray ? (%{$Inherited_Hash{$name}{$class}[CACHE] ||= []}) :
($Inherited_Hash{$name}{$class}[CACHE] ||= []);
}
my $cache = $Inherited_Hash{$name}{$class}[CACHE] ||= [];
my @parents = ($class);
while(my $parent = shift(@parents))
{
no strict 'refs';
foreach my $superclass (@{$parent . '::ISA'})
{
push(@parents, $superclass);
if($superclass->can($cache_method))
{
my $supercache = $superclass->$cache_method();
while(my($attr, $state) = each %{$supercache->[META] || {}})
{
next if($state == DELETED_VALUE);
no warnings 'uninitialized';
unless(exists $cache->[ATTRS]{$attr})
{
$cache->[ATTRS]{$attr} = $supercache->[ATTRS]{$attr};
$cache->[META]{$attr} = INHERITED_VALUE;
}
}
}
# Slower method for superclasses that don't want to implement the
# cache method (which is not strictly part of the public API)
elsif($superclass->can($keys_method))
{
foreach my $attr ($superclass->$keys_method())
{
unless(exists $Inherited_Hash{$name}{$class}[CACHE][ATTRS]{$attr})
{
$Inherited_Hash{$name}{$class}[CACHE][META]{$attr} = INHERITED_VALUE;
$Inherited_Hash{$name}{$class}[CACHE][ATTRS]{$attr} =
$Inherited_Hash{$name}{$superclass}[CACHE][ATTRS]{$attr};
}
}
}
}
}
$Inherited_Hash{$name}{$class}[META]{'cache_is_valid'} = 1;
my $want = wantarray;
return unless(defined $want);
$want ? (%{$Inherited_Hash{$name}{$class}[CACHE] ||= []}) :
($Inherited_Hash{$name}{$class}[CACHE] ||= []);
};
$methods{$get_set_method} = sub
{
my($class) = ref($_[0]) ? ref(shift) : shift;
return 0 unless(defined $_[0]);
my $key = shift;
if(@_)
{
Carp::croak "More than one value passed to $get_set_method()" if(@_ > 1);
$class->$adds_method($key, @_);
}
else
{
if($Inherited_Hash{$name}{$class}[META]{'cache_is_valid'})
{
my $cache = $Inherited_Hash{$name}{$class}[CACHE] ||= [];
no warnings 'uninitialized';
return $cache->[ATTRS]{$key} unless($cache->[META]{$key} == DELETED_VALUE);
return undef;
}
my $cache = $class->$cache_method();
no warnings 'uninitialized';
return $cache->[ATTRS]{$key} unless($cache->[META]{$key} == DELETED_VALUE);
return undef;
}
};
$methods{$keys_method} = sub
{
my($class) = shift;
$class = ref $class if(ref $class);
return wantarray ? keys %{$class->$get_set_all_method()} :
[ keys %{$class->$get_set_all_method()} ];
};
$methods{$get_set_all_method} = sub
{
my($class) = shift;
$class = ref $class if(ref $class);
if(@_)
{
$class->$clear_method();
return $class->$adds_method(@_);
}
my $cache = $class->$cache_method();
my %hash = %{$cache->[ATTRS] || {}};
foreach my $k (keys %hash)
{
delete $hash{$k} if($Inherited_Hash{$name}{$class}[CACHE][META]{$k} == DELETED_VALUE);
}
return wantarray ? %hash : \%hash;
};
$methods{$exists_method} = sub
{
my($class) = ref($_[0]) ? ref(shift) : shift;
my $key = shift;
return 0 unless(defined $key);
if($Inherited_Hash{$name}{$class}[META]{'cache_is_valid'})
{
my $cache = $Inherited_Hash{$name}{$class}[CACHE] ||= [];
return (exists $cache->[ATTRS]{$key} && $cache->[META]{$key} != DELETED_VALUE) ? 1 : 0;
}
my $cache = $class->$cache_method();
return (exists $cache->[ATTRS]{$key} && $cache->[META]{$key} != DELETED_VALUE) ? 1 : 0;
};
$methods{$add_method} = sub { shift->$adds_method(@_) };
$methods{$adds_method} = sub
{
my($class) = ref($_[0]) ? ref(shift) : shift;
Carp::croak("Missing name/value pair(s) to add") unless(@_);
my @attrs;
my $count = 0;
my $cache = $Inherited_Hash{$name}{$class}[CACHE] ||= [];
# XXX: Lame duplication to avoid copying the hash
if(@_ == 1 && ref $_[0] eq 'HASH')
{
while(my($attr, $value) = each(%{$_[0]}))
{
next unless(defined $attr);
push(@attrs, $attr);
$cache->[ATTRS]{$attr} = $value;
$cache->[META]{$attr} = CLASS_VALUE;
if($add_implies)
{
foreach my $method (@$add_implies)
{
$class->$method($attr => $value);
}
}
$count++;
}
}
else
{
Carp::croak("Odd number of arguments passed to $adds_method") if(@_ % 2);
while(@_)
{
my($attr, $value) = (shift, shift);
push(@attrs, $attr);
no strict 'refs';
next unless(defined $attr);
$cache->[ATTRS]{$attr} = $value;
$cache->[META]{$attr} = CLASS_VALUE;
if($add_implies)
{
foreach my $method (@$add_implies)
{
$class->$method($attr => $value);
}
}
$count++;
}
}
if($count)
{
foreach my $test_class (keys %{$Inherited_Hash{$name}})
{
if($test_class->isa($class) && $test_class ne $class)
{
$Inherited_Hash{$name}{$test_class}[META]{'cache_is_valid'} = 0;
foreach my $attr (@attrs)
{
delete $Inherited_Hash{$name}{$test_class}[CACHE][ATTRS]{$attr};
}
}
}
}
return $count;
};
$methods{$clear_method} = sub
{
my($class) = ref($_[0]) ? ref(shift) : shift;
my @keys = $class->$keys_method();
return unless(@keys);
$class->$deletes_method(@keys);
};
$methods{$delete_method} = sub { shift->$deletes_method(@_) };
$methods{$deletes_method} = sub
{
my($class) = ref($_[0]) ? ref(shift) : shift;
Carp::croak("Missing value(s) to delete") unless(@_);
# Init set if it doesn't exist
unless(exists $Inherited_Hash{$name}{$class})
{
$class->$cache_method();
}
my $count = 0;
my $cache = $Inherited_Hash{$name}{$class}[CACHE] ||= [];
foreach my $attr (@_)
{
no strict 'refs';
next unless(defined $attr);
if(exists $cache->[ATTRS]{$attr} &&
$cache->[META]{$attr} != DELETED_VALUE)
{
$cache->[META]{$attr} = DELETED_VALUE;
$count++;
if($delete_implies)
{
foreach my $method (@$delete_implies)
{
$class->$method($attr);
}
}
foreach my $test_class (keys %{$Inherited_Hash{$name}})
{
next if($class eq $test_class);
my $test_cache = $Inherited_Hash{$name}{$test_class}[CACHE] ||= [];
if($test_class->isa($class) && exists $test_cache->[ATTRS]{$attr} &&
$test_cache->[META]{$attr} == INHERITED_VALUE)
{
delete $test_cache->[ATTRS]{$attr};
delete $test_cache->[META]{$attr};
$Inherited_Hash{$name}{$test_class}[META]{'cache_is_valid'} = 0;
}
}
}
}
return $count;
};
$methods{$inherit_method} = sub { shift->$inherits_method(@_) };
$methods{$inherits_method} = sub
{
my($class) = ref($_[0]) ? ref(shift) : shift;
Carp::croak("Missing value(s) to inherit") unless(@_);
my $count = 0;
my $cache = $Inherited_Hash{$name}{$class}[CACHE] ||= [];
foreach my $attr (@_)
{
if(exists $cache->[ATTRS]{$attr})
{
delete $cache->[ATTRS]{$attr};
delete $cache->[META]{$attr};
$Inherited_Hash{$name}{$class}[META]{'cache_is_valid'} = 0;
$count++;
}
if($inherit_implies)
{
foreach my $method (@$inherit_implies)
{
$class->$method($attr);
}
}
}
return $count;
};
if($interface ne 'all')
{
Carp::croak "Unknown interface: $interface";
}
return \%methods;
}
1;
__END__
=head1 NAME
Rose::Class::MakeMethods::Generic - Create simple class methods.
=head1 SYNOPSIS
package MyClass;
use Rose::Class::MakeMethods::Generic
(
scalar =>
[
'error',
'type' => { interface => 'get_set_init' },
],
inheritable_scalar => 'name',
);
sub init_type { 'special' }
...
package MySubClass;
our @ISA = qw(MyClass);
...
MyClass->error(123);
print MyClass->type; # 'special'
MyClass->name('Fred');
print MySubClass->name; # 'Fred'
MyClass->name('Wilma');
print MySubClass->name; # 'Wilma'
MySubClass->name('Bam');
print MyClass->name; # 'Wilma'
print MySubClass->name; # 'Bam'
=head1 DESCRIPTION
L<Rose::Class::MakeMethods::Generic> is a method maker that inherits from L<Rose::Object::MakeMethods>. See the L<Rose::Object::MakeMethods> documentation to learn about the interface. The method types provided by this module are described below. All methods work only with classes, not objects.
=head1 METHODS TYPES
=over 4
=item B<scalar>
Create get/set methods for scalar class attributes.
=over 4
=item Options
=over 4
=item C<init_method>
The name of the class method to call when initializing the value of an undefined attribute. This option is only applicable when using the C<get_set_init> interface. Defaults to the method name with the prefix C<init_> added.
=item C<interface>
Choose one of the two possible interfaces. Defaults to C<get_set>.
=back
=item Interfaces
=over 4
=item C<get_set>
Creates a simple get/set accessor method for a class attribute. When called with an argument, the value of the attribute is set. The current value of the attribute is returned.
=item C<get_set_init>
Behaves like the C<get_set> interface unless the value of the attribute is undefined. In that case, the class method specified by the C<init_method> option is called and the attribute is set to the return value of that method.
=back
=back
Example:
package MyClass;
use Rose::Class::MakeMethods::Generic
(
scalar => 'power',
'scalar --get_set_init' => 'name',
);
sub init_name { 'Fred' }
...
MyClass->power(99); # returns 99
MyClass->name; # returns "Fred"
MyClass->name('Bill'); # returns "Bill"
=item B<inheritable_boolean>
Create get/set methods for boolean class attributes that are inherited by subclasses until/unless their values are changed.
=over 4
=item Options
=over 4
=item C<interface>
Choose the interface. This is kind of pointless since there is only one interface right now. Defaults to C<get_set>, obviously.
=back
=item Interfaces
=over 4
=item C<get_set>
Creates a get/set accessor method for a class attribute. When called with an argument, the value of the attribute is set to 1 if that argument is true or 0 if it is false. The value of the attribute is then returned.
If called with no arguments, and if the attribute was never set for this class, then a left-most, breadth-first search of the parent classes is initiated. The value returned is taken from first parent class encountered that has ever had this attribute set.
=back
=back
Example:
package MyClass;
use Rose::Class::MakeMethods::Generic
(
inheritable_boolean => 'enabled',
);
...
package MySubClass;
our @ISA = qw(MyClass);
...
package MySubSubClass;
our @ISA = qw(MySubClass);
...
$x = MyClass->enabled; # undef
$y = MySubClass->enabled; # undef
$z = MySubSubClass->enabled; # undef
MyClass->enabled(1);
$x = MyClass->enabled; # 1
$y = MySubClass->enabled; # 1
$z = MySubSubClass->enabled; # 1
MyClass->enabled(0);
$x = MyClass->enabled; # 0
$y = MySubClass->enabled; # 0
$z = MySubSubClass->enabled; # 0
MySubClass->enabled(1);
$x = MyClass->enabled; # 0
$y = MySubClass->enabled; # 1
$z = MySubSubClass->enabled; # 1
MyClass->enabled(1);
MySubClass->enabled(undef);
$x = MyClass->enabled; # 1
$y = MySubClass->enabled; # 0
$z = MySubSubClass->enabled; # 0
MySubSubClass->enabled(1);
$x = MyClass->enabled; # 1
$y = MySubClass->enabled; # 0
$z = MySubSubClass->enabled; # 0
=item B<inheritable_scalar>
Create get/set methods for scalar class attributes that are inherited by subclasses until/unless their values are changed.
=over 4
=item Options
=over 4
=item C<interface>
Choose the interface. This is kind of pointless since there is only one interface right now. Defaults to C<get_set>, obviously.
=back
=item Interfaces
=over 4
=item C<get_set>
Creates a get/set accessor method for a class attribute. When called with an argument, the value of the attribute is set and then returned.
If called with no arguments, and if the attribute was never set for this class, then a left-most, breadth-first search of the parent classes is initiated. The value returned is taken from first parent class encountered that has ever had this attribute set.
=back
=back
Example:
package MyClass;
use Rose::Class::MakeMethods::Generic
(
inheritable_scalar => 'name',
);
...
package MySubClass;
our @ISA = qw(MyClass);
...
package MySubSubClass;
our @ISA = qw(MySubClass);
...
$x = MyClass->name; # undef
$y = MySubClass->name; # undef
$z = MySubSubClass->name; # undef
MyClass->name('Fred');
$x = MyClass->name; # 'Fred'
$y = MySubClass->name; # 'Fred'
$z = MySubSubClass->name; # 'Fred'
MyClass->name('Wilma');
$x = MyClass->name; # 'Wilma'
$y = MySubClass->name; # 'Wilma'
$z = MySubSubClass->name; # 'Wilma'
MySubClass->name('Bam');
$x = MyClass->name; # 'Wilma'
$y = MySubClass->name; # 'Bam'
$z = MySubSubClass->name; # 'Bam'
MyClass->name('Koop');
MySubClass->name(undef);
$x = MyClass->name; # 'Koop'
$y = MySubClass->name; # undef
$z = MySubSubClass->name; # undef
MySubSubClass->name('Sam');
$x = MyClass->name; # 'Koop'
$y = MySubClass->name; # undef
$z = MySubSubClass->name; # 'Sam'
=item B<hash>
Create methods to manipulate a hash of class attributes.
=over 4
=item Options
=over 4
=item C<hash_key>
The key to use for the storage of this attribute. Defaults to the name of the method.
=item C<interface>
Choose which interface to use. Defaults to C<get_set>.
=back
=item Interfaces
=over 4
=item C<get_set>
If called with no arguments, returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
If called with one argument, and that argument is a reference to a hash, that hash reference is used as the new value for the attribute. Returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
If called with one argument, and that argument is a reference to an array, then a list of the hash values for each key in the array is returned.
If called with one argument, and it is not a reference to a hash or an array, then the hash value for that key is returned.
If called with an even number of arguments, they are taken as name/value pairs and are added to the hash. It then returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
Passing an odd number of arguments greater than 1 causes a fatal error.
=item C<get_set_all>
If called with no arguments, returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
If called with one argument, and that argument is a reference to a hash, that hash reference is used as the new value for the attribute. Returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
Otherwise, the hash is emptied and the arguments are taken as name/value pairs that are then added to the hash. It then returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
=item C<clear>
Sets the attribute to an empty hash.
=item C<reset>
Sets the attribute to undef.
=item C<delete>
Deletes the key(s) passed as arguments. Failure to pass any arguments causes a fatal error.
=item C<exists>
Returns true of the argument exists in the hash, false otherwise. Failure to pass an argument or passing more than one argument causes a fatal error.
=item C<keys>
Returns the keys of the hash in list context, or a reference to an array of the keys of the hash in scalar context. The keys are not sorted.
=item C<names>
An alias for the C<keys> interface.
=item C<values>
Returns the values of the hash in list context, or a reference to an array of the values of the hash in scalar context. The values are not sorted.
=back
=back
Example:
package MyClass;
use Rose::Class::MakeMethods::Generic
(
hash =>
[
param => { hash_key =>'params' },
params => { interface=>'get_set_all' },
param_names => { interface=>'keys', hash_key=>'params' },
param_values => { interface=>'values', hash_key=>'params' },
param_exists => { interface=>'exists', hash_key=>'params' },
delete_param => { interface=>'delete', hash_key=>'params' },
clear_params => { interface=>'clear', hash_key=>'params' },
reset_params => { interface=>'reset', hash_key=>'params' },
],
);
...
MyClass->params; # undef
MyClass->params(a => 1, b => 2); # add pairs
$val = MyClass->param('b'); # 2
%params = MyClass->params; # copy hash keys and values
$params = MyClass->params; # get hash ref
MyClass->params({ c => 3, d => 4 }); # replace contents
MyClass->param_exists('a'); # false
$keys = join(',', sort MyClass->param_names); # 'c,d'
$vals = join(',', sort MyClass->param_values); # '3,4'
MyClass->delete_param('c');
MyClass->param(f => 7, g => 8);
$vals = join(',', sort MyClass->param_values); # '4,7,8'
MyClass->clear_params;
$params = MyClass->params; # empty hash
MyClass->reset_params;
$params = MyClass->params; # undef
=item B<inheritable_hash>
Create methods to manipulate a hash of class attributes that can be inherited by subclasses.
The hash of attributes is inherited by subclasses using a one-time copy. Any subclass that accesses or manipulates the hash in any way will immediately get its own private copy of the hash I<as it exists in the superclass at the time of the access or manipulation>.
The superclass from which the hash is copied is the closest ("least super") class that has ever accessed or manipulated this hash. The copy is a "shallow" copy, duplicating only the keys and values. Reference values are not recursively copied.
Setting to hash to undef (using the 'reset' interface) will cause it to be re-copied from a superclass the next time it is accessed.
=over 4
=item Options
=over 4
=item C<hash_key>
The key to use for the storage of this attribute. Defaults to the name of the method.
=item C<interface>
Choose which interface to use. Defaults to C<get_set>.
=back
=item Interfaces
=over 4
=item C<get_set>
If called with no arguments, returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
If called with one argument, and that argument is a reference to a hash, that hash reference is used as the new value for the attribute. Returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
If called with one argument, and that argument is a reference to an array, then a list of the hash values for each key in the array is returned.
If called with one argument, and it is not a reference to a hash or an array, then the hash value for that key is returned.
If called with an even number of arguments, they are taken as name/value pairs and are added to the hash. It then returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
Passing an odd number of arguments greater than 1 causes a fatal error.
=item C<get_set_all>
If called with no arguments, returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
If called with one argument, and that argument is a reference to a hash, that hash reference is used as the new value for the attribute. Returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
Otherwise, the hash is emptied and the arguments are taken as name/value pairs that are then added to the hash. It then returns a list of key/value pairs in list context or a reference to the actual hash used to store values in scalar context.
=item C<clear>
Sets the attribute to an empty hash.
=item C<reset>
Sets the attribute to undef.
=item C<delete>
Deletes the key(s) passed as arguments. Failure to pass any arguments causes a fatal error.
=item C<exists>
Returns true of the argument exists in the hash, false otherwise. Failure to pass an argument or passing more than one argument causes a fatal error.
=item C<keys>
Returns the keys of the hash in list context, or a reference to an array of the keys of the hash in scalar context. The keys are not sorted.
=item C<names>
An alias for the C<keys> interface.
=item C<values>
Returns the values of the hash in list context, or a reference to an array of the values of the hash in scalar context. The values are not sorted.
=back
=back
Example:
package MyClass;
use Rose::Class::MakeMethods::Generic
(
inheritable_hash =>
[
param => { hash_key =>'params' },
params => { interface=>'get_set_all' },
param_names => { interface=>'keys', hash_key=>'params' },
param_values => { interface=>'values', hash_key=>'params' },
param_exists => { interface=>'exists', hash_key=>'params' },
delete_param => { interface=>'delete', hash_key=>'params' },
clear_params => { interface=>'clear', hash_key=>'params' },
reset_params => { interface=>'reset', hash_key=>'params' },
],
);
...
package MySubClass;
our @ISA = qw(MyClass);
...
MyClass->params; # undef
MyClass->params(a => 1, b => 2); # add pairs
$val = MyClass->param('b'); # 2
%params = MyClass->params; # copy hash keys and values
$params = MyClass->params; # get hash ref
# Inherit a copy of params from MyClass
$params = MySubClass->params; # { a => 1, b => 2 }
MyClass->params({ c => 3, d => 4 }); # replace contents
# MySubClass params are still as the existed at the time
# they were originally copied from MyClass
$params = MySubClass->params; # { a => 1, b => 2 }
# MySubClass can manipulate its own params as it wishes
MySubClass->param(z => 9);
$params = MySubClass->params; # { a => 1, b => 2, z => 9 }
MyClass->param_exists('a'); # false
$keys = join(',', sort MyClass->param_names); # 'c,d'
$vals = join(',', sort MyClass->param_values); # '3,4'
# Reset params (set to undef) so that they will be re-copied
# from MyClass the next time they're accessed
MySubClass->reset_params;
MyClass->delete_param('c');
MyClass->param(f => 7, g => 8);
$vals = join(',', sort MyClass->param_values); # '4,7,8'
# Inherit a copy of params from MyClass
$params = MySubClass->params; # { d => 4, f => 7, g => 8 }
=item B<inherited_hash>
Create a family of class methods for managing an inherited hash.
An inherited hash is made up of the union of the hashes of all superclasses, minus any keys that are explicitly deleted in the current class.
=over 4
=item Options
=over 4
=item C<add_implies>
A method name, or reference to a list of method names, to call when a key is added to the hash. Each added name/value pair is passed to each method in the C<add_implies> list, one pair at a time.
=item C<add_method>
The name of the class method used to add a single name/value pair to the hash. Defaults to the method name with the prefix C<add_> added.
=item C<adds_method>
The name of the class method used to add one or more name/value pairs to the hash. Defaults to C<plural_name> with the prefix C<add_> added.
=item C<cache_method>
The name of the class method used to retrieve (or generate, if it doesn't exist) the internal cache for the hash. This should be considered a private method, but it is listed here because it does take up a spot in the method namespace. Defaults to C<plural_name> with C<_cache> added to the end.
=item C<clear_method>
The name of the class method used to clear the contents of the hash. Defaults to C<plural_name> with a C<clear_> prefix added.
=item C<delete_implies>
A method name, or reference to a list of method names, to call when a key is removed from the hash. Each deleted key is passed as an argument to each method in the C<delete_implies> list, one key per call.
=item C<delete_method>
The name of the class method used to remove a single key from the hash. Defaults to the method name with the prefix C<delete_> added.
=item C<deletes_method>
The name of the class method used to remove one or more keys from the hash. Defaults to C<plural_name> with a C<delete_> prefix added.
=item C<exists_method>
The name of the class method that tests for the existence of a key in the hash. Defaults to the method name with the suffix C<_exists> added.
=item C<get_set_all_method>
The name of the class method use to set or fetch the entire hash. The hash may be passed as a reference to a hash or as a list of name/value pairs. Returns the hash (in list context) or a reference to a hash (in scalar context). Defaults to C<plural_name>.
=item C<hash_method>
This is an alias for the C<get_set_all_method> parameter.
=item C<inherit_method>
The name of the class method used to indicate that an inherited key that was previously deleted from the hash should return to being inherited. Defaults to the method name with the prefix C<inherit_> added.
=item C<inherits_method>
The name of the class method used to indicate that one or more inherited keys that were previously deleted from the hash should return to being inherited. Defaults to the C<plural_name> with the prefix C<inherit_> added.
=item C<interface>
Choose the interface. This is kind of pointless since there is only one interface right now. Defaults to C<all>, obviously.
=item C<keys_method>
The name of the class method that returns a reference to a list of keys in scalar context, or a list of keys in list context. Defaults to to C<plural_name> with "_keys" added to the end.
=item C<plural_name>
The plural version of the method name, used to construct the default names for some other methods. Defaults to the method name with C<s> added.
=back
=item Interfaces
=over 4
=item C<all>
Creates the entire family of methods described above. The example
below illustrates their use.
=back
=back
Example:
package MyClass;
use Rose::Class::MakeMethods::Generic
(
inherited_hash =>
[
pet_color =>
{
keys_method => 'pets',
delete_implies => 'delete_special_pet_color',
inherit_implies => 'inherit_special_pet_color',
},
special_pet_color =>
{
keys_method => 'special_pets',
add_implies => 'add_pet_color',
},
],
);
...
package MySubClass;
our @ISA = qw(MyClass);
...
MyClass->pet_colors(Fido => 'white',
Max => 'black',
Spot => 'yellow');
MyClass->special_pet_color(Toby => 'tan');
MyClass->pets; # Fido, Max, Spot, Toby
MyClass->special_pets; # Toby
MySubClass->pets; # Fido, Max, Spot, Toby
MyClass->pet_color('Toby'); # tan
MySubClass->special_pet_color(Toby => 'gold');
MyClass->pet_color('Toby'); # tan
MyClass->special_pet_color('Toby'); # tan
MySubClass->pet_color('Toby'); # gold
MySubClass->special_pet_color('Toby'); # gold
MySubClass->inherit_pet_color('Toby');
MySubClass->pet_color('Toby'); # tan
MySubClass->special_pet_color('Toby'); # tan
MyClass->delete_pet_color('Max');
MyClass->pets; # Fido, Spot, Toby
MySubClass->pets; # Fido, Spot, Toby
MyClass->special_pet_color(Max => 'mauve');
MyClass->pets; # Fido, Max, Spot, Toby
MySubClass->pets; # Fido, Max, Spot, Toby
MyClass->special_pets; # Max, Toby
MySubClass->special_pets; # Max, Toby
MySubClass->delete_special_pet_color('Max');
MyClass->pets; # Fido, Max, Spot, Toby
MySubClass->pets; # Fido, Max, Spot, Toby
MyClass->special_pets; # Max, Toby
MySubClass->special_pets; # Toby
=back
=head1 AUTHOR
John C. Siracusa (siracusa@gmail.com)
=head1 LICENSE
Copyright (c) 2006 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.
|