| 1 | |||
| 2 | package DBIx::Romani::Query::XML::Function; | ||
| 3 | |||
| 4 | use DBIx::Romani::Query::XML::Util; | ||
| 5 | use DBIx::Romani::Query::XML::TTT; | ||
| 6 | use DBIx::Romani::Query::XML::SQL; | ||
| 7 | use DBIx::Romani::Query::Function::Count; | ||
| 8 | use XML::DOM; | ||
| 9 | use strict; | ||
| 10 | |||
| 11 | use Data::Dumper; | ||
| 12 | |||
| 13 | sub create_function_from_node | ||
| 14 | { | ||
| 15 | my $func_node = shift; | ||
| 16 | |||
| 17 | my $name = $func_node->getLocalName(); | ||
| 18 | my $ns_uri = $func_node->getNamespaceURI(); | ||
| 19 | |||
| 20 | my $func; | ||
| 21 | |||
| 22 | if ( $ns_uri eq $DBIx::Romani::Query::XML::Util::NS_QUERY_FUNCTION ) | ||
| 23 | { | ||
| 24 | if ( $name eq 'count' ) | ||
| 25 | { | ||
| 26 | $func = DBIx::Romani::Query::Function::Count->new(); | ||
| 27 | $func->set_distinct( DBIx::Romani::Query::XML::Util::get_boolean( $func_node, 'distinct', 0 ) ); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | if ( not defined $func ) | ||
| 32 | { | ||
| 33 | die "Unknown function tag \"$ns_uri\" \"$name\""; | ||
| 34 | } | ||
| 35 | |||
| 36 | # add the children to the function | ||
| 37 | my $node = $func_node->getFirstChild(); | ||
| 38 | while ( defined $node ) | ||
| 39 | { | ||
| 40 | if ( $node->getNodeType() == XML::DOM::ELEMENT_NODE ) | ||
| 41 | { | ||
| 42 | my $value = DBIx::Romani::Query::XML::SQL::create_value_from_node( $node ); | ||
| 43 | if ( not defined $value ) | ||
| 44 | { | ||
| 45 | die "Function \"$name\" contains invalid value"; | ||
| 46 | } | ||
| 47 | |||
| 48 | $func->add( $value ); | ||
| 49 | } | ||
| 50 | |||
| 51 | $node = $node->getNextSibling(); | ||
| 52 | } | ||
| 53 | |||
| 54 | return $func; | ||
| 55 | } | ||
| 56 | |||
| 57 | 1; | ||
| 58 |