| 1 | package oEdtk::XPath; | ||
| 2 | |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 2 | ▶ | use base 'XML::XPath'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | our $VERSION = 2.1131; | ||
| 8 | |||
| 9 | sub findTextValue { | ||
| 10 | my ( $self, $path, $context ) = @_; | ||
| 11 | my $val = $self->findvalue( $path, $context ); | ||
| 12 | return "$val"; | ||
| 13 | } | ||
| 14 | |||
| 15 | 1; | ||
| 16 | |||
| 17 | =head1 NAME | ||
| 18 | |||
| 19 | oEdtk::XPath - XML::XPath subclass returning plain string values | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | use oEdtk::XPath; | ||
| 24 | |||
| 25 | my $xp = oEdtk::XPath->new(filename => 'doc.xml'); | ||
| 26 | my $v = $xp->findTextValue('/root/child'); | ||
| 27 | |||
| 28 | =head1 DESCRIPTION | ||
| 29 | |||
| 30 | A minimal subclass of C<XML::XPath> that adds a string-coercing lookup: it | ||
| 31 | runs the usual C<findvalue> and forces the result into a plain string, so a | ||
| 32 | node value can be used directly as a scalar. | ||
| 33 | |||
| 34 | =head1 METHODS | ||
| 35 | |||
| 36 | =head2 findTextValue | ||
| 37 | |||
| 38 | my $value = $xp->findTextValue($path, $context); | ||
| 39 | |||
| 40 | Run C<findvalue> for C<$path> in C<$context> and return its result as a plain | ||
| 41 | string. The rest of the C<XML::XPath> API (C<new>, C<find>, C<findnodes>, ...) | ||
| 42 | is inherited unchanged. | ||
| 43 | |||
| 44 | =head1 AUTHOR | ||
| 45 | |||
| 46 | The oEdtk team. | ||
| 47 | |||
| 48 | =cut | ||