Apparently introspection isn't part of the API
see attributes, Attribute::Handlers
#!/usr/bin/perl --
package Foo; BEGIN {
use Scalar::Util qw( refaddr );
our %attrs;
sub MODIFY_SCALAR_ATTRIBUTES {
print "Foo::MODIFY_SCALAR_ATTRIBUTES! @_\n";
my($package, $scalarref, @attrs) = @_;
$attrs{ refaddr $scalarref } = \@attrs;
return;
}
sub FETCH_SCALAR_ATTRIBUTES {
print "Foo::FETCH_SCALAR_ATTRIBUTES! @_\n";
my($package, $scalarref) = @_;
my $attrs = $attrs{ refaddr $scalarref };
return $attrs ? @$attrs : ();
}
sub new {
print "Foo::new! @_\n";
my $class = shift;
return bless { yo => [@_] }, $class ;
}
}
use strict; use warnings;
use attributes();
use Data::Dump;
my Foo $bar : WHAT = 24;
my Foo $ey = 42;
my Foo $new :AND :CHEWY = Foo->new( 42 );
print "\n\n";
for my $ref( \$bar, \$ey, \$new ){
dd $ref;
dd [ attributes::get($ref) ];
dd [ attributes::_fetch_attrs($ref) ];
#~ use Devel::Peek;Dump( $ref );
print "\n\n";
}
dd \%Foo::attrs;
__END__
Foo::MODIFY_SCALAR_ATTRIBUTES! Foo SCALAR(0x9c8284) WHAT
Foo::new! Foo 42
Foo::MODIFY_SCALAR_ATTRIBUTES! Foo SCALAR(0xa3358c) AND CHEWY
\24
Foo::FETCH_SCALAR_ATTRIBUTES! Foo SCALAR(0x9c8284)
["WHAT"]
[]
\42
Foo::FETCH_SCALAR_ATTRIBUTES! Foo SCALAR(0x99aa3c)
[]
[]
\bless({ yo => [42] }, "Foo")
[]
[]
{ 10257028 => ["WHAT"], 10696076 => ["AND", "CHEWY"] }
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|