public
Description:
Homepage:
Clone URL: git://github.com/robertkrimen/moosex-scaffold.git
moosex-scaffold / README
100644 174 lines (117 sloc) 6.231 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
NAME
    MooseX::Scaffold - Template metaprogramming with Moose
 
VERSION
    Version 0.03
 
SYNOPSIS
        package MyScaffolder;
 
        use MooseX::Scaffold;
 
        MooseX::Scaffold->setup_scaffolding_import;
 
        sub SCAFFOLD {
            my $class = shift; my %given = @_;
 
            $class->has($given{kind} => is => 'ro', isa => 'Int', required => 1);
 
            # Using MooseX::ClassAttribute
            $class->class_has(kind => is => 'ro', isa => 'Str', default => $given{kind});
        }
 
        package MyAppleClass;
 
        use Moose;
        use MooseX::ClassAttribute;
        use MyScaffolder kind => 'apple';
 
        package MyBananaClass;
 
        use Moose;
        use MooseX::ClassAttribute;
        use MyScaffolder kind => 'banana';
 
        # ... meanwhile, back at the Batcave ...
 
        use MyAppleClass;
        use MyBananaClass;
 
        my $apple = MyAppleClass->new(apple => 1);
        my $banana = MyBananaClass->new(banana => 2);
 
DESCRIPTION
    MooseX::Scaffold is a tool for creating or augmenting Moose classes
    on-the-fly.
 
    Scaffolding can be triggered when a "use" is executed (any import
    arguments are passed to the scaffold subroutine) or you can explicitly
    call MooseX::Scaffold->scaffold with the scaffolding subroutine and the
    package name for the class.
 
    Depending on what you're trying to do, MooseX::Scaffold can behave in
    three different ways (Assume My::Class is the class you're trying to
    create/augment):
 
        load_and_scaffold (scaffold) - Attempt to require My::Class from My/Class.pm or do Moose::Meta::Class->create('My::Class')
                                         to make the package on-the-fly. Scaffold the result.
 
        load_or_scaffold (load) - Attempt to require My::Class from My/Class.pm and stop if that works. If no My/Class.pm is
                                         found in @INC, then make a Moose class on-the-fly and scaffold it.
                                         This option can be used to create a default class if one isn't found.
 
        scaffold_without_load - Don't attempt to require My::Class, just create it on-the-fly and scaffold it.
 
METHODS
  MooseX::Scaffold->scaffold( ... )
    Scaffold a class by either loading it or creating it. You can pass
    through the following:
 
        scaffolder
        scaffolding_package This should be either a subroutine (sub { ... }) or a package name. If a package name
                                is given, then the package should contain a subroutine called SCAFFOLD
 
        class
        class_package The package name of resulting class
 
        load_or_scaffold Attempt to load $class_package first and do nothing successful. Otherwise create
                                $class_package and scaffold it
 
        scaffold_without_load Scaffold $class_package without attempting to load it first. Does not have
                                any effect if $class_package has been loaded already
 
        no_class_attribute Set this to 1 to disable applying the MooseX::ClassAttribute meta-role
                                on class creation. This has no effect if the class is loaded (If you
                                want class_has with a loaded class, make sure to 'use MooseX::ClassAttribute')
 
  MooseX::Scaffold->load_and_scaffold( ... )
    An alias for ->scaffold
 
  MooseX::Scaffold->load_or_scaffold( ... )
    An alias for ->scaffold with "load_or_scaffold" set to 1
 
  MooseX::Scaffold->load( ... )
    An alias for ->load_or_scaffold
 
  MooseX::Scaffold->scaffold_without_load( ... )
    An alias for ->scaffold with "scaffold_without_load" set to 1
 
  MooseX::Scaffold->build_scaffolding_import( ... )
    Return an anonymous subroutine suitable for use an an import function
 
    Anything passable to ->scaffold is fair game. In addition:
 
        scaffolder This will default to the package of caller() if unspecified
 
        chain_import An (optional) subroutine that will goto'd after scaffolding is complete
 
  MooseX::Scaffold->setup_scaffolding_import( ... )
    Install an import subroutine. By default, caller() will be used for the
    exporting package, but another may be specified.
 
    Anything passable to ->build_scaffolding_import is fair game. In
    addition:
 
        exporter
        exporting_package The package that will house the import subroutine (the scaffolding will trigger
                            when the package is used or imported)
 
  MooseX::Scaffold->load_package( $package )
  MooseX::Scaffold->load_class( $class )
    A convenience method that will attempt to require $package or $class if
    not already loaded
 
    Essentially does ...
 
        eval "require $package;" or die $@
 
    ... but uses Class::Inspector to check for $package existence first
    (%INC is not trustworthy)
 
AUTHOR
    Robert Krimen, "<rkrimen at cpan.org>"
 
SOURCE
    You can contribute or fork this project via GitHub:
 
    <http://github.com/robertkrimen/moosex-scaffold/tree/master>
 
        git clone git://github.com/robertkrimen/moosex-scaffold.git MooseX-Scaffold
 
BUGS
    Please report any bugs or feature requests to "bug-moosex-classscaffold
    at rt.cpan.org", or through the web interface at
    <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Scaffold>. I will
    be notified, and then you'll automatically be notified of progress on
    your bug as I make changes.
 
SUPPORT
    You can find documentation for this module with the perldoc command.
 
        perldoc MooseX::Scaffold
 
    You can also look for information at:
 
    * RT: CPAN's request tracker
        <http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Scaffold>
 
    * AnnoCPAN: Annotated CPAN documentation
        <http://annocpan.org/dist/MooseX-Scaffold>
 
    * CPAN Ratings
        <http://cpanratings.perl.org/d/MooseX-Scaffold>
 
    * Search CPAN
        <http://search.cpan.org/dist/MooseX-Scaffold>
 
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
    Copyright 2008 Robert Krimen, all rights reserved.
 
    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.