blib/lib/Data/Stag/PodParser.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 92 CC 11 SCAR 41.3
CC
11
Cov
0%
parse_fh
110.0
trim
6.0
BEGIN
2.0
CRAP 62.4
1 # $Id: PodParser.pm,v 1.10 2008/06/03 17:31:15 cmungall Exp $
2 #
3 # Copyright (C) 2002 Chris Mungall <cjm@fruitfly.org>
4 #
5 # See also - http://stag.sourceforge.net
6 #
7 # This module is free software.
8 # You may distribute this module under the same terms as perl itself
9  
10 package Data::Stag::PodParser;
11  
12 =head1 NAME
13  
14 PodParser.pm - parses perl POD documentation into stag events
15  
16 =head1 SYNOPSIS
17  
18 =cut
19  
20 =head1 DESCRIPTION
21  
22  
23 =head1 AUTHOR
24  
25 =cut
26  
27 use Exporter;
28 use Carp;
29 use FileHandle;
30 use strict;
31 use base qw(Data::Stag::BaseGenerator Exporter);
32  
33 use vars qw($VERSION);
34 $VERSION="0.14";
35  
36 sub trim {
37 my $w = shift;
38 $w = '' unless defined $w;
39 $w =~ s/^\s+//g;
40 $w =~ s/\s+$//g;
41 return $w;
42 }
43  
44 sub parse_fh {
45 my $self = shift;
46 my $fh = shift;
47 my @stack = ();
48 my $txt;
49  
50 my $in_pod = 0;
51 my $tt = 'text';
52 $self->start_event("pod");
53 my $buf;
54 my $section;
55 while(<$fh>) {
56 chomp;
57 if (/^=(\S+)\s*(.*)/) {
58 $tt = 'text';
59 my ($ev, $data) = ($1, $2);
60 $in_pod = $ev eq 'cut' ? 0 : 1;
61 $data =~ s/\s*$//;
62 $section = $data;
63 if ($buf) {
64 $self->event($tt=>trim($buf));
65 $buf = undef;
66 }
67 $self->pop_stack_to_depth(1);
68 # $self->event($ev, $data);
69 if ($data) {
70 $self->start_event('section');
71 $self->event(type=>$ev);
72 $self->event(name=>$data);
73 }
74 }
75 else {
76 if (/^\s\s\s*(.*)/) {
77 if ($tt eq 'text') {
78 $tt = 'code';
79 if ($buf) {
80 $self->event(text=>trim($buf));
81 $buf = undef;
82 }
83 }
84 }
85 if ($in_pod) {
86 $buf .= "$_\n";
87 }
88 }
89 }
90 if ($buf) {
91 $self->event($tt=>trim($buf));
92 }
93 $fh->close;
94 $self->pop_stack_to_depth(0);
95 return;
96 }
97  
98 1;