This class handles turning the XML response to AWS requests into perl objects. Only one method is likely to be useful to developers, the add_override() class method. This allows you to replace the handlers used to map the response onto objects.

Before invoking a VM::EC2 request you wish to customize, call the add_override() method with two arguments. The first argument is the name of the request you wish to customize, such as "DescribeVolumes". The second argument is either a code reference, a VM::EC2::Dispatch method name and arguments (separated by commas), or a class name.

In the case of a code reference as the second argument, the subroutine you provide will be invoked with four arguments consisting of the parsed XML response, the VM::EC2 object, the XML namespace string from the request, and the Amazon-assigned request ID. In practice, only the first two arguments are useful.

In the case of a string containing a classname, the class will be loaded if it needs to be, and then its new() method invoked as follows:

Your::Class->new($parsed_xml,$ec2,$xmlns,$requestid)

Your new() method should return one or more objects. It is suggested that you subclass VM::EC2::Generic and use the inherited new() method to store the parsed XML and EC2 object. See the code for VM::EC2::AvailabilityRegion for a simple template.

If the second argument is neither a code reference nor a classname, it will be treated as a VM::EC2::Dispatch method name and its arguments, separated by commas. The method will be invoked as follows:

$dispatch->$method_name($raw_xml,$ec2,$arg1,$arg2,$arg3,...)

There are two methods currently defined for this purpose, boolean(), and fetch_items(), which handle the preprocessing of several common XML representations of EC2 data. Note that in this form, the RAW XML is passed in, not the parsed data structure.

The parsed XML response is generated by the XML::Simple module using these options:

In general, this will give you a hash of hashes. Any tag named 'item' or 'member' will be forced to point to an array reference, and any tag named "key" will be flattened as described in the XML::Simple documentation.

A simple way to examine the raw parsed XML is to invoke any VM::EC2::Object's as_string method:

my ($i) = $ec2->describe_instances;
print $i->as_string;

This will give you a Data::Dumper representation of the XML after it has been parsed.

Look at the data structure "ObjectRegistration" in the source code for this module to see many examples of response to object mapping.

The following methods perform simple pre-processing of the parsed XML (a hash of hashes) before passing the modified data structure to the designated object class. They are used as the second argument to add_override()

It looks inside the Result structure for the tag named $tag and returns the list wrapped in member elements. In this case the tag is 'AvailabilityZones' and the return value would be: ( 'us-west-2a', 'us-west-2b' )

If $embedded_tag is passed, then it is used for XML responses such as this, where the member list has an embedded tag:

It looks inside the Result structure for the tag named $tag and returns the list wrapped in a member element plus the embedded tag. In this case the tag is 'Instances', the embedded tag is 'InstanceId' and the return value would be: ( 'i-12345678', 'i-90abcdef' )

It looks inside the structure for the tag named $container_tag, pulls out the items that are stored under <item> and then passes the parsed contents to $object_class->new(). The optional $nokey argument is used to suppress XML::Simple's default flattening behavior turning tags named "key" into hash keys.

This is used for requests that have a -max_results argument. In this case, the response will have a nextToken field, which can be used to fetch the "next page" of results.

The $token_name is some unique identifying token. It will be turned into two temporary EC2 instance variables, one named "${token_name}_token", which contains the nextToken value, and the other "${token_name}_stop", which flags the caller that no more results will be forthcoming.

This must all be coordinated with the request subroutine. See how describe_instance_status() and describe_spot_price_history() do it.

This package and its accompanying libraries is free software; you can redistribute it and/or modify it under the terms of the GPL (either version 1, or at your option, any later version) or the Artistic License 2.0. Refer to LICENSE for the full license text. In addition, please see DISCLAIMER.txt for disclaimers of warranty.