<commit_before>use MooseX::Declare;
use Moose::Util::TypeConstraints;

role AWS::API::Attribute::Trait::Unwrapped {
  use Moose::Util;
  Moose::Util::meta_attribute_alias('Unwrapped');
  has xmlname => (is => 'ro', isa => 'Str');
}

class AWS::Common::Tag with AWS::API::ResultParser {
  has Key => (is => 'ro', isa => 'Str', required => 1);
  has Value => (is => 'ro', isa => 'Str', required => 1);
}

class AWS::API::Integer {
  has Value => (isa => 'Int', is => 'ro', required => 1);
  method to_params (Str $param_name) { ($param_name => $self->Value) }
}

coerce 'AWS::API::Integer', from 'Int', via { AWS::API::Integer->new(Value => $_) };

class AWS::API::String {
  has Value => (isa => 'Str', is => 'rw', required => 1);
  method to_params (Str $param_name) { ($param_name => $self->Value) }
}

coerce 'AWS::API::String', from 'Str', via { AWS::API::String->new(Value => $_) };

class AWS::API::Boolean {
  has Value => (isa => 'Bool', is => 'rw', required => 1);
  #where { $_ eq 'true' or $_ eq 'false' };
  method to_params (Str $param_name) { ( $param_name => ($self->Value?'true':'false') ) }
}

coerce 'AWS::API::Boolean', from 'Str', via { 
  my $val = $_;
  $val = 1 if ($val eq 'true');
  $val = 0 if ($val eq 'false');
  AWS::API::Boolean->new(Value => $_) 
};

class AWS::API::StringList {
  has Value => (isa => 'ArrayRef[Str]', is => 'rw', required => 1);

  method to_params (Str $param_name) {
    my $i = 1;
    my %params;
    foreach my $value (@{ $self->Value }){
      $params{ sprintf("%s.member.%d", $param_name, $i) } = $value;
      $i++
    }
    return %params
  }
}

coerce 'AWS::API::StringList',
  from 'ArrayRef',
   via { AWS::API::StringList->new( Value => $_ ) };

role AWS::API::RegionalEndpointCaller {
  has region => (is => 'rw', isa => 'Str');
  requires 'service';

  method endpoint_host {
    return sprintf '%s.%s.amazonaws.com', $self->service, $self->region;
  }

  method _api_endpoint {
    return sprintf '%s://%s/', 'https', $self->endpoint_host;
  }
}

role AWS::API::SingleEndpointCaller {
  requires 'service';

  method region {
    # http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html
    # For services that use a globally unique endpoint, such as IAM, use us-east-1
    return 'us-east-1';
  }

  method endpoint_host {
    return sprintf '%s.amazonaws.com', $self->service;
  }

  method _api_endpoint {
    return sprintf '%s://%s/', 'https', $self->endpoint_host;
  }
}

role AWS::API::MapParser {
  sub from_result {
    my ($class, $result) = @_;
    $class->new(map { ($_->{ key } => $_->{ value }) } @$result);
  }

  sub result_to_args {
    die "Should this be deprecated??\n";
    my ($class, $result) = @_;
    $class->new(map { ($_->{ key } => $_->{ value }) } @$result);
  }
}

role AWS::API::StrToStrMapParser {
  sub from_result {
    my ($class, $result) = @_;
    $class->new(Map => { %$result });  
  }

  sub result_to_args {
    die "Should this be deprecated??\n";
    my ($class, $result) = @_;
    $class->new(Map => { %$result });
  }
}

role AWS::API::ToParams {
  sub _to_params {
    my ($self) = @_;
    my $params = {};
    foreach my $att ($self->meta->get_attribute_list) {
      $params->{$att} = $self->$att();
    }
    return $params;
  }
}

role AWS::API::UnwrappedParser {
  sub result_to_args {
    my ($class, $result) = @_;
    my %args;

    foreach my $att ($class->meta->get_attribute_list) {
      next if (not my $meta = $class->meta->get_attribute($att));
      my $key = $meta->xmlname;

      #use Data::Dumper;
      #print STDERR "ATTRIBUTE: $att RESULTKEY: $key: ", $meta->type_constraint, " result: ", Dumper($result->{$key});
      my $att_type = $meta->type_constraint;

      my $value = $result->{ $key };
      my $value_ref = ref($value);
      if ($value_ref eq 'HASH') {
        if (exists $value->{ item }) {
          $value = $value->{ item };
        } elsif (exists $value->{ entry }) {
          $value = $value->{ entry  };
        }
      }
      $value_ref = ref($value);

      #print STDERR "GOING TO DO AN $att_type\n";
      #print STDERR "VALUE: " . Dumper($value);
      #print STDERR "REF de \$value" . ref($value) . "\n";

      # We'll consider that an attribute without brackets [] isn't an array type
      if ($att_type !~ m/\[.*\]$/) {
        if ($att_type =~ m/\:\:/) {
          if (defined $value) {
            if (not $value_ref) {
              $args{ $att } = $value;
            } else {
              #my $class = ("$att_type" eq 'Moose::Meta::TypeConstraint::Class') ? $att_type->class : $att_type;
              my $class = $att_type->class;
              $args{ $att } = $class->from_result( $value );
            }
          }
        } else {
          $args{ $att } = $value if (defined $value);
        }
      } elsif (my ($type) = ($att_type =~ m/^ArrayRef\[(.*)\]$/)) {
        if ($type =~ m/\:\:/) {
          if (not defined $value) {
            $args{ $att } = [ ];
          } elsif ($value_ref eq 'ARRAY') {
            $args{ $att } = [ map { $type->from_result( $_ ) } @$value ] ;
          } elsif ($value_ref eq 'HASH') {
            $args{ $att } = [ $type->from_result( $value ) ];
          }
        } else {
          if (defined $value){
            if ($value_ref eq 'ARRAY') {
              $args{ $att } = $value; 
            } else {
              $args{ $att } = [ $value ];
            }
          }
        }
      }
    }

    return %args;
  }

  sub from_result {
    my ($class, $result) = @_;
    my %args = $class->result_to_args($result, $class);
    return $class->new(%args);
  }
}

role AWS::API::ResultParser {
  sub result_to_args {
    my ($class, $result) = @_;
    my %args;

    foreach my $key ($class->meta->get_attribute_list) {
      next if (not my $meta = $class->meta->get_attribute($key));

      #use Data::Dumper;
      #print STDERR "ATTRIBUTE: $key: ", $meta->type_constraint, " result: ", Dumper($result->{$key});
      my $att_type = $meta->type_constraint;

      my $value = $result->{ $key };
      my $value_ref = ref($value);
      if ($value_ref eq 'HASH') {
        if (exists $value->{ member }) {
          $value = $value->{ member };
        } elsif (exists $value->{ entry }) {
          $value = $value->{ entry  };
        }
      }
      $value_ref = ref($value);

      #print STDERR "GOING TO DO AN $att_type\n";
      #print STDERR "VALUE: " . Dumper($value);
      #print STDERR "REF de \$value" . ref($value) . "\n";

      # We'll consider that an attribute without brackets [] isn't an array type
      if ($att_type !~ m/\[.*\]$/) {
        if ($att_type =~ m/\:\:/) {
          if (defined $value) {
            if (not $value_ref) {
              $args{ $key } = $value;
            } else {
              #my $class = ("$att_type" eq 'Moose::Meta::TypeConstraint::Class') ? $att_type->class : $att_type;
              my $class = $att_type->class;
              $args{ $key } = $class->from_result( $value );
            }
          }
        } else {
          $args{ $key } = $result->{ $key } if (defined $result->{ $key });
        }
      } elsif (my ($type) = ($att_type =~ m/^ArrayRef\[(.*)\]$/)) {
        if ($type =~ m/\:\:/) {
          if (not defined $value) {
            $args{ $key } = [ ];
          } elsif ($value_ref eq 'ARRAY') {
            $args{ $key } = [ map { $type->from_result( $_ ) } @$value ] ;
          } elsif ($value_ref eq 'HASH') {
            $args{ $key } = [ $type->from_result( $value ) ];
          }
        } else {
          if (defined $value){
            if ($value_ref eq 'ARRAY') {
              $args{ $key } = $value; 
            } else {
              $args{ $key } = [ $value ];
            }
          }
        }
      }
    }
    return %args;
  }

  sub from_result {
    my ($class, $result) = @_;
    my %args = $class->result_to_args($result, $class);
    return $class->new(%args);
  }
}


<commit_msg>Delete unused classes in AWS::API. Have gone unused for some time now<commit_after>use MooseX::Declare;
use Moose::Util::TypeConstraints;

role AWS::API::Attribute::Trait::Unwrapped {
  use Moose::Util;
  Moose::Util::meta_attribute_alias('Unwrapped');
  has xmlname => (is => 'ro', isa => 'Str');
}

class AWS::Common::Tag with AWS::API::ResultParser {
  has Key => (is => 'ro', isa => 'Str', required => 1);
  has Value => (is => 'ro', isa => 'Str', required => 1);
}

role AWS::API::RegionalEndpointCaller {
  has region => (is => 'rw', isa => 'Str');
  requires 'service';

  method endpoint_host {
    return sprintf '%s.%s.amazonaws.com', $self->service, $self->region;
  }

  method _api_endpoint {
    return sprintf '%s://%s/', 'https', $self->endpoint_host;
  }
}

role AWS::API::SingleEndpointCaller {
  requires 'service';

  method region {
    # http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html
    # For services that use a globally unique endpoint, such as IAM, use us-east-1
    return 'us-east-1';
  }

  method endpoint_host {
    return sprintf '%s.amazonaws.com', $self->service;
  }

  method _api_endpoint {
    return sprintf '%s://%s/', 'https', $self->endpoint_host;
  }
}

role AWS::API::MapParser {
  sub from_result {
    my ($class, $result) = @_;
    $class->new(map { ($_->{ key } => $_->{ value }) } @$result);
  }

  sub result_to_args {
    die "Should this be deprecated??\n";
    my ($class, $result) = @_;
    $class->new(map { ($_->{ key } => $_->{ value }) } @$result);
  }
}

role AWS::API::StrToStrMapParser {
  sub from_result {
    my ($class, $result) = @_;
    $class->new(Map => { %$result });  
  }

  sub result_to_args {
    die "Should this be deprecated??\n";
    my ($class, $result) = @_;
    $class->new(Map => { %$result });
  }
}

role AWS::API::ToParams {
  sub _to_params {
    my ($self) = @_;
    my $params = {};
    foreach my $att ($self->meta->get_attribute_list) {
      $params->{$att} = $self->$att();
    }
    return $params;
  }
}

role AWS::API::UnwrappedParser {
  sub result_to_args {
    my ($class, $result) = @_;
    my %args;

    foreach my $att ($class->meta->get_attribute_list) {
      next if (not my $meta = $class->meta->get_attribute($att));
      my $key = $meta->xmlname;

      #use Data::Dumper;
      #print STDERR "ATTRIBUTE: $att RESULTKEY: $key: ", $meta->type_constraint, " result: ", Dumper($result->{$key});
      my $att_type = $meta->type_constraint;

      my $value = $result->{ $key };
      my $value_ref = ref($value);
      if ($value_ref eq 'HASH') {
        if (exists $value->{ item }) {
          $value = $value->{ item };
        } elsif (exists $value->{ entry }) {
          $value = $value->{ entry  };
        }
      }
      $value_ref = ref($value);

      #print STDERR "GOING TO DO AN $att_type\n";
      #print STDERR "VALUE: " . Dumper($value);
      #print STDERR "REF de \$value" . ref($value) . "\n";

      # We'll consider that an attribute without brackets [] isn't an array type
      if ($att_type !~ m/\[.*\]$/) {
        if ($att_type =~ m/\:\:/) {
          if (defined $value) {
            if (not $value_ref) {
              $args{ $att } = $value;
            } else {
              #my $class = ("$att_type" eq 'Moose::Meta::TypeConstraint::Class') ? $att_type->class : $att_type;
              my $class = $att_type->class;
              $args{ $att } = $class->from_result( $value );
            }
          }
        } else {
          $args{ $att } = $value if (defined $value);
        }
      } elsif (my ($type) = ($att_type =~ m/^ArrayRef\[(.*)\]$/)) {
        if ($type =~ m/\:\:/) {
          if (not defined $value) {
            $args{ $att } = [ ];
          } elsif ($value_ref eq 'ARRAY') {
            $args{ $att } = [ map { $type->from_result( $_ ) } @$value ] ;
          } elsif ($value_ref eq 'HASH') {
            $args{ $att } = [ $type->from_result( $value ) ];
          }
        } else {
          if (defined $value){
            if ($value_ref eq 'ARRAY') {
              $args{ $att } = $value; 
            } else {
              $args{ $att } = [ $value ];
            }
          }
        }
      }
    }

    return %args;
  }

  sub from_result {
    my ($class, $result) = @_;
    my %args = $class->result_to_args($result, $class);
    return $class->new(%args);
  }
}

role AWS::API::ResultParser {
  sub result_to_args {
    my ($class, $result) = @_;
    my %args;

    foreach my $key ($class->meta->get_attribute_list) {
      next if (not my $meta = $class->meta->get_attribute($key));

      #use Data::Dumper;
      #print STDERR "ATTRIBUTE: $key: ", $meta->type_constraint, " result: ", Dumper($result->{$key});
      my $att_type = $meta->type_constraint;

      my $value = $result->{ $key };
      my $value_ref = ref($value);
      if ($value_ref eq 'HASH') {
        if (exists $value->{ member }) {
          $value = $value->{ member };
        } elsif (exists $value->{ entry }) {
          $value = $value->{ entry  };
        }
      }
      $value_ref = ref($value);

      #print STDERR "GOING TO DO AN $att_type\n";
      #print STDERR "VALUE: " . Dumper($value);
      #print STDERR "REF de \$value" . ref($value) . "\n";

      # We'll consider that an attribute without brackets [] isn't an array type
      if ($att_type !~ m/\[.*\]$/) {
        if ($att_type =~ m/\:\:/) {
          if (defined $value) {
            if (not $value_ref) {
              $args{ $key } = $value;
            } else {
              #my $class = ("$att_type" eq 'Moose::Meta::TypeConstraint::Class') ? $att_type->class : $att_type;
              my $class = $att_type->class;
              $args{ $key } = $class->from_result( $value );
            }
          }
        } else {
          $args{ $key } = $result->{ $key } if (defined $result->{ $key });
        }
      } elsif (my ($type) = ($att_type =~ m/^ArrayRef\[(.*)\]$/)) {
        if ($type =~ m/\:\:/) {
          if (not defined $value) {
            $args{ $key } = [ ];
          } elsif ($value_ref eq 'ARRAY') {
            $args{ $key } = [ map { $type->from_result( $_ ) } @$value ] ;
          } elsif ($value_ref eq 'HASH') {
            $args{ $key } = [ $type->from_result( $value ) ];
          }
        } else {
          if (defined $value){
            if ($value_ref eq 'ARRAY') {
              $args{ $key } = $value; 
            } else {
              $args{ $key } = [ $value ];
            }
          }
        }
      }
    }
    return %args;
  }

  sub from_result {
    my ($class, $result) = @_;
    my %args = $class->result_to_args($result, $class);
    return $class->new(%args);
  }
}



{'fraction_non_alphanumeric': 0.19604488846311754, 'fraction_numerical': 0.001163268099083071, 'mean_word_length': 2.1382864505046166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 186, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1918470', 'n_tokens_mistral': 5094, 'n_tokens_neox': 5025, 'n_words': 1193}