The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Evo::Class::Meta

VERSION

version 0.0405

SYNOPSYS

  use Evo;
  {

    package Foo::Bar;
    use Evo::Class;
  }

  say Foo::Bar->META;
  say Foo::Bar->META->attrs;
  say $Foo::Bar::EVO_CLASS_META;
  say $Foo::Bar::EVO_CLASS_META->attrs;
  say $Foo::Bar::EVO_CLASS_META->{attrs};

  Foo::Bar->META->reg_attr('foo');
  use Data::Dumper;
  say Dumper (Foo::Bar->META->attrs->slots);

METHODS

register

Register a meta instance only once. The second invocation will return the same instance. But if it will be called from another subclass, die. This is a protection from the fool

Meta is stored in $Some::Class::EVO_CLASS_META global variable and lives as long as a package.

attrs

Returns an inctance of attributes generator Evo::Class::Attrs

IMPLEMENTATION NOTES

overridden

"overridden" means this symbol will be skept during "extend_with" so if you marked something as overridden, you should define method or sub yourself too. This is not a problem with sub foo : Over {} or "reg_attr_over" because it marks symbol as overridden and also registers a symbol.

BUT!!! "reg_attr_over" should be called

private

Mark something as private (even if it doesn't exist) to skip at from "public_*". But better use my sub foo {} feature

reg_method

All methods compiled in the class are public by default. But what to do if you make a method by monkey-patching or by extending? Use /reg_method

  package Foo;
  use Evo 'Scalar::Util(); -Class::Meta';
  my $meta = Evo::Class::Meta->register(__PACKAGE__);

  no warnings 'once';
  *lln = \&Scalar::Util::looks_like_number;

  # nothing, because lln was compiled in Scalar::Util
  say $meta->public_methods;

  # fix this
  $meta->reg_method('lln');
  say $meta->public_methods;

check_implementation

If implementation requires "attribute", "reg_attr" should be called before checking implementation

mark_as_private

If you want to hide method, you should use my sub feature. But sometimes this also will help. It doesn't hide you method from being executed, it hides it from inheritance

  package Foo;
  use Evo -Class;
  sub foo { }

  local $, = ' ';
  say 'LIST: ', META->public_methods;

  META->mark_as_private('foo');    # hide foo
  say 'LIST: ', META->public_methods;

But foo is still available via Foo::->foo

DUMPING (EXPERIMENTAL)

  package My::Foo;
  use Evo -Class;
  has 'foo';

  use Data::Dumper;
  say Dumper __PACKAGE__->META->info;

AUTHOR

alexbyk.com

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by alexbyk.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.