Decorator/Group.pm

filter: Statementstmt 100% 21 / 21 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 100% 33 / 33 CC 2 SCAR 2.2
CC
2
Cov
100%
format_as
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Decorator/Node.pm ↑ Summary Decorator/Filter/Quoted.pm »
1 package Text::Decorator::Group;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
34 5 my $class = shift;
35 5 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 ▶sub nodes { return @{ shift->{nodes} } }
Subroutine nodes: called CC=1 SCAR=0.0
Pod documented
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 6 ▶sub format_as {
Subroutine format_as: called CC=2 SCAR=6.9
Pod documented
64 6 my ($self, $format) = @_;
65 6 my $gformat = $format;
66 6 ▶ $gformat = "text" if not exists $self->{representations}{$format};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"representations"}{$format} 1 5 6
67 6 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 return $self->{representations}{$gformat}{pre}
69 . join(
70 $self->{representations}{$gformat}{inter},
71 map $_->format_as($format),
72 $self->nodes
73 )
74 6 . $self->{representations}{$gformat}{post};
75 }
76  
77 6 1;
78  
« Decorator/Node.pm ↑ Summary Decorator/Filter/Quoted.pm »