The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

VM::EC2::Dispatch - Create Perl objects from AWS XML requests

SYNOPSIS

  use VM::EC2;

  VM::EC2::Dispatch->add_override('DescribeRegions'=>\&mysub);

  VM::EC2::Dispatch->add_override('DescribeTags'=>'My::Type');
  
  sub mysub {
      my ($parsed_xml_object,$ec2) = @_;
      my $payload = $parsed_xml_object->{regionInfo}
      return My::Type->new($payload,$ec2);
  }

DESCRIPTION

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 built-in request to object mapping with your own objects.

VM::EC2::Dispatch->add_override($request_name => \&sub) =head2 VM::EC2::Dispatch->add_override($request_name => 'Class::Name')

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, or a string containing a class name.

In the case of a code reference as the second argument, the subroutine you provide will be invoked with two arguments consisting of the parsed XML response and the VM::EC2 object.

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)

Your new() method should return one or more objects.

In either case, the parsed XML response will have been passed through XML::Simple with the options:

  $parser = XML::Simple->new(ForceArray    => ['item'],
                             KeyAttr       => ['key'],
                             SuppressEmpty => undef);
  $parsed = $parser->XMLin($raw_xml)

In general, this will give you a hash of hashes. Any tag named 'item' 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.

SEE ALSO

VM::EC2 VM::EC2::Object VM::EC2::Generic VM::EC2::BlockDevice VM::EC2::BlockDevice::Attachment VM::EC2::BlockDevice::Mapping VM::EC2::BlockDevice::Mapping::EBS VM::EC2::Error VM::EC2::Generic VM::EC2::Group VM::EC2::Image VM::EC2::Instance VM::EC2::Instance::ConsoleOutput VM::EC2::Instance::Set VM::EC2::Instance::State VM::EC2::Instance::State::Change VM::EC2::Instance::State::Reason VM::EC2::Region VM::EC2::ReservationSet VM::EC2::SecurityGroup VM::EC2::Snapshot VM::EC2::Tag VM::EC2::Volume

AUTHOR

Lincoln Stein <lincoln.stein@gmail.com>.

Copyright (c) 2011 Ontario Institute for Cancer Research

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.