Tobias Tacke

NAME

Fukurama::Class::Attributes - Pragma like module to extend code attributes

VERSION

Version 0.01 (beta)

SYNOPSIS

 package MyAttributeClass;
 sub MyFirstCodeAttribute {
        my $class = $_[0];
        my $subroutine_data = $_[1];
        
        ... do some checks or what you want ...
        
        return;
 }
 sub check_inheritation {
        my $class = $_[0];
        my $method_name = $_[1];
        my $parent_class = $_[2];
        my $child_class = $_[3];
        my $inheritation_type = $_[4];
        
        return;
 }
 
 package MyClass;
 BEGIN {
        use Fukurama::Class::Attributes();
        Fukurama::Class::Attributes->add_attribute_handler('MyAttributeClass');
 }
 use Fukurama::Class::Attributes;
 sub my_method : Method(static|void|) {
        return;
 }
 sub other_sub : MyFirstCodeAttribute() {
        ...
 }

DESCRIPTION

This pragma-like module provides functions to extend code attributes for yourself and check the inheritation. It includes Fukurama::Attributes::OOStandard, which enables Method and Constructor definitoins for subroutines. Use Fukurama::Class instead, to get all the features for OO.

CONFIG

You can disables all checks, which includes syntax and inheritation check by saying:

$Fukurama::Class::Attributes::CHECK_LEVEL = $Fukurama::Class::Attributes::LEVEL_CHECK_NONE;

EXPORT

-

METHODS

add_attribute_handler( handler_class:CLASS ) return:BOOLEAN

Add all defined attribute-methods of the given class, so you can use their code attributes in all of your subroutines. See section "CREATE AN OWN ATTRIBUTE CLASS" for the rules.

remove_attribute_handler( handler_class:CLASS ) return:BOOLEAN

Remove all defined attribute-methods of the given class, so you can't use their anymore as code attributes.

register_class( export_to_class:CLASS ) return:BOOLEAN

Export all code attributes to the given class so you can use all registered code attributes in there. Every child of the given class can even use this behavior.

run_check( ) return:VOID

Helper method for static perl (see Fukurama::Class > BUGS) Its calls Fukurama::Class::AttributeHandler->run_check(), which check the correct syntax of all registered code attributes and check some defined conventions.

E.g. for code attribute Method: it will check that the access level of child class methods are the same or stricter than the parent class method.

CREATE AN OWN ATTRIBUTE CLASS

An "attribute class" describe one (or many) code attributes, which you can use like my_method : MyNewCodeAttribute(Foo) {...} There are the following rules for the class-methods:

-Every Attribute has to start with an uppercase letter

-Only on other method can be there, the subroutine check_inheritation()

-All these methods have to be void

Attribute methods take on parameter, a hash reference, which contain informations about the method, which uses the actual code-attribute. For every subroutine which contains this code attribute, the corresponding method in your attribute class would be called. The parameter contain the following data:

 resolved       => BOOLEAN, # the subroutine is resolved (only internal use to avoid calls without the name of the subroutine)
 data           => STRING,  # the attribute-data. If you say B<sub get : Method(public||)> it youd contain B<public||>
 sub_name       => STRING,  # the name of the subroutine, which call this attribute
 executed       => BOOLEAN, # this attribute for this subroutine is allways called (only internal use to avoid double callings)
 attribute      => STRING,  # the name of the attribute. Its the same like the name of your code-attribute-method.
 handler        => HASHREF, # Contain a reference to your code-attribute method and class. Only for internal use.
 sub            => CODEREF, # The code referense of the subroutine, which contain the code attribute.
 class          => STRING,      # The class in which the subroutine is declared, which contain the code attribute.
 

There are many things which you can do with code attributes, e.g. the Method and Constructor definitions from Fukurama::Class::Attributes::OOStandard or some simple things like in Catalyst. So, do what you need.

The check_inheritation() method is optional, check the code attribute inheritation for each class and take the following parameters:

 $method_name  : STRING # the methodname which is checked
 $parent_class : STRING # the parent class of the actual checked class
 $child_class  : STRING # the actual checked class
 $inheritation_type : STRING # the type of inheritation. extend is standard, implement even exists
 

With this method you can compare every subroutine, which contain a code attribute, with all parents. If you use multi inheritation or interfaces there can be more than one parent. And it even compares in the same way all grandparents etc.

AUTHOR, BUGS, SUPPORT, ACKNOWLEDGEMENTS, COPYRIGHT & LICENSE

see perldoc of Fukurama::Class