Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

105 lines (69 sloc) 3.158 kB


Perl 5 MOP - Syntax - Metadata


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.


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.


Expression evaluation at compile-time

Python Decorators

C# Attributes

Java Annotations,5.0/docs/guide/language/annotations.html


Stevan Little <>


Copyright 2011 Infinity Interactive, Inc.

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

Jump to Line
Something went wrong with that request. Please try again.