1 package Graph
::Attribute
;
6 sub _COMPAT02
() { 0x00000001 }
11 my $caller = caller(0);
12 if (exists $attr{array
}) {
15 *{"${caller}::_get_attributes"} = sub { $_[0]->[ $i ] };
16 *{"${caller}::_set_attributes"} =
17 sub { $_[0]->[ $i ] ||= { };
18 $_[0]->[ $i ] = $_[1] if @_ == 2;
20 *{"${caller}::_has_attributes"} = sub { defined $_[0]->[ $i ] };
21 *{"${caller}::_delete_attributes"} = sub { undef $_[0]->[ $i ]; 1 };
22 } elsif (exists $attr{hash
}) {
25 *{"${caller}::_get_attributes"} = sub { $_[0]->{ $k } };
26 *{"${caller}::_set_attributes"} =
27 sub { $_[0]->{ $k } ||= { };
28 $_[0]->{ $k } = $_[1] if @_ == 2;
30 *{"${caller}::_has_attributes"} = sub { defined $_[0]->{ $k } };
31 *{"${caller}::_delete_attributes"} = sub { delete $_[0]->{ $k } };
33 die "Graph::Attribute::import($package @_) caller $caller\n";
35 my @api = qw(get_attribute
44 get_attribute_values);
45 if (exists $attr{map}) {
48 my ($first, $rest) = ($api =~ /^(\w+?)_(.+)/);
50 *{"${caller}::${first}_${map}_${rest}"} = \
&$api;
59 my $p = $g->_set_attributes;
67 my $p = $g->_set_attributes( $a );
74 my $p = $g->_get_attributes;
75 $p ?
exists $p->{ $a } : 0;
80 $g->_get_attributes ?
1 : 0;
86 my $p = $g->_get_attributes;
87 $p ?
$p->{ $a } : undef;
90 sub delete_attribute
{
93 my $p = $g->_get_attributes;
102 sub delete_attributes
{
104 if ($g->_has_attributes) {
105 $g->_delete_attributes;
112 sub get_attribute_names
{
114 my $p = $g->_get_attributes;
115 defined $p ?
keys %{ $p } : ( );
118 sub get_attribute_values
{
120 my $p = $g->_get_attributes;
121 defined $p ?
values %{ $p } : ( );
126 my $a = $g->_get_attributes;
127 ($g->[ _F
] & _COMPAT02
) ?
(defined $a ?
%{ $a } : ()) : $a;