just some docs and tiny changes
[gitmo/MooseX-AutoDoc.git] / lib / MooseX / AutoDoc / View / TT.pm
CommitLineData
3890b670 1package MooseX::AutoDoc::View::TT;
2
9afe15bd 3#TODO:
4# Versions
5# POD block for RT / Bugs / etc
6# MooseX::Methods support
7
3890b670 8use Moose;
9use Scalar::Util qw/blessed/;
10use Template;
11
12extends 'MooseX::AutoDoc::View';
13
14has _tt => (is => 'ro', isa => 'Template', lazy_build => 1);
15has '+args' => (isa => 'HashRef');
16
17sub _build__tt {
18 my $self = shift;
19 Template->new($self->has_args ? $self->args : {})
20 || confess $Template::ERROR;
21}
22
23has role_template => (is => 'rw', isa => 'Str', lazy_build => 1);
24has class_template => (is => 'rw', isa => 'Str', lazy_build => 1);
25
26has role_template_blocks => (is => 'rw', isa => 'HashRef', lazy_build => 1);
27has class_template_blocks => (is => 'rw', isa => 'HashRef', lazy_build => 1);
28
29sub _build_role_template { "[% USE wrap; PROCESS role_block; %]" }
30sub _build_class_template { "[% USE wrap; PROCESS class_block; %]" }
31
32sub render_role {
33 my ($self, $vars, $options) = @_;
34 my $tt = $self->_tt;
35 my $output;
36 my $template = $self->role_template. " ".$self->_role_blocks;
37 $tt->process(\ $template, $vars, \ $output, %{ $options || {}})
38 || confess $tt->error;
39 return $output;
40}
41
42sub render_class {
43 my ($self, $vars, $options) = @_;
44 my $tt = $self->_tt;
45 my $output;
46 my $template = $self->class_template. " ".$self->_class_blocks;
47 $tt->process(\ $template, $vars, \ $output, %{ $options || {}})
48 || confess $tt->error;
49 return $output;
50}
51
52
53sub _class_blocks {
54 my $self= shift;
55 my $blocks = $self->class_template_blocks;
56 return join "",
57 map { " [%- BLOCK ${_} %] ".$blocks->{$_}." [% END; -%] "}
58 keys %$blocks;
59}
60
61sub _role_blocks {
62 my $self= shift;
63 my $blocks = $self->role_template_blocks;
64 return join "",
65 map { " [%- BLOCK ${_} %] ".$blocks->{$_}." [% END; -%] "}
66 keys %$blocks;
67}
68
691;
70
71sub _build_class_template_blocks{
72 my $blocks = {};
73 $blocks->{name_block} = q^
74=head1 NAME
75
76[% class.name %]
77^;
78
79 $blocks->{synopsys_block} = q^
80=head1 SYNOPSYS
81
82 use [% class.name %];
83 #TODO
84 [% class.name %]->new();
85^;
86
87 $blocks->{description_block} = q^
88=head1 DESCRIPTION
89
90[%- IF class.superclasses.size == 1 %]
91[% 'This class is a subclass of L<' _ class.superclasses.first.name _'>' _
92' and inherits all it\'s methods and attributes.' FILTER wrap(80,'','') %]
93
94[%- ELSIF class.superclasses.size > 1 %]
95This class is a subclass of the following classes and inherits all their
96methods and attributes;
97
98=over 4
99[%- FOREACH superclass = class.superclasses %]
100
101=item L<[% superclass.name %]>
102[%- END %]
103
104=back
105
106[%- END -%]
107^;
108
109 $blocks->{roles_consumed_block} = q^
110[%- IF class.roles.size %]
111=head1 ROLES CONSUMED
112
113The following roles are consumed by this class. Unless otherwise indicated, all
114methods, modifiers and attributes present in those roles are applied to this
115class.
116
117=over 4
118[% FOREACH role_consumed = class.roles;
119 PROCESS role_consumed_block;
120 END %]
121=back
122[% END -%]
123^;
124
125 $blocks->{role_consumed_block} = q^
126=item L<[% role_consumed.name %]>
127^;
128
129 $blocks->{attributes_block} = q^
130[%- IF class.attributes.size %]
131=head1 ATTRIBUTES
132
133Unless noted otherwise, you may set any of these attributes at C<new> time by
134passing key / value pairs to C<new> where the key is the name of the attribute
135you wish to set. Unless noted otherwise accessor methods for attributes also
136share the same name as the attribute.
137[%
138 FOREACH attribute = class.attributes;
139 PROCESS attribute_block;
140 END;
141END;
142-%]
143^;
144
145 $blocks->{attribute_block} = q^
146=head2 [% attribute.name %]
147[%- IF attribute.info.size %]
148
149=over 4
150[% FOREACH pair IN attribute.info.pairs %]
ec75fdb0 151=item B<[% pair.key %]> - [% pair.value %]
3890b670 152[% END %]
153=back
154[%- END; %]
155
156[% attribute.description FILTER wrap(80, '',''); %]
157^;
158
159 $blocks->{methods_block} = q^
160=head1 METHODS
161
9afe15bd 162=head2 new key => $value
3890b670 163
164Instantiate a new object. Please refer to L</"ATTRIBUTES"> for a list of valid
165key options.
166[%
167 FOREACH method = class.methods;
168 PROCESS method_block;
169 END;
170%]
171=head2 meta
172
173Retrieve the metaclass instance. Please see L<Moose::Meta::Class> and
174L<Class::MOP::Class> for more information.
175^;
176
177 $blocks->{method_block} = q^
178=head2 [% method.name %]
179
180Description of [% method.name %]
181^;
182
183 $blocks->{authors_block} = q^
184=head1 AUTHORS
185[%
186 FOREACH author = authors;
187 PROCESS author_block;
188 END;
189-%]
190^;
191
192 $blocks->{author_block} = q^
193[%
194IF author.name.length; author.name _ ' '; END;
195IF author.handle.length; '(' _ author.name _ ') '; END;
196IF author.email.length; '<' _ author.email _ '>'; END;
197%]
198^;
199
200 $blocks->{license_block} = q^
201=head1 COPYRIGHT AND LICENSE
202
203[% license FILTER wrap(80, '', '') %]
204^;
205
206 $blocks->{class_block} = q^
207[%
208PROCESS name_block;
209PROCESS synopsys_block;
210PROCESS description_block;
211PROCESS roles_consumed_block;
212PROCESS attributes_block;
213PROCESS methods_block;
214PROCESS authors_block;
215PROCESS license_block;
216%]
217=cut
218^;
219
220 return $blocks;
221}
222
223sub _build_role_template_blocks{
224 my $blocks = {};
225
226 $blocks->{name_block} = q^
227=head1 NAME
228
229[% role.name %]
230^;
231
232 $blocks->{synopsys_block} = q^
233=head1 SYNOPSYS
234
235 use Moose;
236 with '[% role.name %]';
237^;
238
239 $blocks->{description_block} = q^
240=head1 DESCRIPTION
241
242When consumed, this role will apply to the consuming class all the methods,
243method modifiers, and attributes it is composed of.
244^;
245
246 $blocks->{roles_consumed_block} = q^
247[%- IF role.roles.size %]
248=head1 ROLES CONSUMED
249
250The following roles are consumed by this role. Unless otherwise indicated, all
251methods, modifiers and attributes present in those roles will also be applied
252to any class or role consuming this role.
253
254=over 4
255[% FOREACH role_consumed = role.roles;
256 PROCESS role_consumed_block;
257 END %]
258=back
259[% END -%]
260^;
261
262 $blocks->{role_consumed_block} = q^
263=item L<[% role_consumed.name %]>
264^;
265
266 $blocks->{attributes_block} = q^
267[%- IF role.attributes.size %]
268=head1 ATTRIBUTES
269
270Unless noted otherwise, you may set any of these attributes on consuming
271classes at C<new()> time by passing key / value pairs to C<new> where the key
272is the name of the attribute you wish to set. Unless noted otherwise accessor
273methods for attributes also share the same name as the attribute.
274[%
275 FOREACH attribute = role.attributes;
276 PROCESS attribute_block;
277 END;
278END;
279-%]
280^;
281
282 $blocks->{attribute_block} = q^
283=head2 [% attribute.name %]
284[%- IF attribute.info.size %]
285
286=over 4
287[% FOREACH pair IN attribute.info.pairs %]
288=item B<[% pair.key %]> - [% pair.value %]
289[% END %]
290=back
291[%- END; %]
292
293[% attribute.description FILTER wrap(80, '',''); %]
294^;
295
296 $blocks->{methods_block} = q^
297=head1 METHODS
298[%
299 FOREACH method = role.methods;
300 PROCESS method_block;
301 END;
302%]
303=head2 meta
304
305Retrieve the role metaclass instance. Please see L<Moose::Meta::Role>;
306^;
307
308 $blocks->{method_block} = q^
309=head2 [% method.name %]
310
311Description of [% method.name %]
312^;
313
314 $blocks->{authors_block} = q^
315=head1 AUTHORS
316[%
317 FOREACH author = authors;
318 PROCESS author_block;
319 END;
320-%]
321^;
322
323 $blocks->{author_block} = q^
324[%
325IF author.name.length; author.name _ ' '; END;
326IF author.handle.length; '(' _ author.name _ ') '; END;
327IF author.email.length; '<' _ author.email _ '> '; END;
328%]
329^;
330
331 $blocks->{license_block} = q^
332=head1 COPYRIGHT AND LICENSE
333
334[% license FILTER wrap(80, '', '') %]
335^;
336
337 $blocks->{role_block} = q^
338[%
339PROCESS name_block;
340PROCESS synopsys_block;
341PROCESS description_block;
342PROCESS roles_consumed_block;
343PROCESS attributes_block;
344PROCESS methods_block;
345PROCESS authors_block;
346PROCESS license_block;
347%]
348=cut
349^;
350
351 return $blocks;
352}
353
3541;
355
356__END__;