File Coverage

blib/lib/Pod/XPath.pm
Criterion Covered Total %
statement 38 41 92.6
branch 5 8 62.5
condition 0 3 0.0
subroutine 8 8 100.0
pod 0 1 0.0
total 51 61 83.6


line stmt bran cond sub pod time code
1             package Pod::XPath;
2              
3             # ----------------------------------------------------------------------
4             # $Id: XPath.pm,v 1.4 2003/09/12 16:04:38 dlc Exp $
5             # ----------------------------------------------------------------------
6             # Pod::XPath -- use XPath expressions to navigate a POD document.
7             # Copyright (C) 2003 darren chamberlain
8             # ----------------------------------------------------------------------
9              
10 3     3   58154 use strict;
  3         7  
  3         137  
11 3     3   17 use vars qw($VERSION $REVISION $XPATH_CLASS);
  3         5  
  3         395  
12              
13             $VERSION = "1.00";
14             $REVISION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/;
15             $XPATH_CLASS = 'XML::XPath' unless defined $XPATH_CLASS;
16              
17 3     3   27 use Carp qw(carp);
  3         7  
  3         225  
18 3     3   3273 use IO::Handle qw(SEEK_SET);
  3         31747  
  3         243  
19 3     3   2836 use IO::String;
  3         9603  
  3         101  
20 3     3   2877 use Pod::XML;
  3         9498  
  3         162  
21 3     3   2758 use UNIVERSAL::require;
  3         5315  
  3         35  
22              
23             sub new {
24 2     2 0 28 my ($class, $pod) = @_;
25 2         4 my ($parser, $data, $string);
26              
27 2         21 $string = IO::String->new;
28 2         162 $parser = Pod::XML->new();
29              
30 2 50       61 if (UNIVERSAL::isa($pod, 'GLOB')) {
    100          
    50          
31             # Filehandle
32 0         0 $parser->parse_from_filehandle($pod, $string);
33             }
34             elsif (-f $pod) {
35             # Given a filename
36 1         139 $parser->parse_from_file($pod, $string);
37             }
38             elsif ($pod =~ /::/) {
39             # A module name
40 1 50       10 $pod->require
41             || die $UNIVERSAL::require::ERROR;
42              
43 1         59 my $podfile = $pod;
44 1         4 $podfile =~ s#::#/#g;
45 1         3 $podfile .= '.pm';
46 1         151 $parser->parse_from_file($INC{$podfile}, $string);
47             }
48             else {
49 0   0     0 my $stuff = ref($pod) || substr($pod, 0, 32) . "...";
50 0         0 warn "$class can't use '$stuff' as input.\n"
51             . "Sorry it didn't work out.\n";
52             }
53              
54             { # Turn the IO::String into a string
55 2         41571 local $/;
  2         11  
56 2         12 $string->seek(0, SEEK_SET);
57 2         46 $string = <$string>;
58             }
59              
60 2         57 $XPATH_CLASS->require;
61              
62 2         322 return $XPATH_CLASS->new(ioref => $string);
63             }
64              
65             1;
66             __END__