File Coverage

blib/lib/Tk/CodeText/Pod.pm
Criterion Covered Total %
statement 9 66 13.6
branch 0 24 0.0
condition 0 9 0.0
subroutine 3 6 50.0
pod 1 3 33.3
total 13 108 12.0


line stmt bran cond sub pod time code
1             package Tk::CodeText::Pod;
2              
3 1     1   46778 use vars qw($VERSION);
  1         3  
  1         64  
4             $VERSION = '0.2';
5              
6 1     1   5 use strict;
  1         2  
  1         34  
7 1     1   16 use base 'Tk::CodeText::Template';
  1         2  
  1         693  
8              
9             sub new {
10 0     0 0   my ($proto, $rules) = @_;
11 0   0       my $class = ref($proto) || $proto;
12 0 0         if (not defined($rules)) {
13 0           $rules = [
14             ['Text'],
15             ['Bold', -foreground => 'purple'],
16             ['Italic', -foreground => 'purple'],
17             ['Exact', -foreground => 'brown'],
18             ['Command', -foreground => 'orange'],
19             ['Space', -background => 'beige'],
20             ['Tab', -background => 'pale green'],
21             ];
22             };
23 0           my $self = $class->SUPER::new($rules);
24 0           bless ($self, $class);
25 0           $self->listAdd('specchars', 'B', 'I');
26 0           $self->listAdd('specmodes', 'Bold', 'Italic');
27 0           $self->stackPush('Text');
28 0           return $self;
29             }
30              
31             sub highlight {
32 0     0 1   my ($hlt, $in) = @_;
33 0           $hlt->snippetParse;
34 0           my $out = $hlt->out;
35 0           @$out = ();
36 0           my $first = substr($in, 0, 1);
37 0 0 0       if (substr($in, 0, 5) eq '=head') {
    0          
    0          
38             #head mode
39 0           $hlt->snippet($in);
40 0           $hlt->tokenParse('Command');
41             } elsif ($first eq '=') {
42             #command mode
43 0           $in =~ /(=[^\s]+)/g;
44 0           $hlt->snippet($1);
45 0           $hlt->tokenParse('Command');
46 0           $hlt->parseText(substr($in, length($1), length($in) - length($1)));
47             } elsif (($first eq "\t") or ($first eq ' ')) {
48             #exact mode
49 0           $in =~ /(^[^\S]+)/g;
50 0           my @sp = split //, $1;
51 0           while (@sp) {
52 0           my $k = shift @sp;
53 0 0         if ($k eq " ") {
    0          
54 0           $hlt->snippet($k);
55 0           $hlt->tokenParse('Space');
56             } elsif ($k eq "\t") {
57 0           $hlt->snippet($k);
58 0           $hlt->tokenParse('Tab');
59             }
60             }
61 0           $hlt->tokenParse('Command');
62 0           $hlt->snippet(substr($in, length($1), length($in) - length($1)));
63 0           $hlt->tokenParse('Exact');
64             } else {
65             #text mode
66 0           $hlt->parseText($in);
67             }
68 0           return @$out;
69             }
70              
71             sub parseText {
72 0     0 0   my $hlt = shift;
73 0           my @c = split //, shift;
74 0           while (@c) {
75 0           my $t = shift @c;
76 0 0         if ($hlt->tokenTest($t, 'specchars')) {
    0          
77 0 0 0       if ((@c) and ($c[0] eq '<')) {
78 0 0         if ($t eq 'B') {
    0          
79 0           $hlt->snippetParse;
80 0           $hlt->snippetAppend($t);
81 0           $hlt->stackPush('Bold');
82             } elsif ($t eq 'I') {
83 0           $hlt->snippetParse;
84 0           $hlt->snippetAppend($t);
85 0           $hlt->stackPush('Italic');
86             } else {
87 0           $hlt->snippetAppend($t);
88             }
89             } else {
90 0           $hlt->snippetAppend($t);
91             }
92             } elsif ($t eq '>') {
93 0 0         if ($hlt->tokenTest($hlt->stackTop, 'specmodes')) {
94 0           $hlt->snippetAppend($t);
95 0           $hlt->snippetParse;
96 0           $hlt->stackPull;
97             }
98             } else {
99 0           $hlt->snippetAppend($t);
100             }
101            
102             };
103 0           $hlt->snippetParse;
104             }
105              
106             1;
107              
108             __END__