Elemental/Objectifier.pm

filter: Statementstmt 100% 32 / 32 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 95.9% 47 / 49 CC 4 SCAR 5.1
CC
4
Cov
95%
objectify_events
3.0
element_class_for_event
2.0
BEGIN
1.0
CRAP 1.7
« Elemental/Command.pm ↑ Summary Elemental/Paragraph.pm »
1 package Pod::Elemental::Objectifier 0.103006;
2 # ABSTRACT: it turns a Pod::Eventual event stream into objects
3  
4 12 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #pod =head1 OVERVIEW
7 #pod
8 #pod An objectifier is responsible for taking the events produced by
9 #pod L<Pod::Eventual|Pod::Eventual> and converting them into objects that perform
10 #pod the Pod::Elemental::Paragraph role.
11 #pod
12 #pod In general, it does this by producing a sequence of element objects in the
13 #pod Pod::Elemental::Element::Generic namespace.
14 #pod
15 #pod =cut
16  
17 12 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 12 ▶use Pod::Elemental::Element::Generic::Blank;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶use Pod::Elemental::Element::Generic::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶use Pod::Elemental::Element::Generic::Nonpod;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 12 ▶use Pod::Elemental::Element::Generic::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 #pod =method objectify_events
25 #pod
26 #pod my $elements = $objectifier->objectify_events(\@events);
27 #pod
28 #pod Given an arrayref of Pod events, this method returns an arrayref of objects
29 #pod formed from the event stream.
30 #pod
31 #pod =cut
32  
33 14 ▶sub objectify_events {
Subroutine objectify_events: called CC=3 SCAR=11.0
Pod documented
34 14 my ($self, $events) = @_;
35 return [ map {
36 14 ▶ Carp::croak("not a valid event") unless ref $_;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ 0 344 344
37  
38 344 my $class = $self->element_class_for_event($_);
39  
40 my %guts = (
41 content => $_->{content},
42 start_line => $_->{start_line},
43  
44 344 ▶ ($_->{type} eq 'command' ? (command => $_->{command}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
$_->{'type'} eq 'command' ? : 120 224 344
45 );
46  
47 344 $class->new(\%guts);
48 } @$events ];
49 }
50  
51  
52 #pod =method element_class_for_event
53 #pod
54 #pod This method returns the name of the class to be used for the given event.
55 #pod
56 #pod =cut
57  
58 344 ▶sub __class_for {
Subroutine __class_for: called CC=1 SCAR=0.0
59 return {
60 344 blank => 'Pod::Elemental::Element::Generic::Blank',
61 command => 'Pod::Elemental::Element::Generic::Command',
62 nonpod => 'Pod::Elemental::Element::Generic::Nonpod',
63 text => 'Pod::Elemental::Element::Generic::Text',
64 };
65 }
66  
67 344 ▶sub element_class_for_event {
Subroutine element_class_for_event: called CC=2 SCAR=7.0
Pod documented
68 344 my ($self, $event) = @_;
69 344 my $t = $event->{type};
70 344 my $class_for = $self->__class_for;
71  
72 344 ▶ Carp::croak "unknown event type: $t" unless exists $class_for->{ $t };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $class_for->{$t} 0 344 344
73  
74 344 return $class_for->{ $t };
75 }
76  
77 12 __PACKAGE__->meta->make_immutable;
78  
79 12 1;
80  
81 __END__
« Elemental/Command.pm ↑ Summary Elemental/Paragraph.pm »