On Mon, 5 Feb 2018, Dan Book wrote:

> Introspection capabilities are a feature of Moose.

Moose, however, adds many, many more dependencies than Mojo::Base...

> 
> On Mon, Feb 5, 2018 at 5:14 AM, Konstantin Cherednichenko <
> [email protected]> 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 [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.
> >
> 
> 

Reply via email to