our %EXPORT_TAGS = (
assert => [qw(assert_64bit)],
- class => [qw(extends has)],
+ class => [qw(extends has list_attributes)],
clone => [qw(clone clone_nomagic)],
coercion => [qw(to_bool to_number to_string to_time to_tristate to_uuid)],
crypt => [qw(pad_pkcs7)],
'=~' => '!~',
'!~' => '=~',
);
+my %ATTRIBUTES;
=func load_xs
my $has_default = is_coderef $default;
my $has_coerce = is_coderef $coerce;
+ my $store = $args{store};
+ ($store, $name) = split(/\./, $name, 2) if $name =~ /\./;
+
my $caller = caller;
+ push @{$ATTRIBUTES{$caller} //= []}, $name;
+
no strict 'refs'; ## no critic (ProhibitNoStrict)
- if (my $store = $args{store}) {
+ if ($store) {
*{"${caller}::${name}"} = $is eq 'ro' && $has_default ? sub {
$_[0]->$store->{$name} //= scalar $default->($_[0]);
} : $is eq 'ro' ? sub {
sub is_uuid { defined $_[0] && !is_ref($_[0]) && length($_[0]) == 16 }
+=func list_attributes
+
+ @attributes = list_attributes($package);
+
+Get a list of attributes for a class.
+
+=cut
+
+sub list_attributes {
+ my $package = shift;
+ return @{$ATTRIBUTES{$package} // []};
+}
+
=func load_optional
$package = load_optional($package);