U
/usr/ceo
I've had a need for this at points in the past, but was always able to
code around it (and still could even now), but I'd really like to be
able to do this, and I can't find anything out there that does this
exactly as I want. (Which tends to make me believe what I want
wouldn't be as immediately useful as maybe I would think it to be,
but...?!)
Given an object defined as this:
package Person;
use strict;
use warnings qw( all );
sub new {
my $proto = shift;
my $class = ref $proto || $proto;
my %attrs = @_;
my $self = {};
# Nevermind the error checking for attributes right now.
$self->{__name} = $attrs{name};
$self->{__age} = $attrs{age};
bless $class, $self;
return $self;
}
# RW attributes.
sub name { $s = shift; $s->{__name} = shift if @_; return $s-
# Methods.
sub sayName { print "My name is: " . shift->{__name} . "\n" }
sub sayAge { print "I am " . shift->{__age} . " years old.\n" }
1;
I want to be able to read the following XML and create instances of
Person from each instance in the XML:
<xml>
<People>
<Person name="John Doe" age="22" />
<Person name="Jane Doe" age="23" />
<Person name="Maxx Doogan" age="10" />
</People>
</xml>
So I get an array of Person objects which I can then write:
my @people; # Hold the array of Person object created from the XML
above.
for my $person (@people) {
$person->sayName();
$person->sayAge();
}
I've looked through SOAP::Lite (and SOAP::Serialize and
SOAP:eserialize). I'm a fairly frequent user of XML::Simple, but
Simple doesn't do the above (AFAIK). SURELY *something* like this is
"out there" (read "CPAN") but I can't seem to find it; only things
close to it (like SOAP::SOM objects that require an xpath of sorts and
my methods are still not available through an instantiated method of
just the data [object attributes] in XML.)
Thanks!
/usr/ceo
code around it (and still could even now), but I'd really like to be
able to do this, and I can't find anything out there that does this
exactly as I want. (Which tends to make me believe what I want
wouldn't be as immediately useful as maybe I would think it to be,
but...?!)
Given an object defined as this:
package Person;
use strict;
use warnings qw( all );
sub new {
my $proto = shift;
my $class = ref $proto || $proto;
my %attrs = @_;
my $self = {};
# Nevermind the error checking for attributes right now.
$self->{__name} = $attrs{name};
$self->{__age} = $attrs{age};
bless $class, $self;
return $self;
}
# RW attributes.
sub name { $s = shift; $s->{__name} = shift if @_; return $s-
sub age { $s = shift; $s->{__age} = shift if @_; return $s->{__age} }{__name} }
# Methods.
sub sayName { print "My name is: " . shift->{__name} . "\n" }
sub sayAge { print "I am " . shift->{__age} . " years old.\n" }
1;
I want to be able to read the following XML and create instances of
Person from each instance in the XML:
<xml>
<People>
<Person name="John Doe" age="22" />
<Person name="Jane Doe" age="23" />
<Person name="Maxx Doogan" age="10" />
</People>
</xml>
So I get an array of Person objects which I can then write:
my @people; # Hold the array of Person object created from the XML
above.
for my $person (@people) {
$person->sayName();
$person->sayAge();
}
I've looked through SOAP::Lite (and SOAP::Serialize and
SOAP:eserialize). I'm a fairly frequent user of XML::Simple, but
Simple doesn't do the above (AFAIK). SURELY *something* like this is
"out there" (read "CPAN") but I can't seem to find it; only things
close to it (like SOAP::SOM objects that require an xpath of sorts and
my methods are still not available through an instantiated method of
just the data [object attributes] in XML.)
Thanks!
/usr/ceo