Not quite sure what to call such a module, but I just wrote a proof of 
concept 
here: https://gist.github.com/jhthorsen/0ad4c5c84661588e89da910a08460e88


On Monday, February 5, 2018 at 11:14:06 AM UTC+1, Konstantin Cherednichenko 
wrote:
>
> 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 mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to