1 package MooseX::AutoDoc::View::TT;
4 use Scalar::Util qw/blessed/;
7 extends 'MooseX::AutoDoc::View';
9 has _tt => (is => 'ro', isa => 'Template', lazy_build => 1);
10 has '+args' => (isa => 'HashRef');
14 Template->new($self->has_args ? $self->args : {})
15 || confess $Template::ERROR;
18 has role_template => (is => 'rw', isa => 'Str', lazy_build => 1);
19 has class_template => (is => 'rw', isa => 'Str', lazy_build => 1);
21 has role_template_blocks => (is => 'rw', isa => 'HashRef', lazy_build => 1);
22 has class_template_blocks => (is => 'rw', isa => 'HashRef', lazy_build => 1);
24 sub _build_role_template { "[% USE wrap; PROCESS role_block; %]" }
25 sub _build_class_template { "[% USE wrap; PROCESS class_block; %]" }
28 my ($self, $vars, $options) = @_;
31 my $template = $self->role_template. " ".$self->_role_blocks;
32 $tt->process(\ $template, $vars, \ $output, %{ $options || {}})
33 || confess $tt->error;
38 my ($self, $vars, $options) = @_;
41 my $template = $self->class_template. " ".$self->_class_blocks;
42 $tt->process(\ $template, $vars, \ $output, %{ $options || {}})
43 || confess $tt->error;
50 my $blocks = $self->class_template_blocks;
52 map { " [%- BLOCK ${_} %] ".$blocks->{$_}." [% END; -%] "}
58 my $blocks = $self->role_template_blocks;
60 map { " [%- BLOCK ${_} %] ".$blocks->{$_}." [% END; -%] "}
66 sub _build_class_template_blocks{
68 $blocks->{name_block} = q^
74 $blocks->{synopsys_block} = q^
79 [% class.name %]->new();
82 $blocks->{description_block} = q^
85 [%- IF class.superclasses.size == 1 %]
86 [% 'This class is a subclass of L<' _ class.superclasses.first.name _'>' _
87 ' and inherits all it\'s methods and attributes.' FILTER wrap(80,'','') %]
89 [%- ELSIF class.superclasses.size > 1 %]
90 This class is a subclass of the following classes and inherits all their
91 methods and attributes;
94 [%- FOREACH superclass = class.superclasses %]
96 =item L<[% superclass.name %]>
104 $blocks->{roles_consumed_block} = q^
105 [%- IF class.roles.size %]
106 =head1 ROLES CONSUMED
108 The following roles are consumed by this class. Unless otherwise indicated, all
109 methods, modifiers and attributes present in those roles are applied to this
113 [% FOREACH role_consumed = class.roles;
114 PROCESS role_consumed_block;
120 $blocks->{role_consumed_block} = q^
121 =item L<[% role_consumed.name %]>
124 $blocks->{attributes_block} = q^
125 [%- IF class.attributes.size %]
128 Unless noted otherwise, you may set any of these attributes at C<new> time by
129 passing key / value pairs to C<new> where the key is the name of the attribute
130 you wish to set. Unless noted otherwise accessor methods for attributes also
131 share the same name as the attribute.
133 FOREACH attribute = class.attributes;
134 PROCESS attribute_block;
140 $blocks->{attribute_block} = q^
141 =head2 [% attribute.name %]
142 [%- IF attribute.info.size %]
145 [% FOREACH pair IN attribute.info.pairs %]
146 =item B<[% pair.key %]> - [% pair.value %]
151 [% attribute.description FILTER wrap(80, '',''); %]
154 $blocks->{methods_block} = q^
157 =head2 new $key => $value
159 Instantiate a new object. Please refer to L</"ATTRIBUTES"> for a list of valid
162 FOREACH method = class.methods;
163 PROCESS method_block;
168 Retrieve the metaclass instance. Please see L<Moose::Meta::Class> and
169 L<Class::MOP::Class> for more information.
172 $blocks->{method_block} = q^
173 =head2 [% method.name %]
175 Description of [% method.name %]
178 $blocks->{authors_block} = q^
181 FOREACH author = authors;
182 PROCESS author_block;
187 $blocks->{author_block} = q^
189 IF author.name.length; author.name _ ' '; END;
190 IF author.handle.length; '(' _ author.name _ ') '; END;
191 IF author.email.length; '<' _ author.email _ '>'; END;
195 $blocks->{license_block} = q^
196 =head1 COPYRIGHT AND LICENSE
198 [% license FILTER wrap(80, '', '') %]
201 $blocks->{class_block} = q^
204 PROCESS synopsys_block;
205 PROCESS description_block;
206 PROCESS roles_consumed_block;
207 PROCESS attributes_block;
208 PROCESS methods_block;
209 PROCESS authors_block;
210 PROCESS license_block;
218 sub _build_role_template_blocks{
221 $blocks->{name_block} = q^
227 $blocks->{synopsys_block} = q^
231 with '[% role.name %]';
234 $blocks->{description_block} = q^
237 When consumed, this role will apply to the consuming class all the methods,
238 method modifiers, and attributes it is composed of.
241 $blocks->{roles_consumed_block} = q^
242 [%- IF role.roles.size %]
243 =head1 ROLES CONSUMED
245 The following roles are consumed by this role. Unless otherwise indicated, all
246 methods, modifiers and attributes present in those roles will also be applied
247 to any class or role consuming this role.
250 [% FOREACH role_consumed = role.roles;
251 PROCESS role_consumed_block;
257 $blocks->{role_consumed_block} = q^
258 =item L<[% role_consumed.name %]>
261 $blocks->{attributes_block} = q^
262 [%- IF role.attributes.size %]
265 Unless noted otherwise, you may set any of these attributes on consuming
266 classes at C<new()> time by passing key / value pairs to C<new> where the key
267 is the name of the attribute you wish to set. Unless noted otherwise accessor
268 methods for attributes also share the same name as the attribute.
270 FOREACH attribute = role.attributes;
271 PROCESS attribute_block;
277 $blocks->{attribute_block} = q^
278 =head2 [% attribute.name %]
279 [%- IF attribute.info.size %]
282 [% FOREACH pair IN attribute.info.pairs %]
283 =item B<[% pair.key %]> - [% pair.value %]
288 [% attribute.description FILTER wrap(80, '',''); %]
291 $blocks->{methods_block} = q^
294 FOREACH method = role.methods;
295 PROCESS method_block;
300 Retrieve the role metaclass instance. Please see L<Moose::Meta::Role>;
303 $blocks->{method_block} = q^
304 =head2 [% method.name %]
306 Description of [% method.name %]
309 $blocks->{authors_block} = q^
312 FOREACH author = authors;
313 PROCESS author_block;
318 $blocks->{author_block} = q^
320 IF author.name.length; author.name _ ' '; END;
321 IF author.handle.length; '(' _ author.name _ ') '; END;
322 IF author.email.length; '<' _ author.email _ '> '; END;
326 $blocks->{license_block} = q^
327 =head1 COPYRIGHT AND LICENSE
329 [% license FILTER wrap(80, '', '') %]
332 $blocks->{role_block} = q^
335 PROCESS synopsys_block;
336 PROCESS description_block;
337 PROCESS roles_consumed_block;
338 PROCESS attributes_block;
339 PROCESS methods_block;
340 PROCESS authors_block;
341 PROCESS license_block;