package Ernad::Sausage; use strict; use warnings; use Carp qw(confess); use Krichel::Shonu; my $ernad_ns = $Ernad::Constant::c->{'ernad_ns'}; my $amf_ns = $Ernad::Constant::c->{'amf_ns'}; ## is used in non-Ernad namf generating software our $sos_ele_name='sausage'; sub has_it { my $doc=shift; my $ref_doc; $ref_doc=ref $doc; if($ref_doc ne 'XML::LibXML::Document') { confess "I need an XML document, but you gave me '$ref_doc'"; } my $sos_count=$doc->getElementsByTagNameNS($ernad_ns,$sos_ele_name)->size(); return $sos_count; } sub inject { my $doc=shift; my $ref_doc; $ref_doc=ref $doc; if($ref_doc ne 'XML::LibXML::Document') { confess "I need an XML document, but you gave me '$ref_doc'"; } ## if it's there don't do it again if(&has_it($doc)) { return 0; } my @text_elements=$doc->getElementsByTagNameNS($amf_ns,'text')->get_nodelist(); my $text_count=$doc->getElementsByTagNameNS($amf_ns,'text')->size(); my $count_texts=0; while($count_texts < $text_count) { my $text_ele=$text_elements[$count_texts]; ## now start counting from 1 $count_texts++; my $sos_ele=$doc->createElementNS($ernad_ns,$sos_ele_name); $sos_ele->setAttribute('decim',$count_texts); my $shonu=&Krichel::Shonu::make($count_texts); $sos_ele->setAttribute('shonu',$shonu); $text_ele->appendText(" \n"); $text_ele->appendChild($sos_ele); $text_ele->appendText(" \n"); } return 1; } 1;