line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Decorator::Group; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
1322
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
377
|
|
4
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
117
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
117
|
use Carp; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
1024
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Text::Decorator::Group - A (possibly nested) group of nodes |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $group = $self->new(@nodes); |
15
|
|
|
|
|
|
|
$self->format_as('html'); |
16
|
|
|
|
|
|
|
$self->nodes |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
A Group is a set of nodes that live together for some semantic reason - |
21
|
|
|
|
|
|
|
paragraphs in a document, sentences in a paragraph, or whatever. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 METHODS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 new |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$self->new(@nodes); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Creates a new Text::Decorator::Group instance. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
5
|
|
|
5
|
1
|
400
|
my $class = shift; |
35
|
5
|
|
|
|
|
68
|
return bless { |
36
|
|
|
|
|
|
|
nodes => [@_], |
37
|
|
|
|
|
|
|
representations => {}, |
38
|
|
|
|
|
|
|
notes => {}, # What's this group all about, then? |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
} => $class; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 nodes |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
@nodes = $self->nodes; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Returns the nodes which make up this group. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
6
|
1
|
6
|
sub nodes { return @{ shift->{nodes} } } |
|
6
|
|
|
|
|
24
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 format_as |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$self->format_as("html") |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Descend into the group, formatting each node, stringing the pieces |
58
|
|
|
|
|
|
|
together and returning the result, optionally adding some pre- and post- |
59
|
|
|
|
|
|
|
representation-specific material. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub format_as { |
64
|
6
|
|
|
6
|
1
|
9
|
my ($self, $format) = @_; |
65
|
6
|
|
|
|
|
7
|
my $gformat = $format; |
66
|
6
|
100
|
|
|
|
17
|
$gformat = "text" if not exists $self->{representations}{$format}; |
67
|
5
|
|
|
5
|
|
24
|
no warnings; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
1079
|
|
68
|
6
|
|
|
|
|
22
|
return $self->{representations}{$gformat}{pre} |
69
|
|
|
|
|
|
|
. join( |
70
|
|
|
|
|
|
|
$self->{representations}{$gformat}{inter}, |
71
|
|
|
|
|
|
|
map $_->format_as($format), |
72
|
|
|
|
|
|
|
$self->nodes |
73
|
|
|
|
|
|
|
) |
74
|
|
|
|
|
|
|
. $self->{representations}{$gformat}{post}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|