view release on metacpan or search on metacpan
lib/MOSES/MOBY/Data/Object.pm view on Meta::CPAN
# types) of the names whose values are not object references
sub _add_XML_element {
my ($self, $name, $value, $root) = @_;
my (%special_names) =
(xrefs => 1,
provision => 1,
);
if ($name eq 'value' and $self->primitive) {
if (defined $value) {
if ($self->{cdata}) { # don't use: $self->cdata because not everybody has it
$root->appendChild (XML::LibXML::CDATASection->new ($self->_express_value ($value)));
} else {
$root->appendText ($self->_express_value ($value));
}
}
return;
}
if (ref ($value)) {
if ($special_names{$name}) {
return;
lib/MOSES/MOBY/Data/String.pm view on Meta::CPAN
# create a Moby String with initial value of 'eddie'
my $data = MOSES::MOBY::Data::String->new (value => 'eddie');
my $data = MOSES::MOBY::Data::String->new ('eddie');
# later change the value of this data object
$data->value ('tulak');
print $data->value();
# indicate that the value should be treated as CDATA
$data->cdata (1);
print $data->toXML->toString;
=head1 DESCRIPTION
An object representing a String, a Moby primitive data type.
=head1 AUTHORS
Edward Kawas (edward.kawas [at] gmail [dot] com)
Martin Senger (martin.senger [at] gmail [dot] com)
lib/MOSES/MOBY/Data/String.pm view on Meta::CPAN
Details are in L<MOSES::MOBY::Base>. Here just a list of them (additionally
to the attributes from the parent classes)
=over
=item B<value>
A value of this datatype. Must be an integer.
=item B<cdata>
Boolean. If set to true the value will be wrapped as CDATA in the XML
representing this object.
=back
=cut
{
my %_allowed =
(
value => {type => MOSES::MOBY::Base->STRING},
cdata => {type => MOSES::MOBY::Base->BOOLEAN},
);
sub _accessible {
my ($self, $attr) = @_;
exists $_allowed{$attr} or $self->SUPER::_accessible ($attr);
}
sub _attr_prop {
my ($self, $attr_name, $prop_name) = @_;
my $attr = $_allowed {$attr_name};
return ref ($attr) ? $attr->{$prop_name} : $attr if $attr;
lib/MOSES/MOBY/Data/String.pm view on Meta::CPAN
}
}
#-----------------------------------------------------------------
# init
#-----------------------------------------------------------------
sub init {
my ($self) = shift;
$self->SUPER::init();
$self->primitive ('yes');
$self->cdata ('no');
}
1;
__END__
lib/MOSES/MOBY/Package.pm view on Meta::CPAN
#-----------------------------------------------------------------
# A list of allowed attribute names. See MOSES::MOBY::Base for details.
#-----------------------------------------------------------------
{
my %_allowed =
(
authority => undef,
jobs => {type => 'MOSES::MOBY::Job', is_array => 1},
exceptions => {type => 'MOSES::MOBY::ServiceException', is_array => 1},
serviceNotes => undef,
cdata => {type => MOSES::MOBY::Base->BOOLEAN},
);
sub _accessible {
my ($self, $attr) = @_;
exists $_allowed{$attr} or $self->SUPER::_accessible ($attr);
}
sub _attr_prop {
my ($self, $attr_name, $prop_name) = @_;
my $attr = $_allowed {$attr_name};
return ref ($attr) ? $attr->{$prop_name} : $attr if $attr;
return $self->SUPER::_attr_prop ($attr_name, $prop_name);
}
}
#-----------------------------------------------------------------
# init
#-----------------------------------------------------------------
sub init {
my ($self) = shift;
$self->SUPER::init();
$self->cdata ('no');
}
#-----------------------------------------------------------------
# job_by_id
#-----------------------------------------------------------------
=head2 job_by_id
In this package, find and return a C<MOSES::MOBY::Job> object with the given
ID. Or throw an exception if such job does not exist. (TBD)
lib/MOSES/MOBY/Package.pm view on Meta::CPAN
my $self = shift;
$self->increaseXMLCounter;
my $root = $self->createXMLElement (MOBY);
my $elemContent = $self->createXMLElement (MOBYCONTENT);
$self->setXMLAttribute ($elemContent, AUTHORITY, $self->authority);
if ($self->serviceNotes or $self->{exceptions}) {
my $sNotes = $self->createXMLElement (SERVICENOTES);
if ($self->serviceNotes) {
my $notes = $self->createXMLElement (NOTES);
if ($self->cdata) {
$notes->appendChild (XML::LibXML::CDATASection->new ($self->serviceNotes));
} else {
$notes->appendText ($self->serviceNotes);
}
$sNotes->appendChild ($notes);
}
if ($self->exceptions) {
foreach my $exception (@{ $self->exceptions }) {
$sNotes->appendChild ($exception->toXML);
}
lib/MOSES/MOBY/Parser.pm view on Meta::CPAN
#-----------------------------------------------------------------
# init
#-----------------------------------------------------------------
sub init {
my ($self) = shift;
$self->SUPER::init();
$self->lowestKnownDataTypes ({});
}
my %pcdataNames ;
my %pcdataNamesForPrimitives;
my @pcdataNamesArray;
my @pcdataNamesArrayForPrimitives;
# special logger just for the parser
my $PLOG;
BEGIN {
@pcdataNamesArray =
( NOTES, SERVICECOMMENT, VALUE, XREF, EXCEPTIONCODE, EXCEPTIONMESSAGE );
@pcdataNamesArrayForPrimitives =
( MOBYSTRING, MOBYINTEGER, MOBYFLOAT, MOBYBOOLEAN, MOBYDATETIME );
foreach (@pcdataNamesArray) {
$pcdataNames{$_} = 1;
}
foreach (@pcdataNamesArrayForPrimitives) {
$pcdataNamesForPrimitives{$_} = 1;
}
# special logger just for the parser because debugging level from
# the parser clutters other logging too much
use Log::Log4perl qw(get_logger :levels :no_extra_logdie_message);
$PLOG = get_logger ('parser');
}
############################################################
# GLOBAL VARIABLES
############################################################
my %generated; # keep track of whether a type was generated or not
my @objectStack; # type MobyObject
my @pcdataStack; # strings
my $readingMobyObject = 0; # true if inside Simple
my $readingCollection = 0; # true if inside collection
my $readingXrefs = 0; # true if inside Crossreference
my $readingProvision = 0; # true if inside provision information
my $insubstitution = 0; # when just using 'lowestKnownDataTypes' it contains a name of substituted element
my $inServiceNotes = 0; # true if inside serviceNotes
my $inMobyException = 0;
my $ignoring = 0; # count depth of ignored (unknown) data objects
my $result; # type MobyPackage - the whole result
my @articleNames;
lib/MOSES/MOBY/Parser.pm view on Meta::CPAN
# Value The normalized value of the attribute.
# NamespaceURI The namespace of this attribute.
# Prefix The namespace prefix used on this attribute.
# LocalName The local name of this attribute.
$PLOG->debug ("Starting element $element->{Name} with local name $element->{LocalName} \n");
if ( $ignoring > 0 ) {
$ignoring++;
return;
}
if ( exists $pcdataNames{ $element->{LocalName} } ) {
my $st = "";
push @pcdataStack, \$st;
}
if ($readingMobyObject) {
if ( exists $pcdataNamesForPrimitives{ $element->{LocalName} } ) {
my $st = "";
push @pcdataStack, \$st;
}
}
if ($readingMobyObject) {
if ( $element->{LocalName} eq PROVISIONINFORMATION ) {
push @objectStack, \MOSES::MOBY::Data::ProvisionInformation->new();
$readingProvision = 1;
}
elsif ( $element->{LocalName} eq CROSSREFERENCE ) {
$readingXrefs = 1;
}
lib/MOSES/MOBY/Parser.pm view on Meta::CPAN
$obj = pop @objectStack;
$obj = ${$obj};
${ $self->vPeek("MOSES::MOBY::Data::Object") }->provision($obj);
$readingProvision = 0;
}
elsif ( $element->{LocalName} eq CROSSREFERENCE ) {
$readingXrefs = 0;
}
elsif ($readingXrefs) {
if ( $element->{LocalName} eq XREF ) {
$obj = pop @pcdataStack;
$obj = ${$obj};
${ $self->vPeek("MOSES::MOBY::Data::Xref") }
->description($obj);
$obj = pop @objectStack;
$obj = ${$obj};
${ $self->vPeek("MOSES::MOBY::Data::Object") }->add_xrefs($obj);
}
elsif ( $element->{LocalName} eq MOBYOBJECT ) {
$obj = pop @objectStack;
$obj = ${$obj};
${ $self->vPeek("MOSES::MOBY::Data::Object") }->add_xrefs($obj);
}
}
elsif ($readingProvision) {
if ( $element->{LocalName} eq SERVICECOMMENT ) {
$obj = pop @pcdataStack;
$obj = ${$obj};
${ $self->vPeek("MOSES::MOBY::Data::ProvisionInformation") }
->serviceComment($obj);
}
}
else {
if ($insubstitution or $generated{$element->{LocalName}}) {
my $mobyObj = pop @objectStack;
$mobyObj = ${$mobyObj};
if ( $insubstitution
and $element->{LocalName} eq $insubstitution ) {
$insubstitution = 0;
}
if ( exists $pcdataNamesForPrimitives{ $element->{LocalName} } )
{
my $value = pop @pcdataStack;
$value = ${$value};
$mobyObj->value($value);
}
$obj2 = ${ $self->peek() };
if ( $obj2->isa("MOSES::MOBY::Simple") ) {
$obj2->data($mobyObj);
}
else {
# save original article name in data object itself
lib/MOSES/MOBY/Parser.pm view on Meta::CPAN
$obj = ${$obj};
${ $self->vPeek("MOSES::MOBY::Job") }->add_dataElements($obj);
$readingCollection = 0;
}
elsif ( $element->{LocalName} eq PARAMETER ) {
$obj = pop @objectStack;
$obj = ${$obj};
${ $self->vPeek("MOSES::MOBY::Job") }->add_dataElements($obj);
}
elsif ( $element->{LocalName} eq NOTES ) {
$obj = pop @pcdataStack;
$obj = ${$obj};
${ $self->vPeek("MOSES::MOBY::Package") }->serviceNotes($obj);
}
elsif ( $element->{LocalName} eq EXCEPTIONCODE ) {
$obj = pop @pcdataStack;
$obj = ${$obj};
if ($inMobyException) {
${ $self->vPeek("MOSES::MOBY::ServiceException") }->code($obj);
}
}
elsif ( $element->{LocalName} eq EXCEPTIONMESSAGE ) {
$obj = pop @pcdataStack;
$obj = ${$obj};
if ($inMobyException ){
${ $self->vPeek("MOSES::MOBY::ServiceException") }->message($obj);
}
}
elsif ( $element->{LocalName} eq VALUE ) {
$obj = pop @pcdataStack;
$obj = ${$obj};
${ $self->vPeek("MOSES::MOBY::Parameter") }->value($obj);
}
$PLOG->debug ($self->printInfo) if $PLOG->is_debug;
}
sub characters {
my ( $self, $characters ) = @_;
$PLOG->debug ("characters: $characters->{Data}\n") if $PLOG->is_debug;
# characters is a hash reference with this property:
# Data The characters from the XML document.
if ( @pcdataStack . "" == 0 ) {
return;
}
my $text = $characters->{Data};
$text =~ s/^\s+//;
$text =~ s/\s+$//;
${ $self->pcdataPeek() } = ${ $self->pcdataPeek() } . $text;
}
sub start_document {
my ( $self, $document ) = @_;
@objectStack = ();
@articleNames = ();
@pcdataStack = ();
$ignoring = 0;
}
sub end_document {
my ( $self, $document ) = @_;
@objectStack = undef;
@pcdataStack = undef;
$ignoring = 0;
}
sub ignorable_whitespace {
my ( $self, $characters ) = @_;
}
# returns type MobyObject or dies if shouldBeThere->isa(ref(objectStack.top))
sub vPeek {
my ( $self, $shouldBeThere ) = @_;
lib/MOSES/MOBY/Parser.pm view on Meta::CPAN
sub peek {
my ($self) = @_;
# my version of peek
my $obj = pop @objectStack;
push @objectStack, $obj;
return $obj;
}
# returns string references
sub pcdataPeek {
my ($self) = @_;
# my version of peek
my $obj = pop @pcdataStack;
push @pcdataStack, $obj;
return $obj;
}
# returns the value of an attribute either using a namespace or not
# attributes=>, name=>
sub getValue {
my ( $self, %hash) = @_;
my (%attributes, $name);
%attributes = %{$hash{attributes}} if exists $hash{attributes};
lib/MOSES/MOBY/Parser.pm view on Meta::CPAN
use Data::Dumper;
my $buf =
"##########################################################\n"
. "# INFO #\n"
. "##########################################################\n"
. "Object stack currently holds:\n\tBOTTOM: ";
foreach (@objectStack) {
$buf .= Dumper($$_) . "\n";
}
$buf .= "TOP\n";
$buf .= "pcdataStack currently holds:\n\tBOTTOM: ";
foreach (@pcdataStack) {
$buf .= Dumper($$_) . "\n";
}
$buf .= "TOP\n";
$buf .=
"readingMobyObject: $readingMobyObject\n"
. "readingCollection: $readingCollection\n"
. "readingXrefs : $readingXrefs\n"
. "readingProvision : $readingProvision\n"
. "insubstition : $insubstitution\n"
. "inServiceNotes : $inServiceNotes\n"