@@ -13,8 +13,8 @@ Synopsis 12: Objects
13
13
14
14
Created: 27 Oct 2004
15
15
16
- Last Modified: 14 Jan 2012
17
- Version: 124
16
+ Last Modified: 22 Jun 2012
17
+ Version: 125
18
18
19
19
=head1 Overview
20
20
@@ -2474,6 +2474,65 @@ those types as well as any types outside of them, such as C<Mu> or
2474
2474
C<Junction>. But users should not generally be deriving from those
2475
2475
types anyway.
2476
2476
2477
+ =head1 Custom Meta-objects
2478
+
2479
+ [Note: This section is still subject to some changes, but does at least
2480
+ reflect current implementation reality fairly well.]
2481
+
2482
+ When the parser encounters a package declarator, it uses the name of
2483
+ the declarator (such as C<class> or C<grammar>) to look up the type of
2484
+ meta-object to use. The default meta-objects support the standard Perl 6
2485
+ OO semantics. However, it is possible for a module to export different
2486
+ meta-objects with different semantics. This is done by making entries in
2487
+ an EXPORTHOW package, which in turn must be located in UNIT of the module.
2488
+ The name it is installed under maps to a package or type declarator name.
2489
+
2490
+ Thus, a module can provide a replacement implementation of the meta-object
2491
+ type used for grammars like this:
2492
+
2493
+ my module EXPORTHOW { }
2494
+ EXPORTHOW::<grammar> = TracedGrammarHOW;
2495
+
2496
+ The easiest way to define a new meta-object is to inherit from an existing
2497
+ meta-object.
2498
+
2499
+ my class TracedGrammarHOW is Metamodel::GrammarHOW {
2500
+ }
2501
+
2502
+ Here is a list of the various meta-objects that you may safely subclass and
2503
+ the name they are installed under by default.
2504
+
2505
+ Metamodel::ClassHOW class
2506
+ Metamodel::EnumHOW enum
2507
+ Metamodel::GrammarHOW grammar
2508
+ Metamodel::ModuleHOW module
2509
+ Metamodel::PackageHOW package
2510
+ Metamodel::ParametricRoleHOW role
2511
+ Metamodel::ParametricRoleGroupHOW role-group
2512
+ Metamodel::SubsetHOW subset
2513
+
2514
+ All of these meta-objects inherit from C<Any>. However, they will in turn
2515
+ be implemented by other meta-objects that may or may not do so. This is
2516
+ considered implementation specific, and implementations may re-arrange these
2517
+ details freely between versions. Thus, relying on them is erroneous.
2518
+
2519
+ SomeP6Class.HOW # Promises to (ultimately) inherit from Any
2520
+ SomeP6Class.HOW.HOW # Implementation specific
2521
+
2522
+ Roles are a little interesting, since they involve multiple meta-objects.
2523
+ When you write:
2524
+
2525
+ role Foo {
2526
+ }
2527
+
2528
+ Then a C<ParametricRoleHOW> is created to represent the role declaration.
2529
+ It is in turn wrapped up inside a C<ParametricRoleGroupHOW>, which is then
2530
+ installed under the name C<Foo>. This is because one short name may have
2531
+ many long names due to signatured roles.
2532
+
2533
+ role Foo[::T] {
2534
+ }
2535
+
2477
2536
=head1 Autovivifying objects
2478
2537
2479
2538
The C<WHENCE> property of an object is its autovivifying closure.
0 commit comments