Skip Menu |

This queue is for tickets about the XML-Rabbit CPAN distribution.

Report information
The Basics
Id: 81780
Status: resolved
Worked: 10 min
Priority: 0/
Queue: XML-Rabbit

People
Owner: Nobody in particular
Requestors: arfreitas [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.2.1
Fixed in: (no value)



Subject: add validation of values recovered from XML data
I tried to use a Moose::Role (attached) to validate data recovered from the package below: package Siebel::Monitor::Server::Component; use warnings; use strict; use XML::Rabbit; has_xpath_value 'name' => './@name'; has_xpath_value 'description' => './@description'; has_xpath_value 'componentGroup' => './@ComponentGroup'; has_xpath_value 'OKStatus' => './@OKStatus'; has_xpath_value 'criticality' => './@criticality'; with 'Siebel::Srvrmgr::Daemon::Action::CheckComps::Component'; finalize_class(); I used a empty value in the "criticality" element in the XML and a exception did not occur as I expected. It would be cool to be able to validate what a the XML::Rabbit::Node instance expects for it's attributes, using a Moose::Role or anything else.
Subject: Component.pm
package Siebel::Srvrmgr::Daemon::Action::CheckComps::Component; use Moose::Role; =pod =head1 NAME Siebel::Srvrmgr::Daemon::Action::CheckComps::Component - role for classes that hold Siebel server components information =head1 DESCRIPTION This class is a role, not a subclass of L<Siebel::Srvrmgr::Daemon::Action::CheckComps>. It is intended to be used by classes that provides information about which components are available in a Siebel server and which is their expected status. =head1 ATTRIBUTES =head2 name A string representing the name of the component. =cut has name => ( isa => 'Str', is => 'ro', required => 1 ); =pod =head2 description A string representing the description of the component. =cut has description => ( isa => 'Str', is => 'ro', required => 1 ); =pod =head2 componentGroup A string representing the Component Group alias that this component is part of. =cut has componentGroup => ( isa => 'Str', is => 'ro', required => 1 ); =pod =head2 OKStatus The status that the component is expected to have. It may be one, several (concatenated with a pipe character) or none. =cut has OKStatus => ( isa => 'Str', is => 'ro', required => 1 ); =pod =head2 criticality A integer indicating how critical it is if the component does not have the expected status: the largest the number, the more critical it is. =cut has criticality => ( isa => 'Int', is => 'ro', required => 1 ); =pod =head1 METHODS One for each one of the attributes, with the same name for invocation. Those methods B<must> be overrided by the classes that applies this role or an exception will be raised. =cut requires 'name'; requires 'description'; requires 'componentGroup'; requires 'OKStatus'; requires 'criticality'; =pod =head1 SEE ALSO =over 2 =item * L<Siebel::Srvrmgr::Daemon::Action::CheckComps> =item * L<Siebel::Srvrmgr::Daemon::Action::CheckComps::Server> =back =head1 AUTHOR Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.org<E<gt> =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.org<E<gt> This file is part of Siebel Monitoring Tools. Siebel Monitoring Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Siebel Monitoring Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Siebel Monitoring Tools. If not, see <http://www.gnu.org/licenses/>. =cut 1;
On Fri Dec 07 19:12:13 2012, ARFREITAS wrote: Show quoted text
> I tried to use a Moose::Role (attached) to validate data recovered > from the package below: > > package Siebel::Monitor::Server::Component; > use warnings; > use strict;
When you use XML::Rabbit it automatically sets strict+warnings for you. The two above lines are redundant. Show quoted text
> use XML::Rabbit; > > has_xpath_value 'name' => './@name'; > has_xpath_value 'description' => './@description'; > has_xpath_value 'componentGroup' => './@ComponentGroup'; > has_xpath_value 'OKStatus' => './@OKStatus'; > has_xpath_value 'criticality' => './@criticality'; > > with 'Siebel::Srvrmgr::Daemon::Action::CheckComps::Component'; > > finalize_class(); > > I used a empty value in the "criticality" element in the XML and a > exception did not occur as I expected. > > It would be cool to be able to validate what a the XML::Rabbit::Node > instance expects for it's attributes, using a Moose::Role or anything
else. You can change the definition of 'criticality' to include any valid Moose attribute definition. Changing it to e.g. has_xpath_value 'criticality' => './@criticality', isa => Int, coerce => 1; You can use the type constraint Int defined in MooseX::Types. You only need to import the Int TC and define a coercion from Str to Int (all xpath-extracted values are extracted as strings). Though it might be smart to create a user-defined TC to avoid strings coercing to integers everywhere. So what you want should already be available. -- Robin