1Meta::Builder(3)      User Contributed Perl Documentation     Meta::Builder(3)
2
3
4

NAME

6       Meta::Builder - Tools for creating Meta objects to track custom
7       metrics.
8

DESCRIPTION

10       Meta programming is becoming more and more popular. The popularity of
11       Meta programming comes from the fact that many problems are made
12       significantly easier. There are a few specialized Meta tools out there,
13       for instance <Class:MOP> which is used by Moose to track class
14       metadata.
15
16       Meta::Builder is designed to be a generic tool for writing Meta
17       objects. Unlike specialized tools, Meta::Builder makes no assumptions
18       about what metrics you will care about. Meta::Builder also makes it
19       simple for others to extend your meta-object based tools by providing
20       hooks for other packages to add metrics to your meta object.
21
22       If a specialized Meta object tool is available to meet your needs
23       please use it. However if you need a simple Meta object to track a
24       couple metrics, use Meta::Builder.
25
26       Meta::Builder is also low-sugar and low-dep. In most cases you will not
27       want a class that needs a meta object to use your meta-object class
28       directly. Rather you will usually want to create a sugar class that
29       exports enhanced API functions that manipulate the meta object.
30

SYNOPSIS

32       My/Meta.pm:
33
34           package My::Meta;
35           use strict;
36           use warnings;
37
38           use Meta::Builder;
39
40           # Name the accessor that will be defined in the class that uses the meta object
41           # It is used to retrieve the classes meta object.
42           accessor "mymeta";
43
44           # Add a metric with two actions
45           metric mymetric => sub { [] },
46                  pop => sub {
47                      my $self = shift;
48                      my ( $data ) = @_;
49                      pop @$data;
50                  },
51                  push => sub {
52                      my $self = shift;
53                      my ( $data, $metric, $action, @args ) = @_;
54                      push @$data => @args;
55                  };
56
57           # Add an additional action to the metric
58           action mymetric => ( get_ref => sub { shift });
59
60           # Add some predefined metric types + actions
61           hash_metric 'my_hashmetric';
62           lists_metric 'my_listsmetric';
63
64       My.pm:
65
66           package My;
67           use strict;
68           use warnings;
69
70           use My::Meta;
71
72           My::Meta->new( __PACKAGE__ );
73
74           # My::Meta defines mymeta() as the accessor we use to get our meta object.
75           # this is the ONLY way to get the meta object for this class.
76
77           mymeta()->mymetric_push( "some data" );
78           mymeta()->my_hashmetric_add( key => 'value' );
79           mymeta()->my_listsmetric_push( list => qw/valueA valueB/ );
80
81           # It works fine as an object/class method as well.
82           __PACKAGE__->mymeta->do_thing(...);
83
84           ...;
85

USING

87       When you use Meta::Builder your class is automatically turned into a
88       subclass of Meta::Builder::Base. In addition several "sugar" functions
89       are exported into your namespace. To avoid the "sugar" functions you
90       can simply subclass Meta::Builder::Base directly.
91

EXPORTS

93       metric( $name, \&generator, %actions )
94           Wrapper around "caller-"add_metric()>. See Meta::Builder::Base.
95
96       action( $metric, $name, $code )
97           Wrapper around "caller-"add_action()>. See Meta::Builder::Base.
98
99       hash_metric( $name, %additional_actions )
100           Wrapper around "caller-"add_hash_metric()>. See
101           Meta::Builder::Base.
102
103       lists_metric( $name, %additional_actions )
104           Wrapper around "caller-"add_lists_metric()>. See
105           Meta::Builder::Base.
106
107       before( $metric, $action, $code )
108           Wrapper around "caller-"hook_before()>. See Meta::Builder::Base.
109
110       after( $metric, $action, $code )
111           Wrapper around "caller-"hook_after()>. See Meta::Builder::Base.
112
113       accessor( $name )
114           Wrapper around "caller-"set_accessor()>. See Meta::Builder::Base.
115
116       make_immutable()
117           Overrides all functions/methods that alter the meta objects meta-
118           data. This in effect prevents anything from adding new metrics,
119           actions, or hooks without directly editing the metadata.
120

AUTHORS

122       Chad Granum exodist7@gmail.com
123
125       Copyright (C) 2010 Chad Granum
126
127       Meta-Builder is free software and is licensed under the same terms as
128       Perl itself.
129
130       Meta-Builder is distributed in the hope that it will be useful, but
131       WITHOUT ANY WARRANTY; without even the implied warranty of
132       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the license
133       for more details.
134
135
136
137perl v5.34.0                      2021-07-22                  Meta::Builder(3)
Impressum