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 becomming 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 mkaes 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 ot 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 sublass Meta::Builder::Base directly.
91

EXPORTS

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

AUTHORS

121       Chad Granum exodist7@gmail.com
122
124       Copyright (C) 2010 Chad Granum
125
126       Meta-Builder is free software; Standard perl licence.
127
128       Meta-Builder is distributed in the hope that it will be useful, but
129       WITHOUT ANY WARRANTY; without even the implied warranty of
130       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the license
131       for more details.
132
133
134
135perl v5.28.0                      2018-07-14                  Meta::Builder(3)
Impressum