| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::SMS::ASPSMS::XML; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 27508 | use warnings; | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 84 |  | 
| 4 | 2 |  |  | 2 |  | 12 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 77 |  | 
| 5 | 2 |  |  | 2 |  | 12 | use Carp; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 260 |  | 
| 6 |  |  |  |  |  |  | #use Unicode::String qw(utf8); | 
| 7 | 2 |  |  | 2 |  | 1750 | use overload q("") => \&as_string; | 
|  | 2 |  |  |  |  | 1213 |  | 
|  | 2 |  |  |  |  | 20 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our $VERSION = '1.0.2'; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | my @valid_tags = qw( | 
| 12 |  |  |  |  |  |  | Userkey AffiliateId Password Originator UsedCredits | 
| 13 |  |  |  |  |  |  | Recipient_PhoneNumber Recipient_TransRefNumber | 
| 14 |  |  |  |  |  |  | DeferredDeliveryTime LifeTime MessageData URLBinaryFile | 
| 15 |  |  |  |  |  |  | FlashingSMS BlinkingSMS MCC MNC | 
| 16 |  |  |  |  |  |  | URLBufferedMessageNotification URLDeliveryNotification | 
| 17 |  |  |  |  |  |  | URLNonDeliveryNotification TimeZone XSer BinaryFileDataHex | 
| 18 |  |  |  |  |  |  | TransRefNumber ReplaceMessage | 
| 19 |  |  |  |  |  |  | VCard_VName VCard_VPhoneNumber | 
| 20 |  |  |  |  |  |  | WAPPushDescription WAPPushURL OriginatorUnlockCode Action | 
| 21 |  |  |  |  |  |  | ); | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | my %valid_tags = (); | 
| 24 |  |  |  |  |  |  | @valid_tags{map {lc($_), $_} @valid_tags} = @valid_tags; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub new { | 
| 27 | 3 |  |  | 3 | 0 | 366 | my $this = shift; | 
| 28 | 3 |  | 33 |  |  | 16 | my $class = ref($this) || $this; | 
| 29 | 3 |  |  |  |  | 8 | my $self = {}; | 
| 30 | 3 |  |  |  |  | 9 | bless $self, $class; | 
| 31 | 3 |  |  |  |  | 11 | $self->initialize(@_); | 
| 32 | 3 |  |  |  |  | 11 | return $self; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub initialize { | 
| 36 | 3 |  |  | 3 | 0 | 4 | my $self = shift; | 
| 37 | 3 | 100 | 100 |  |  | 22 | my $arg = defined($_[0]) && ref($_[0]) eq 'HASH' ? $_[0] : {@_}; | 
| 38 | 3 |  |  |  |  | 13 | foreach (keys %$arg) { | 
| 39 | 3 | 50 |  |  |  | 12 | if (exists $valid_tags{lc($_)}) { | 
| 40 | 3 |  |  |  |  | 15 | $self->{data}->{lc($_)} = $arg->{$_} | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub as_string { | 
| 46 | 13 |  |  | 13 | 0 | 36 | my $self = shift; | 
| 47 | 13 |  |  |  |  | 19 | my $encoding = shift; | 
| 48 | 13 | 50 |  |  |  | 36 | $encoding = "ISO-8859-1" if not defined $encoding; | 
| 49 | 13 |  |  |  |  | 18 | my $container = ''; | 
| 50 | 13 |  |  |  |  | 29 | my $result = "\n"; | 
| 51 | 13 |  |  |  |  | 18 | $result .= "\n"; | 
| 52 | 13 |  |  |  |  | 26 | foreach (@valid_tags) { | 
| 53 | 377 | 100 |  |  |  | 975 | if (exists $self->{data}->{lc($_)}) { | 
| 54 | 38 | 100 |  |  |  | 132 | my ($c, $tag) = /^(.*)_(.*)/ ? ($1, $2) : ('', $_); | 
| 55 | 38 |  |  |  |  | 76 | my $content =  $self->{data}->{lc($_)}; | 
| 56 | 38 | 100 |  |  |  | 87 | if ($c ne $container) { | 
| 57 | 15 | 100 |  |  |  | 37 | $result .= "  $container>\n" if $container; | 
| 58 | 15 | 100 |  |  |  | 45 | $result .= "  <$c>\n" if $c; | 
| 59 | 15 |  |  |  |  | 19 | $container = $c; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | #$content = utf8($content)->latin1; | 
| 62 | 38 |  |  |  |  | 76 | $content =~ s/([\x26\x3c\x3e\x80-\xff])/'' . ord($1) . ';'/xeg; | 
|  | 15 |  |  |  |  | 56 |  | 
| 63 | 38 | 100 |  |  |  | 82 | $result .= "  " if $container; | 
| 64 | 38 |  |  |  |  | 699 | $result .= "  <$tag>" . $content . "$tag>\n"; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  | } | 
| 67 | 13 | 100 |  |  |  | 39 | $result .= "  $container>\n" if $container; | 
| 68 | 13 |  |  |  |  | 24 | $result .= ""; | 
| 69 | 13 |  |  |  |  | 55 | return $result | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | sub AUTOLOAD { | 
| 73 | 5 | 50 |  | 5 |  | 62 | my $self = shift or return undef; | 
| 74 | 5 |  |  |  |  | 31 | (my $method = our $AUTOLOAD) =~ s{.*::}{}; | 
| 75 | 5 | 50 |  |  |  | 15 | return if $method eq 'DESTROY'; | 
| 76 | 5 | 50 | 33 |  |  | 29 | if (exists $valid_tags{lc($method)} and defined $_[0]) { | 
| 77 | 5 |  |  |  |  | 23 | $self->{data}->{lc($method)} = $_[0] | 
| 78 |  |  |  |  |  |  | } else { | 
| 79 | 0 |  |  |  |  |  | croak "unknown method $method\n" | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | 1; | 
| 84 |  |  |  |  |  |  | __END__ |