http://www.perlmonks.org?node_id=994149


in reply to Detecting declaration type?

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"] }