Hello!
Is there any easy way to get all attributes names?
I tried to get it via ISA but I also got methods names... I just want to
get "propA" and "propB"...
Could someone please help me?
My example:
#!/usr/bin/env perl
package A;
use Mojo::Base -base;
has propA => 123;
has propB => 'val';
sub get_props_names
{
my $self = shift;
my %names = ();
{
my $base_class = ref($self);
no strict 'refs';
foreach my $class ($base_class, @{"${base_class}::ISA"})
{
foreach my $name (keys %{"${class}::"})
{
$names{$name} ||= 1;
}
}
};
return [sort keys %names];
}
package main;
use Mojo::Base -strict;
use Data::Dumper;
my $obj = A->new;
say Dumper($obj->get_props_names);
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.