| 1 | # | ||||||||||
| 2 | # Copyright (c) 2013-2019 Christian Jaeger, copying@christianjaeger.ch | ||||||||||
| 3 | # | ||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||
| 7 | # bundled with this file. | ||||||||||
| 8 | # | ||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | PXML::Tags | ||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use PXML::Tags qw(records | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | protocol-version | ||||||||||
| 18 | 1 | record); | |||||||||
| 19 | my $xml = RECORDS(PROTOCOL_VERSION("1.0"), | ||||||||||
| 20 | RECORD("Hi"), RECORD("there!")); | ||||||||||
| 21 | is ref($xml), "PXML::Element"; | ||||||||||
| 22 | is $xml->string, '<records><protocol-version>1.0</protocol-version><record>Hi</record><record>there!</record></records>'; | ||||||||||
| 23 | |||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||
| 25 | |||||||||||
| 26 | Creates tag wrappers that return PXML elements. The names of the | ||||||||||
| 27 | wrappers are all uppercase, and "-" is replaced with "_". | ||||||||||
| 28 | |||||||||||
| 29 | =head1 NOTE | ||||||||||
| 30 | |||||||||||
| 31 | This is alpha software! Read the status section in the package README | ||||||||||
| 32 | or on the L<website|http://functional-perl.org/>. | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | package PXML::Tags; | ||||||||||
| 37 | |||||||||||
| 38 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 4 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | |||||||||||
| 42 | 4 | ▶ | use PXML::Element; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | |||||||||||
| 44 | 11 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||
| 45 | 11 | my $caller = caller; | |||||||||
| 46 | 11 | for my $name (@_) { | |||||||||
| 47 | 35 | my $fname = uc $name; | |||||||||
| 48 | 35 | $fname =~ s/-/_/sg; | |||||||||
| 49 | 35 | my $fqname = "${caller}::$fname"; | |||||||||
| 50 | 4 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 37 | ▶ | *$fqname = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 52 | 37 | ▶ | my $atts = ref($_[0]) eq "HASH" ? shift : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 37 | PXML::Element->new($name, $atts, [@_]); | |||||||||
| 54 | 35 | }; | |||||||||
| 55 | } | ||||||||||
| 56 | 1 | ||||||||||
| 57 | 11 | } | |||||||||
| 58 | |||||||||||
| 59 | 4 | 1 | |||||||||