<commit_before>package EnsEMBL::ORM::Rose::ExternalRelationship;

### Name: EnsEMBL::ORM::Rose::ExternalRelationship
### A class for defining relationship of rose object to another rose object while the corrosponding db tables being on different hosts
### The class contains some essential methods as in Rose::DB::Object::Metadata::Relationship
### ExternalRelationship DOES NOT allow many to many relationship

use strict;

use EnsEMBL::Web::Exceptions;

use base qw(EnsEMBL::Web::Root);

sub new {
  ## @constructor
  ## @param Hashref with keys:
  ##  - name        Relationship name
  ##  - type        Type of relationship - 'one to one' etc
  ##  - column_map  Hashref {internal_column => external_column} defining the link between relationship
  ##  - class       Class name of the object mapped
  ## @exception ORMException::ObjectClassMissingException if the class for the related object is not found
  my ($class, $params) = @_;

  $class->dynamic_use($params->{'class'}) or
  throw exception('ORMException::ObjectClassMissingException', sprintf("External relationship mapping class '%s' could not be found.", $params->{'class'}));

  return bless $params, $class;
}

sub class       { return shift->{'class'};                      }
sub name        { return shift->{'name'};                       }
sub type        { return shift->{'type'};                       }
sub column_map  { return shift->{'column_map'};                 }
sub is_singular { return shift->type =~ /to one$/ ? 1 : undef;  }

sub make_methods {
  ## Creates the method to access/modify the value of the related rose object
  ## @param Hash with key target_class - rose object class name
  my ($self, %params) = @_;
  my $object_class = $params{'target_class'};
  my $method_name  = $self->name;

  no strict qw(refs);
  *{"${object_class}::${method_name}"} = sub {
    return shift->external_relationship_value($self, @_);
  };
}

1;<commit_msg>make use of MethodMaker's add_method instead of creating methods manually<commit_after>package EnsEMBL::ORM::Rose::ExternalRelationship;

### Name: EnsEMBL::ORM::Rose::ExternalRelationship
### A class for defining relationship of rose object to another rose object while the corrosponding db tables being on different hosts
### The class contains some essential methods as in Rose::DB::Object::Metadata::Relationship
### ExternalRelationship DOES NOT allow many to many relationship

use strict;

use EnsEMBL::Web::Exceptions;
use EnsEMBL::Web::Tools::MethodMaker qw(add_method);

use base qw(EnsEMBL::Web::Root);

sub new {
  ## @constructor
  ## @param Hashref with keys:
  ##  - name        Relationship name
  ##  - type        Type of relationship - 'one to one' etc
  ##  - column_map  Hashref {internal_column => external_column} defining the link between relationship
  ##  - class       Class name of the object mapped
  ## @exception ORMException::ObjectClassMissingException if the class for the related object is not found
  my ($class, $params) = @_;

  $class->dynamic_use($params->{'class'}) or
  throw exception('ORMException::ObjectClassMissingException', sprintf("External relationship mapping class '%s' could not be found.", $params->{'class'}));

  return bless $params, $class;
}

sub class       { return shift->{'class'};                      }
sub name        { return shift->{'name'};                       }
sub type        { return shift->{'type'};                       }
sub column_map  { return shift->{'column_map'};                 }
sub is_singular { return shift->type =~ /to one$/ ? 1 : undef;  }

sub make_methods {
  ## Creates the method to access/modify the value of the related rose object
  ## @param Hash with key target_class - rose object class name
  my ($self, %params) = @_;

  add_method($params{'target_class'}, $self->name, sub {
    return shift->external_relationship_value($self, @_);
  });
}

1;
{'fraction_non_alphanumeric': 0.12093862815884476, 'fraction_numerical': 0.0010314595152140279, 'mean_word_length': 3.5581668625146885, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4327784', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1058, 'n_words': 363}