To be fare, Mouse can do it as well. And Moo too (but not with support of Moose Meta Object Protocol).
понедельник, 5 февраля 2018 г., 21:13:19 UTC+3 пользователь Charlie Brady написал: > > > 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 < > > dshadow...@gmail.com <javascript:>> 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...@googlegroups.com <javascript:>. > > > To post to this group, send email to mojol...@googlegroups.com > <javascript:>. > > > Visit this group at https://groups.google.com/group/mojolicious. > > > For more options, visit https://groups.google.com/d/optout. > > > > > > > > -- 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.