#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;
use Getopt::Long;
use Pod::Usage;
use Perl6::Say;
use Net::Amazon::EC2::Metadata;
my $DEBUGGING;
my $help;
GetOptions("v" => \$DEBUGGING, "h|help" => \$help, );
pod2usage(-verbose => 1)  if ($help);
if ( $ARGV[0]  )  {
    no strict 'refs';
    no warnings 'uninitialized';
    if ($DEBUGGING)      {
        say "$ARGV[0]: ". eval("Net::Amazon::EC2::Metadata->$ARGV[0]") ;    
    }else      {
        say  eval("Net::Amazon::EC2::Metadata->$ARGV[0]") ;         
    }

}else  {
    no warnings 'uninitialized';
    my $data = Net::Amazon::EC2::Metadata->all_data;
    for (sort keys %$data)      {
        say "$_: $data->{$_}";
    }
}



exit;



__END__

=head1 NAME

ec2meta   - get the metadata for this particular ec2 instance

=head1 SYNOPSIS

ec2meta  -h --help  [type]

=head1 ARGUMENTS

With a TYPE reports just that TYPE of meta data.  With out one reports on all meta data available. (except the keys, which are listed by name, not value)

The -h flag displays this help message.

types:

 ami_id             The AMI ID used to launch the instance. 1.0
 ami_manifest_path  The manifest path of the AMI with which the instance was launched.  1.0
 ami_launch_index   The index of this instance in the reservation (per AMI).    1.0
 ancestor_ami_ids   The AMI IDs of any instances that were rebundled to create this AMI.    2007_10_10
 instance_id        The ID of this instance.    1.0
 instance_type      The type of instance to launch. For more information, see Selecting Instance Types. 2007_08_29
 local_hostname     The local hostname of the instance. 2007_01_19
 public_hostname    The public hostname of the instance.    2007_01_19
 local_ipv4         Public IP address if launched with direct addressing; private IP address if launched with public addressing.    1.0
 public_ipv4        NATted public IP Address    2007_01_19
 public_keys/       Public keys. Only available if supplied at instance launch time 1.0
 reservation_id     ID of the reservation.  1.0
 security_groups    Names of the security groups the instance is launched in. Only available if supplied at instance launch time    1.0
 product_codes      Product codes associated with this instance.    2007_03_01
 user_data          User supplied data at instance launch





=cut