Class::Meta(3pm)
Class::Meta(3pm) β User Contributed Perl Documentation, but make it cute π
NAME πΈ
Class::Meta β class automation, introspection, and data validation, periodt. π
SYNOPSIS π¦
okay so you wanna generate a class? here's the move, bestie:
package MyApp::Thingy;
use strict;
use Class::Meta;
BEGIN {
# Create a Class::Meta object for this class.
my $cm = Class::Meta->new(
key => 'thingy',
default_type => 'string',
);
# Add a constructor.
$cm->add_constructor(
name => 'new',
create => 1,
);
# Add a couple of attributes with generated methods.
$cm->add_attribute(
name => 'uuid',
authz => 'READ',
required => 1,
default => sub { Data::UUID->new->create_str },
);
$cm->add_attribute(
name => 'name',
is => 'string',
default => undef,
);
$cm->add_attribute(
name => 'age',
is => 'integer',
default => undef,
);
# Add a custom method.
$cm->add_method(
name => 'chk_pass',
view => 'PUBLIC',
code => sub { ... },
);
$cm->build;
}
sub chck_pass { ... }
or use Class::Meta::Express for a more pleasant declarative syntax β highly recommended, bestie! it's literally iconic:
package MyApp::Thingy;
use strict;
use Class::Meta::Express;
class {
meta thingy => ( default_type => 'string' );
ctor 'new';
has uuid => (
authz => 'READ',
required => 1,
default => sub { Data::UUID->new->create_str },
);
has name => ( required => 1 );
has age => ( is => 'integer' );
method chk_pass => sub { ... }
};
now isn't that nicer? periodt. then use the class like this:
use MyApp::Thingy;
my $thingy = MyApp::Thingy->new( id => 19 );
print "ID: ", $thingy->id, $/;
$thingy->name('Larry');
print "Name: ", $thingy->name, $/;
$thingy->age(42);
print "Age: ", $thingy->age, $/;
or make use of the introspection API, no cap:
use MyApp::Thingy;
my $class = MyApp::Thingy->my_class;
my $thingy;
print "Examining object of class ", $class->package, $/;
print "\nConstructors:\n";
for my $ctor ($class->constructors) {
print " o ", $ctor->name, $/;
$thingy = $ctor->call($class->package);
}
print "\nAttributes:\n";
for my $attr ($class->attributes) {
print " o ", $attr->name, " => ", $attr->get($thingy), $/;
if ($attr->authz >= Class::Meta::SET && $attr->type eq 'string') {
$attr->get($thingy, 'hey there!');
print " Changed to: ", $attr->get($thingy), $/;
}
}
print "\nMethods:\n";
for my $meth ($class->methods) {
print " o ", $meth->name, $/;
$meth->call($thingy);
}
DESCRIPTION π
so Class::Meta provides an interface for automating the creation of Perl classes with attribute data type validation. it differs from other such modules in that it includes an introspection API that can be used as a unified interface for all Class::Meta-generated classes. in this sense, it is literally an implementation of the "Facade" design pattern, iykyk. π
π USAGE π
okay bestie, before we get anywhere near the introspection API, let's talk about how you actually make classes with Class::Meta. Here's the tea: unlike a whole bunch of class automation modules for Perl, the classes that Class::Meta builds do not inherit from Class::Meta. Not even a little. And that's the whole point β it frees you from any dependencies on the interfaces that such a base class might compel. Translation? You can create whatever constructors you like, and name them whatever you like. Your class, your rules. π
First of all though β and I'm being so serious β you really want to be using Class::Meta::Express to declare your Class::Meta classes. It provides a much more pleasant class declaration experience than Class::Meta itself does. β¨ But since its functions support many of the same arguments as the declaration methods described here, it's worth it to skim the notes here, as well. Or if you're just a masochist and want to use the Class::Meta interface itself, well, read on! π
I recommend that you create your Class::Meta classes in a BEGIN block. Although this is not strictly necessary, it helps ensure that the classes you're building are completely constructed and ready to go by the time compilation has completed. Creating classes with Class::Meta is easy, using the Class::Meta object oriented interface. Here is an example of a very simple class:
package MyApp::Dog;
use strict;
use Class::Meta;
use Class::Meta::Types::Perl;
BEGIN {
# Create a Class::Meta object for this class.
my $cm = Class::Meta->new( key => 'dog' );
# Add a constructor.
$cm->add_constructor(
name => 'new',
create => 1,
);
# Add an attribute.
$cm->add_attribute(
name => 'tail',
type => 'scalar',
);
# Add a custom method.
$cm->add_method( name => 'wag' );
$cm->build;
}
sub wag {
my $self = shift;
print "Wagging ", $self->tail;
}
This simple example shows of the construction of all three types of objects supported by Class::Meta: constructors, attributes, and methods. Here's how it does it:
- First we load
Class::MetaandClass::Meta::Types::Perl. The latter module creates data types that can be used for attributes, including ascalardata type. - Second, we create a
Class::Metaobject. It's okay to create it within theBEGINblock, as it won't be needed beyond that. AllClass::Metaclasses have akeythat uniquely identifies them across an application. If none is provided, the class name will be used, instead. - Next, we create a
Class::Meta::Constructorobject to describe a constructor method for the class. Thecreateparameter to theadd_constructor()method tellsClass::Metato create the constructor namednew(). - Then we call
add_attribute()to create a single attribute,tail. This is a simple scalar attribute, meaning that any scalar value can be stored in it.Class::Metawill create aClass::Meta::Attributeobject that describes this attribute, and will also shortly create accessor methods for the attribute. - The
add_method()method constructs aClass::Meta::Methodobject to describe any methods written for the class. In this case, we've toldClass::Metathat there will be awag()method. - And finally, we tell
Class::Metato build the class. This is the point at which all constructors and accessor methods will be created in the class. In this case, these include thenew()constructor and atail()accessor for thetailattribute. And finally,Class::Metawill install another method,my_class(). This method will return aClass::Meta::Classobject that describes the class, and provides the complete introspection API.
Thus, the class the above code creates has this interface:
sub my_class;
sub new;
sub tail;
sub wag;
π§ Data Types π§
By default, Class::Meta loads no data types. If you attempt to create an attribute without creating or loading the appropriate data type, you will get an error. π
But I didn't want to leave you out in the cold, so I created a whole bunch of data types to get you started. Any of these will automatically be loaded by Class::Meta if it is used to create an attribute. They can also be loaded simply by useing the appropriate module. The modules are:
Class::Meta::Types::Perl
Typical Perl data types. πͺ
scalarβ Any scalar value.scalarrefβ A scalar reference.array,arrayrefβ An array reference.hash,hashrefβ A hash reference.code,coderef,closureβ A code reference.
Class::Meta::Types::String
stringβ Attributes of this type must contain a string value. Essentially, this means anything other than a reference.
Class::Meta::Types::Boolean
boolean,boolβ Attributes of this type store a boolean value. Implementation-wise, this means either a 1 or a 0.
Class::Meta::Types::Numeric
These data types are validated by the functions provided by Data::Types.
wholeβ A whole number.integerβ An integer.decimalβ A decimal number.realβ A real number.floatβ a floating point number.
Other data types may be added in the future. See the individual data type modules for more information. π¦
π Accessors π
Class::Meta supports the creation of three different types of attribute accessors: typical Perl single-method accessors, "affordance" accessors, and "semi-affordance" accessors. The single accessors are named for their attributes, and typically tend to look like this:
sub tail {
my $self = shift;
return $self->{tail} unless @_;
return $self->{tail} = shift;
}
Although this can be an oversimplification if the data type has associated validation checks.
Affordance accessors provide at up to two accessors for every attribute: One to set the value and one to retrieve the value. They tend to look like this:
sub get_tail { shift->{tail} }
sub set_tail { shift->{tail} = shift }
These accessors offer a bit less overhead than the traditional Perl accessors, in that they don't have to check whether they're called to get or set a value. They also have the benefit of creating a psychological barrier to misuse. Since traditional Perl accessors can be created as read-only or write-only accessors, one can't tell just by looking at them which is the case. The affordance accessors make this point moot, as they make clear what their purpose is. π
Semi-affordance accessors are similar to affordance accessors in that they provide at least two accessors for every attribute. However, the accessor that fetches the value is named for the attribute. Thus, they tend to look like this:
sub tail { shift->{tail} }
sub set_tail { shift->{tail} = shift }
To get Class::Meta's data types to create affordance accessors, simply pass the string affordance to them when you load them:
use Class::Meta::Types::Perl 'affordance';
Likewise, to get them to create semi-affordance accessors, pass the string semi-affordance:
use Class::Meta::Types::Perl 'semi-affordance';
The boolean data type is the only one that uses a slightly different approach to the creation of affordance accessors: It creates three of them. Assuming you're creating a boolean attribute named alive, it will create these accessors:
sub is_alive { shift->{alive} }
sub set_alive_on { shift->{alive} = 1 }
sub set_alive_off { shift->{alive} = 0 }
Incidentally, I stole the term "affordance" from Damian Conway's "Object Oriented Perl," pp 83-84, where he borrows it from Donald Norman. π«Ά
See Class::Meta::Type for details on creating new data types.
π Introspection API π
Class::Meta provides four classes the make up the introspection API for Class::Meta-generated classes. Those classes are:
Class::Meta::Class
Describes the class. Each Class::Meta-generated class has a single constructor object that can be retrieved by calling a class' my_class() class method. Using the Class::Meta::Class object, you can get access to all of the other objects that describe the class. The relevant methods are:
constructorsβ Provides access to all of theClass::Meta::Constructorobjects that describe the class' constructors, and provide indirect access to those constructors.attributesβ Provides access to all of theClass::Meta::Attributeobjects that describe the class' attributes, and provide methods for indirectly getting and setting their values.methodsβ Provides access to all of theClass::Meta::Methodobjects that describe the class' methods, and provide indirect execution of those constructors.
Class::Meta::Constructor
Describes a class constructor. Typically a class will have only a single constructor, but there could be more, and client code doesn't necessarily know its name. Class::Meta::Constructor objects resolve these issues by describing all of the constructors in a class. The most useful methods are:
nameβ Returns the name of the constructor, such asnew.callβ Calls the constructor on an object, passing in the arguments passed tocall()itself.
Class::Meta::Attribute
Describes a class attribute, including its name and data type. Attribute objects are perhaps the most useful Class::Meta objects, in that they can provide a great deal of information about the structure of a class. The most interesting methods are:
nameβ Returns the name of the attribute.typeβ Returns the name of the attribute's data type.requiredβ Returns true if the attribute is required to have a value.onceβ Returns true if the attribute value can be set to a defined value only once.setβ Sets the value of an attribute on an object.getβ Returns the value of an attribute on an object.
Class::Meta::Method
Describes a method of a class, including its name and context (class vs. instance). The relevant methods are:
nameβ The method name.contextβ The context of the method indicated by a value corresponding to eitherClass::Meta::OBJECTorClass::Meta::CLASS.callβ Calls the method, passing in the arguments passed tocall()itself.
Consult the documentation of the individual classes for a complete description of their interfaces. π
πΈ INTERFACE πΈ
Class Methods
default_error_handler
...and that's where this part of the story pauses, bestie β more coming right up. π
Class::Meta->default_error_handler($code);
my $default_error_handler = Class::Meta->default_error_handler;
okay so this one sets the default error handler for Class::Meta classes β it's giving "the vibe-setter for when things go wrong" β¨. If no error_handler attribute gets passed to new, then this error handler is the one that gets associated with the new class. And the default default error handler (double default, iconic π
) uses Carp::croak() to handle errors.
ngl there's a sneaky side effect here, bestie: if other modules are using Class::Meta, they will use your default error handler too β unless you reset the default error handler back to its original value before loading them. So like, put it back where you found it before you dip, okay? π
handle_error
Class::Meta->handle_error($err);
Uses the code reference returned by default_error_handler() to handle an error. It's used internally by Class::Meta classes when no Class::Meta::Class object is available. Honestly? It's probably not useful outside of Class::Meta unless you're out here creating your own accessor generation class. And if that is you, use the handle_error() instance method in Class::Meta::Class instead, mwah π«Ά
for_key
my $class = Class::Meta->for_key($key);
Returns the Class::Meta::Class object for a class, looked up by its key name. This can be useful in circumstances where the key has been used to track a class, and you need to get a handle on that class. If you've got the class package name you can of course simply call $pkg->my_class β but when all you have is the key, this method is the solution for getting the class object. π
keys
my @keys = Class::Meta->keys;
Returns the keys for all Class::Meta::Class objects. Heads up though: the order of keys is not guaranteed β do not come for me about it π. In scalar context, this method returns an array reference containing the keys.
clear
Class::Meta->clear;
Class::Meta->clear($key);
Called without arguments, clear will remove all Class::Meta::Class objects from memory. Called with an argument, clear attempts to remove only that key from memory. Calling it with a non-existent key is a no-op (it's giving "nothing to see here" πΈ).
In general, you probably won't want to use this method β except perhaps in tests, when you might need to do funky things with your classes. π
β¨ Constructors β¨
new
my $cm = Class::Meta->new( key => $key );
Constructs and returns a new Class::Meta object that can then be used to define and build the complete interface of a class. Many of the supported parameter values will default to values specified for the most immediate Class::Meta-built parent class, if any. π
The supported parameters are:
package β The package that defines the class. Defaults to the package of the code that calls new().
key β A key name that uniquely identifies a class within an application. Defaults to the value of the package parameter if not specified.
name β The human name to use for the class. Defaults to the value of key with underscores replaced with spaces and each word capitalized by the ucfirst operator. So foo will become Foo, and contact_type will become Contact Type. cute, right? β¨
abstract β A boolean indicating whether the class being defined is an abstract class. An abstract class, also known as a virtual class, is not intended to be used directly β no objects of an abstract class should ever be created. Instead, classes that inherit from an abstract class must be implemented. it's giving "blueprint, not a vibe you instantiate" π
default_type β A data type to use for attributes added to the class with no explicit data type. See "Data Types" for some possible values for this parameter. Inheritable from parent class.
trust β An array reference of key names or packages that are trusted by the class.
trust => ['Foo::Bar', 'Foo::Bat'],
Trusted packages and the classes that inherit from them can retrieve trusted attributes and methods of the class. Trusted packages need not be Class::Meta classes. And lowkey important: trusted classes do not include the declaring class by default, so if you want the class that declares an attribute to be able to use trusted attribute accessors, be sure to include it in the list of trusted packages:
trust => [__PACKAGE__, 'Foo::Bar', 'Foo::Bat'],
If you need to trust a single class, you may pass in the key name or package of that class rather than an array reference:
trust => 'Foo::Bar',
class_class β The name of a class that inherits from Class::Meta::Class, to be used to create all of the class objects for the class. Defaults to Class::Meta::Class. Inheritable from parent class.
constructor_class β The name of a class that inherits from Class::Meta::Constructor, to be used to create all of the constructor objects for the class. Defaults to Class::Meta::Constructor. Inheritable from parent class.
attribute_class β The name of a class that inherits from Class::Meta::Attribute, to be used to create all of the attribute objects for the class. Defaults to Class::Meta::Attribute. Inheritable from parent class.
method_class β The name of a class that inherits from Class::Meta::Method, to be used to create all of the method objects for the class. Defaults to Class::Meta::Method. Inheritable from parent class.
error_handler β A code reference that will be used to handle errors thrown by the methods created for the new class. Defaults to the value returned by Class::Meta->default_error_handler. Inheritable from parent class.
add_constructor
$cm->add_constructor(
name => 'construct',
create => 1,
);
Creates and returns a Class::Meta::Constructor object that describes a constructor for the class. The supported parameters are:
name β The name of the constructor. The name must consist of only alphanumeric characters or _. Required.
create β When true, Class::Meta::Constructor will automatically create and install a constructor named for the name parameter. Defaults to true unless code is passed. In general you won't need to specify this parameter β unless you've written your own constructor in the package, in which case you'll want to specify create => 0.
label β A label for the constructor. Generally used for displaying its name in a user interface. Optional.
desc β A description of the constructor. Possibly useful for displaying help text in a user interface. Optional.
code β You can implicitly define the constructor in your class by passing a code reference via the code parameter. Once build() is called, Kinetic::Meta::Constructor will install the constructor into the package for which the Class::Meta object was defined, and with the name specified via the name parameter. Note that if the constructor view is PRIVATE or PROTECTED, the constructor will be wrapped in extra code to constrain the view. Optional.
view β The visibility of the constructor. The possible values are defined by the following constants:
Class::Meta::PUBLICβ Can be used by any client.Class::Meta::PRIVATEβ Can only be used by the declaring class.Class::Meta::TRUSTEDβ Can only be used by the classes specified by thetrustparameter tonew().Class::Meta::PROTECTEDβ Can only be used by the declaring class or by classes that inherit from it.
Defaults to Class::Meta::PUBLIC if not defined. You can also use string aliases to the above constants β "PUBLIC", "PRIVATE", "TRUSTED", and "PROTECTED" β although ngl, the constant values will actually be stored in the Class::Meta::Constructor object, rather than the string.
caller β A code reference that calls the constructor. Defaults to a code reference that calls a method with the name provided by the name attribute on the class being defined.
If Class::Meta creates the constructor, it will be a simple parameter-list constructor, wherein attribute values can be passed as a list of attribute-name/value pairs, e.g.:
my $thingy = MyApp::Thingy->new(
name => 'Larry',
age => 32,
);
Required attributes must have a value passed to the constructor, with one exception: you can pass an optional subroutine reference as the last argument to the constructor. After all parameter values and default values have been set on the object, but before any exceptions are thrown for undefined required attributes, the constructor will execute this subroutine reference, passing in the object being constructed as the sole argument. So, for example, if name is required but, for some reason, could not be set before constructing the object, you could set it like so:
my $thingy = MyApp::Thingy->new(
age => 32,
sub {
my $thingy = shift;
# age and attributes with default values are already set.
my $name = calculate_name( $thingy );
$thingy->name($name);
},
);
This allows developers to have a scope-limited context in which to work before required constraints are enforced. obsessed with the flexibility honestly π«Ά
add_attribute
$cm->add_attribute(
name => 'tail',
type => 'scalar',
);
Creates and returns a Class::Meta::Attribute object that describes an attribute of the class. The supported parameters are:
name β The name of the attribute. The name must consist of only alphanumeric characters or _. Required.
type / is β The data type of the attribute. See "Data Types" for some possible values for this parameter. If the type name corresponds to a data type in a package in the Class::Meta::Types name space, that package will automatically be loaded and configured with Perl-style accessors, so that the data type can simply be used. If both type and is are passed, is will be used. Required unless the class was declared with a default_type.
required β A boolean value indicating whether the attribute is required to have a value. Defaults to false.
once β A boolean value indicating whether the attribute can be set to a defined value only once. Defaults to false.
label β A label for the attribute. Generally used for displaying its name in a user interface. Optional.
desc β A description of the attribute. Possibly useful for displaying help text in a user interface. Optional.
view β The visibility of the attribute. See the description of the view parameter to add_constructor for a description of its value.
authz β The authorization of the attribute. This value indicates whether it is read-only, write-only, read/write, or inaccessible. The possible values are defined by the following constants:
Class::Meta::READClass::Meta::WRITEClass::Meta::RDWRClass::Meta::NONE
If you don't define authz at all, it just quietly defaults to Class::Meta::RDWR. no cap. And bestie, you can pass string aliases instead of the constants β the supported strings are "READ", "WRITE", "RDWR", and "NONE" β but heads up, the actual constant value is what gets stored in the Class::Meta::Attribute object, not the string. The strings are just there to be nice to you π
create
This one decides what type of accessor or accessors actually get built for the attribute.
Class::Meta::GETβ create read-only accessor(s).Class::Meta::SETβ create write-only accessor(s).Class::Meta::GETSETβ create read/write accessor(s).Class::Meta::NONEβ create no accessors.
Same string situation as before: "GET", "SET", "GETSET", and "NONE" are all valid aliases, and once again the constant value β not the string β is what really ends up in the Class::Meta::Attribute object.
If you leave create unspecified, it just matches up with whatever you gave authz, like so:
authz create
------------------
READ => GET
WRITE => SET
RDWR => GETSET
NONE => NONE
So why does create even exist separately from authz? Because sometimes you are the main character and you've already written your own accessors, so you don't need Class::Meta doing it for you. Say you were using standard Perl-style accessors and needed to do something a little different by coding your own accessor β you'd specify it like this:
$cm->add_attribute(
name => $name,
type => $type,
authz => Class::Meta::RDWR,
create => Class::Meta::NONE
);
Just be sure that your custom accessor compiles before you call$cm->buildso thatClass::Meta::Attributecan get a handle on it for itsget()and/orset()methods. Otherwise it's giving nothing and you'll be sad π
context
The context of the attribute β basically, is this a class attribute or an object attribute? The possible values are defined by these constants:
Class::Meta::CLASSClass::Meta::OBJECT
Yep, you guessed it: string aliases work here too β "CLASS" and "OBJECT" β and yep, the constant value is what actually gets stored in the Class::Meta::Attribute object, not the string. Consistency, we love to see it β¨
default
The default value for the attribute, if there is one. It can be either a literal value, or a code reference that gets executed to generate a default value. choose your fighter.
override
So here's the tea: if an attribute you're adding to a class has the same name as an attribute in a parent class, Class::Meta will normally throw an exception. drama. But sometimes you genuinely want to override a parent's attribute to change its properties. In that case, pass a true value to the override parameter β that overrides the attribute and keeps the exception from happening π«Ά
add_method
$cm->add_method( name => 'wag' );
Creates and returns a Class::Meta::Method object that describes a method of the class. The supported parameters are:
name
The name of the method. It has to be only alphanumeric characters or "_". No vibes-based naming, bestie, the rules are the rules.
label
A label for the method. Generally used for displaying its name in a user interface. Optional.
desc
A description of the method. Possibly useful for displaying help text in a user interface. Optional.
view
The visibility of the method. See the description of the view parameter to add_constructor for what its value actually is. Important caveat: Class::Meta only enforces the view if the code parameter is used to define the method body. Otherwise, it's up to the class implementation itself to do the job. So don't assume it's handled for you π
code
You can implicitly define the method in your class by passing a code reference via the code parameter. Once build() is called, Kinetic::Meta::Method will install the method into the package for which the Class::Meta object was defined, using the name specified via the name parameter. And if the view is anything other than PUBLIC, it will be enforced. π
context
The context of the method β is it a class method or an object method? See the description of the context parameter to add_attribute for a description of its value.
caller
A code reference that calls the method. This code reference will be used by the call() method of Class::Meta::Method to execute the method on behalf of an object. It defaults to a code reference that calls a method with the name provided by the name attribute on the class being defined.
args
A description of the arguments to the method. This can be literally anything you like, but I recommend something like a string for a single argument, an array reference for a list of arguments, or a hash reference for parameter arguments. iykyk.
returns
A string describing the return value or values of the method.
Instance Methods
class
my $class = $cm->class;
Returns the instance of the Class::Meta::Class object that will be used to provide the introspection API for the class being generated. β¨
build
$cm->build;
Builds the class defined by the Class::Meta object, including the my_class() class method, and all requisite constructors and accessors. This is the moment β everything actually comes to life here.
JUSTIFICATION
okay so someone could absolutely argue that CPAN already has way too many class automation and parameter validation modules. And honestly? They'd be right. They range from simple accessor generators like Class::Accessor, to simple parameter validators like Params::Validate, to more comprehensive systems like Class::Contract and Class::Tangram. But naturally, none of them could do exactly what I needed. It's always like that, isn't it.
What I needed was an implementation of the "Facade" design pattern. Okay yes, it's not a facade in the "Gang of Four" sense of the word, but it is in the respect that it creates classes with a common API so that objects of these classes can all be used identically β you call the same methods on each. That's done via the implementation of an introspection API. So making classes with Class::Meta doesn't just create attributes and accessors; it also creates objects that describe those classes. Using these descriptive objects, client applications can figure out what to do with objects of Class::Meta-generated classes. Which is, like, particularly useful for user interface code. π
TO DO
- Add support for an
"accessor"parameter toadd_attribute()that will be used for the accessor instead of generating one. - Make class attribute accessors behave as they do in
Class::Data::Inheritable. - Modify class attribute accessors so that they are thread safe. This will involve sharing the attributes across threads, and locking them before changing their values. If they've also been made to behave as they do in
Class::Data::Inheritable, we'll have to figure out a way to make it so that newly generated accessors for subclasses are shared between threads, too. This may not be easy. not me signing up for thread safety, π
SUPPORT
This module is stored in an open GitHub repository at http://github.com/theory/class-meta/. Feel free to fork and contribute! π«Ά
Please file bug reports via GitHub Issues at http://github.com/theory/class-meta/issues/ or by sending mail to bug-Class-Meta@rt.cpan.org.
AUTHOR
David E. Wheeler <david@justatheory.com>
SEE ALSO
First of all β and I hope I've made this clear enough by now β use Class::Meta::Express instead of Class::Meta to declare your classes. Like, genuinely. Please.
Other classes of interest within the Class::Meta distribution include:
Class::Meta::ClassClass::Meta::ConstructorClass::Meta::AttributeClass::Meta::MethodClass::Meta::TypeClass::Meta::Types::PerlClass::Meta::Types::StringClass::Meta::Types::BooleanClass::Meta::Types::Numeric
For comparative purposes, you might also want to check out these fine modules:
Class::Accessorβ Accessor and constructor automation.Params::Validateβ Parameter validation.Class::Contractβ Design by contract.Class::Tangramβ Accessor automation and data validation for Tangram applications.Class::Makerβ An ambitious yet under-documented module that also manages accessor and constructor generation, data validation, and provides a reflection API. It also supports serialization.Class::MOPβ Stevan Little's application of Perl 6 meta classes to Perl 5.Mooseβ"It's the new camel."Another extension of the Perl 5 object system, built onClass::MOP.
COPYRIGHT AND LICENSE
Copyright (c) 2002-2011, David E. Wheeler. Some Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie!! you made it to the end of Class::Meta(3pm) β this was perl v5.34.0 energy, dated 2022-06-11, and you ate that entire manual page up. go build something iconic πβ¨ππ¦
π¦ where this page comes from
- debian bookworm: libclass-meta-perl 0.66-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-meta-perl 0.66-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-meta-perl 0.66-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms