1 package MooseX::AutoDoc::View::TT;
5 # POD block for RT / Bugs / etc
6 # MooseX::Methods support
9 use Scalar::Util qw/blessed/;
12 extends 'MooseX::AutoDoc::View';
14 has _tt => (is => 'ro', isa => 'Template', lazy_build => 1);
15 has '+args' => (isa => 'HashRef');
19 Template->new($self->has_args ? $self->args : {})
20 || confess $Template::ERROR;
23 has role_template => (is => 'rw', isa => 'Str', lazy_build => 1);
24 has class_template => (is => 'rw', isa => 'Str', lazy_build => 1);
26 has role_template_blocks => (is => 'rw', isa => 'HashRef', lazy_build => 1);
27 has class_template_blocks => (is => 'rw', isa => 'HashRef', lazy_build => 1);
29 sub _build_role_template { "[% USE wrap; PROCESS role_block; %]" }
30 sub _build_class_template { "[% USE wrap; PROCESS class_block; %]" }
33 my ($self, $vars, $options) = @_;
36 my $template = $self->role_template. " ".$self->_role_blocks;
37 $tt->process(\ $template, $vars, \ $output, %{ $options || {}})
38 || confess $tt->error;
43 my ($self, $vars, $options) = @_;
46 my $template = $self->class_template. " ".$self->_class_blocks;
47 $tt->process(\ $template, $vars, \ $output, %{ $options || {}})
48 || confess $tt->error;
55 my $blocks = $self->class_template_blocks;
57 map { " [%- BLOCK ${_} %] ".$blocks->{$_}." [% END; -%] "}
63 my $blocks = $self->role_template_blocks;
65 map { " [%- BLOCK ${_} %] ".$blocks->{$_}." [% END; -%] "}
71 sub _build_class_template_blocks{
73 $blocks->{name_block} = q^
79 $blocks->{synopsys_block} = q^
84 [% class.name %]->new();
87 $blocks->{description_block} = q^
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,'','') %]
94 [%- ELSIF class.superclasses.size > 1 %]
95 This class is a subclass of the following classes and inherits all their
96 methods and attributes;
99 [%- FOREACH superclass = class.superclasses %]
101 =item L<[% superclass.name %]>
109 $blocks->{roles_consumed_block} = q^
110 [%- IF class.roles.size %]
111 =head1 ROLES CONSUMED
113 The following roles are consumed by this class. Unless otherwise indicated, all
114 methods, modifiers and attributes present in those roles are applied to this
118 [% FOREACH role_consumed = class.roles;
119 PROCESS role_consumed_block;
125 $blocks->{role_consumed_block} = q^
126 =item L<[% role_consumed.name %]>
129 $blocks->{attributes_block} = q^
130 [%- IF class.attributes.size %]
133 Unless noted otherwise, you may set any of these attributes at C<new> time by
134 passing key / value pairs to C<new> where the key is the name of the attribute
135 you wish to set. Unless noted otherwise accessor methods for attributes also
136 share the same name as the attribute.
138 FOREACH attribute = class.attributes;
139 PROCESS attribute_block;
145 $blocks->{attribute_block} = q^
146 =head2 [% attribute.name %]
147 [%- IF attribute.info.size %]
150 [% FOREACH pair IN attribute.info.pairs %]
151 =item B<[% pair.key %]> - [% pair.value %]
156 [% attribute.description FILTER wrap(80, '',''); %]
159 $blocks->{methods_block} = q^
162 =head2 new key => $value
164 Instantiate a new object. Please refer to L</"ATTRIBUTES"> for a list of valid
167 FOREACH method = class.methods;
168 PROCESS method_block;
173 Retrieve the metaclass instance. Please see L<Moose::Meta::Class> and
174 L<Class::MOP::Class> for more information.
177 $blocks->{method_block} = q^
178 =head2 [% method.name %]
180 Description of [% method.name %]
183 $blocks->{authors_block} = q^
186 FOREACH author = authors;
187 PROCESS author_block;
192 $blocks->{author_block} = q^
194 IF author.name.length; author.name _ ' '; END;
195 IF author.handle.length; '(' _ author.name _ ') '; END;
196 IF author.email.length; '<' _ author.email _ '>'; END;
200 $blocks->{license_block} = q^
201 =head1 COPYRIGHT AND LICENSE
203 [% license FILTER wrap(80, '', '') %]
206 $blocks->{class_block} = q^
209 PROCESS synopsys_block;
210 PROCESS description_block;
211 PROCESS roles_consumed_block;
212 PROCESS attributes_block;
213 PROCESS methods_block;
214 PROCESS authors_block;
215 PROCESS license_block;
223 sub _build_role_template_blocks{
226 $blocks->{name_block} = q^
232 $blocks->{synopsys_block} = q^
236 with '[% role.name %]';
239 $blocks->{description_block} = q^
242 When consumed, this role will apply to the consuming class all the methods,
243 method modifiers, and attributes it is composed of.
246 $blocks->{roles_consumed_block} = q^
247 [%- IF role.roles.size %]
248 =head1 ROLES CONSUMED
250 The following roles are consumed by this role. Unless otherwise indicated, all
251 methods, modifiers and attributes present in those roles will also be applied
252 to any class or role consuming this role.
255 [% FOREACH role_consumed = role.roles;
256 PROCESS role_consumed_block;
262 $blocks->{role_consumed_block} = q^
263 =item L<[% role_consumed.name %]>
266 $blocks->{attributes_block} = q^
267 [%- IF role.attributes.size %]
270 Unless noted otherwise, you may set any of these attributes on consuming
271 classes at C<new()> time by passing key / value pairs to C<new> where the key
272 is the name of the attribute you wish to set. Unless noted otherwise accessor
273 methods for attributes also share the same name as the attribute.
275 FOREACH attribute = role.attributes;
276 PROCESS attribute_block;
282 $blocks->{attribute_block} = q^
283 =head2 [% attribute.name %]
284 [%- IF attribute.info.size %]
287 [% FOREACH pair IN attribute.info.pairs %]
288 =item B<[% pair.key %]> - [% pair.value %]
293 [% attribute.description FILTER wrap(80, '',''); %]
296 $blocks->{methods_block} = q^
299 FOREACH method = role.methods;
300 PROCESS method_block;
305 Retrieve the role metaclass instance. Please see L<Moose::Meta::Role>;
308 $blocks->{method_block} = q^
309 =head2 [% method.name %]
311 Description of [% method.name %]
314 $blocks->{authors_block} = q^
317 FOREACH author = authors;
318 PROCESS author_block;
323 $blocks->{author_block} = q^
325 IF author.name.length; author.name _ ' '; END;
326 IF author.handle.length; '(' _ author.name _ ') '; END;
327 IF author.email.length; '<' _ author.email _ '> '; END;
331 $blocks->{license_block} = q^
332 =head1 COPYRIGHT AND LICENSE
334 [% license FILTER wrap(80, '', '') %]
337 $blocks->{role_block} = q^
340 PROCESS synopsys_block;
341 PROCESS description_block;
342 PROCESS roles_consumed_block;
343 PROCESS attributes_block;
344 PROCESS methods_block;
345 PROCESS authors_block;
346 PROCESS license_block;