File Coverage

blib/lib/POE/Component/MXML.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package POE::Component::MXML;
2              
3 1     1   889 use strict;
  1         2  
  1         32  
4 1     1   4 use vars qw($VERSION);
  1         1  
  1         52  
5              
6             $VERSION = '0.03';
7              
8 1     1   4 use Carp qw(croak);
  1         5  
  1         54  
9              
10 1     1   1519 use POE::Session;
  0            
  0            
11              
12             sub DEBUG () { 0 }
13              
14             sub spawn {
15             my ($type) = shift;
16              
17             croak qq($type requires an even number of parameters.)
18             if @_ % 2;
19              
20             my %params = @_;
21             #
22             # Validate passed-in parameters
23             #
24             exists $params{Alias} or
25             croak qq($type requires an Alias parameter.);
26             exists $params{InputHandle} or
27             croak qq($type requires an Input handle.);
28             exists $params{Tag} or
29             croak qq($type requires a Tag event to trigger.);
30             #
31             # Default parameter values
32             #
33              
34             my $states = { _start => \&poco_mxml_start,
35             get_tag => \&poco_mxml_get_tag,
36             };
37             if(ref(\$params{InputHandle}) eq 'SCALAR') { # Assume it's a file or text.
38             if(-e $params{InputHandle}) {
39             open FILE,"<$params{InputHandle}" or
40             croak qq($type could not open $params{InputHandle}.);
41             $params{Data} = join '',;
42             close FILE;
43             } else {
44             $params{Data} = $params{InputHandle};
45             }
46             } elsif(ref(\$params{InputHandle}) eq 'ARRAY') {
47             } elsif(ref(\$params{InputHandle}) eq 'HASH') {
48             } else {
49             }
50              
51             DEBUG and do {
52             warn <<_EOF_;
53              
54             /--- spawning $type component --
55             | Alias : $params{Alias}
56             | Tag : $params{Tag}
57             | InputHandle : $params{InputHandle}
58             | Data : $params{Data}
59             \\---
60             _EOF_
61             };
62              
63             POE::Session->create
64             ( inline_states => $states,
65             args => [%params],
66             );
67             undef;
68             }
69              
70             #------------------------------------------------------------------------------
71              
72             sub poco_mxml_start {
73             my ($kernel,$heap) =
74             @_[KERNEL,HEAP];
75             for(my $i=ARG0; $i<@_; $i+=2)
76             { $heap->{$_[$i]}=$_[$i+1] }
77             $kernel->alias_set($heap->{Alias});
78             }
79              
80             sub poco_mxml_get_tag {
81             my ($heap,$sender) =
82             @_[HEAP,SENDER];
83              
84             if($heap->{Data} =~ s,^<([^>]+)>([^<]*),,s) { # Complete
85             warn "Complete Tag : <$1>$2" if DEBUG;
86             $sender->postback($heap->{Tag})->('Tag',$1,$2);
87             } elsif($heap->{Data} =~ s,^<([^>]+)>([^<]+),,s) { # Open Tag
88             warn "Opening Tag : <$1>$2" if DEBUG;
89             push @{$heap->{tagstack}},$1;
90             $sender->postback($heap->{Tag})->('Open_Tag',$1,$2);
91             } elsif($heap->{Data} =~ s,^([^<]+),,s) { # Close Tag
92             warn "Closing Tag : $2" if DEBUG;
93             pop @{$heap->{tagstack}};
94             $sender->postback($heap->{Tag})->('Close_Tag',$2,$1);
95             } elsif($heap->{Data} =~ s,^([^<]+)<(\w+)>,<$2>,s) { # Inter Tag
96             my $foo = $heap->{tagstack}[-1];
97             warn "Inter Tag : <$foo>$1" if DEBUG;
98             $sender->postback($heap->{Tag})->('Inter Tag',$foo,$1);
99             }
100             }
101              
102             1;
103             __END__