Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 105 lines (69 sloc) 3.158 kb

NAME

Perl 5 MOP - Syntax - Metadata

DESCRIPTION

A core component of this object system and (IMO) the key to getting a truly Perlish level of flexibility and extensibility, is the idea of metadata. Since this is a pretty over-used term, this document attempts to clarify exactly what this means.

It would be safe to say that what I am proposing is along the same lines as Python Decorators, C#/.NET Attributes and Java Annotations. Which is to say that this is metadata being declared at compile time and being used by the compiler to make certain decisions as it does its work.

However, unlike these other languages though, my proposed syntax is quite simple and should require nothing beyond what the Perl lexer can already understand.

Metadata (the expression)

A metadata expression is simply a Perl expression contained within a set of parentheses which, when evaluated, should result in metadata (the noun). Here are a few examples:

  ( is => 'rw', default => 100 )

  ( map { $_ => 1 } qw( lazy closed ) )

The context in which this metedata expression is evaluated in is somewhat tricky since it will happen during compile-time. However this is not all that different in complexity from how BEGIN and other compile time blocks are dealt with.

This metadata will be available as parameters to your meta classes and can be accessed by adding attributes.

Metadata (noun)

Metadata is the result of a metadata expression and simply a list of normal Perl values.

It will likely be the common case that it will be a list of key-value pairs (aka. Perl hash) but it should not be restricted to be just that. This is a judgement for the consumer of the metadata to make.

In later documents I will introduce three keywords; class, has and method. Each of these keywords should accept an optional metadata expression which would be feed to the underlying objects being constructed.

NOTES

In some ways I can see this as being some kind of general purpose mechanism, however it could get a little messy where the metadata is passed to the thing being annotated with the metadata. There would need to be an API for this and I believe that to be beyond the scope of these documents.

SEE ALSO

Expression evaluation at compile-time

https://www.metacpan.org/module/Memoize::Lift

Python Decorators

http://wiki.python.org/moin/PythonDecorators http://www.python.org/dev/peps/pep-0318/ http://www.artima.com/weblogs/viewpost.jsp?thread=240808

C# Attributes

http://msdn.microsoft.com/en-us/library/aa288059(v=VS.71).aspx

Java Annotations

http://download.oracle.com/javase/1,5.0/docs/guide/language/annotations.html http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations.html http://en.wikipedia.org/wiki/Java_annotation

AUTHOR

Stevan Little <stevan.little@iinteractive.com>

COPYRIGHT AND LICENSE

Copyright 2011 Infinity Interactive, Inc.

http://www.iinteractive.com

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

Something went wrong with that request. Please try again.