The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooX::ClassStash - Extra class information for Moo

VERSION

version 0.006

SYNOPSIS

  {
    package MyClass;
    use Moo;
    use MooX::ClassStash;

    has i => ( is => 'ro' );

    sub add_own_data { shift->class_stash->add_data(@_) }
    sub get_own_data { shift->class_stash->get_data(@_) }
  }

  # or with MooX

  {
    package MyClass;
    use MooX qw(
      ClassStash
    );
    ...
  }

  my $class_stash = MyClass->class_stash;
  # or MyClass->new->class_stash

  print $class_stash->get_attribute( i => 'is' ); # 'ro'

  $class_stash->add_attribute( j => (
    is => 'rw',
  ));

  print $class_stash->list_all_methods;
  print $class_stash->list_all_keywords;

  $class_stash->add_data( a => 1 ); # caller specific
  MyClass->add_own_data( a => 2 );

  print $class_stash->get_data('a'); # 1
  print MyClass->get_own_data('a'); # 2

DESCRIPTION

ATTRIBUTES

class

The name of the class for the class stash.

package_stash

The Package::Stash object of the given class.

attributes

HashRef of all the attributes set via "has" in Moo

data

HashRef with all the caller specific data stored.

keyword_functions

ArrayRef which contains all the functions which are marked as keywords.

METHODS

add_keyword_functions

If you dont use "add_keyword" for installing a keyword, you might need to call this function to add the names of the keyword functions yourself.

add_data

Adds data to your, caller specific, data context of the class. First parameter is the key, second parameter will be the value.

get_data

Get your, caller specific, data. If you give a parameter, if will only give back the value of this key. If none is given, you get the HashRef of all the data stored.

remove_data

Remove from your, caller specific, data the given key of the HashRef. There is no direct call to delete all the data at once.

add_keyword

Adds the given CodeRef as function to the package, but also add it to "keyword_functions" list, so that it gets excluded on method listings.

get_keyword

Get the CodeRef of the given keyword. Technical identical to "get_method".

has_keyword

Checks for the given keyword. Technical identical to "has_method".

remove_keyword

Remove the function from the package, but also remove it from "keyword_functions" list.

get_or_add_keyword

add_attribute

It is the same like calling "has" in Moo inside the package.

get_attribute

has_attribute

remove_attribute

If you want it, implement it... ;)

get_or_add_attribute

list_all_keywords

add_method

Add a method to the class.

get_method

Get the CodeRef of the given method name.

has_method

Checks if the given method exist.

remove_method

Delete the given method from the class.

get_or_add_method

list_all_methods

List all methods of the class. This method fetches all functions of the package and filters out the keywords from "keyword_functions".

after_method

Install an after modifier on the function given by the first parameter, with the CodeRef given as second parameter. See "after" in Moo.

before_method

Install a before modifier on the function given by the first parameter, with the CodeRef given as second parameter. See "before" in Moo.

around_method

Install an around modifier on the function given by the first parameter, with the CodeRef given as second parameter. See "around" in Moo.

AUTHOR

Torsten Raudssus <torsten@raudss.us>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Torsten Raudssus.

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