File Coverage

blib/lib/PerlIO/via/UnPod.pm
Criterion Covered Total %
statement 16 16 100.0
branch 10 10 100.0
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package PerlIO::via::UnPod;
2              
3             $VERSION= '0.08';
4              
5             # be as strict as possible
6 2     2   106070 use strict;
  2         13  
  2         500  
7              
8             # satisfy -require-
9             1;
10              
11             #-------------------------------------------------------------------------------
12             #
13             # Standard Perl features
14             #
15             #-------------------------------------------------------------------------------
16             # IN: 1 class to bless with
17             # 2 mode string (ignored)
18             # 3 file handle of PerlIO layer below (ignored)
19             # OUT: 1 blessed object
20              
21             sub PUSHED {
22              
23             # create object with right attributes
24 2     2 1 1092 return bless { insrc => 1 }, $_[0];
25             } #PUSHED
26              
27             #-------------------------------------------------------------------------------
28             # IN: 1 instantiated object
29             # 2 handle to read from
30             # OUT: 1 processed string (if any)
31              
32             sub FILL {
33              
34             # process all lines
35 4     4 1 6 local($_);
36 4         27 while ( defined( $_= readline( $_[1] ) ) ) {
37              
38             # pod, and the end of it
39 16 100       34 if ( m#^=[a-zA-Z]# ) {
    100          
40 5         13 $_[0]->{insrc}= m#^=cut#;
41             }
42              
43             # still in source
44             elsif ( $_[0]->{insrc} ) {
45 3         10 return $_;
46             }
47             }
48              
49 1         11 return undef;
50             } #FILL
51              
52             #-------------------------------------------------------------------------------
53             # IN: 1 instantiated object
54             # 2 buffer to be written
55             # 3 handle to write to
56             # OUT: 1 number of bytes written or -1 to indicate failure
57              
58             sub WRITE {
59              
60             # all lines
61 2     2   115 foreach ( split( m#(?<=$/)#, $_[1] ) ) {
62              
63             # pod, and the end of it
64 17 100       39 if ( m#^=[a-zA-Z]# ) {
    100          
65 5         9 $_[0]->{insrc}= m#^=cut#;
66             }
67              
68             # still in source
69             elsif ( $_[0]->{insrc} ) {
70 4 100       6 return -1 if !print {$_[2]} $_;
  4         15  
71             }
72             }
73              
74 1         7 return length( $_[1] );
75             } #WRITE
76              
77             #-------------------------------------------------------------------------------
78              
79             __END__