⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.pm

📁 网页留言本,比一般的留言簿管用
💻 PM
字号:
# $Id: Util.pm 4536 2004-05-11 05:33:05Z btrott $package XML::Atom::Util;use strict;use XML::Atom;use vars qw( @EXPORT_OK @ISA );use Exporter;@EXPORT_OK = qw( first textValue iso2dt encode_xml );@ISA = qw( Exporter );sub first {    if (LIBXML) {        my @res = $_[1] ? $_[0]->getElementsByTagNameNS($_[1], $_[2]) :                          $_[0]->getElementsByTagName($_[2]);        return unless @res;        return $res[0];    } else {        my $set = $_[1] ?            $_[0]->find("descendant::*[local-name()='$_[2]' and namespace-uri()='$_[1]']") :            $_[0]->find("descendant::$_[2]");        return unless $set && $set->isa('XML::XPath::NodeSet');        ($set->get_nodelist)[0];    }}sub textValue {    my $node = first(@_) or return;    LIBXML ? $node->textContent : $node->string_value;}sub iso2dt {    my($iso) = @_;    return unless $iso =~ /^(\d{4})(?:-?(\d{2})(?:-?(\d\d?)(?:T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-]\d{2}:\d{2}))?)?)?)?/;    my($y, $mo, $d, $h, $m, $s, $zone) =        ($1, $2 || 1, $3 || 1, $4 || 0, $5 || 0, $6 || 0, $7);    require DateTime;    my $dt = DateTime->new(               year => $y,               month => $mo,               day => $d,               hour => $h,               minute => $m,               second => $s,               time_zone => 'UTC',    );    if ($zone && $zone ne 'Z') {        my $seconds = DateTime::TimeZone::offset_as_seconds($zone);        $dt->subtract(seconds => $seconds);    }    $dt;}my %Map = ('&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;',           '\'' => '&apos;');my $RE = join '|', keys %Map;sub encode_xml {    my($str) = @_;    $str =~ s!($RE)!$Map{$1}!g;    $str;}1;__END__=head1 NAMEXML::Atom::Util - Utility functions=head1 SYNOPSIS    use XML::Atom::Util qw( iso2dt );    my $dt = iso2dt($entry->issued);=head1 USAGE=head2 iso2dt($iso)Transforms the ISO-8601 date I<$iso> into a I<DateTime> object and returnsthe I<DateTime> object.=head2 encode_xml($str)Encodes characters with special meaning in XML into entities and returnsthe encoded string.=head1 AUTHOR & COPYRIGHTPlease see the I<XML::Atom> manpage for author, copyright, and licenseinformation.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -