Rose-DB-Object

 view release on metacpan or  search on metacpan

lib/Rose/DB/Object/Metadata/MethodMaker.pm  view on Meta::CPAN

  return 0  if($type eq 'get');

  # $args is a reference to the method args *including* the invocant
  return @$args > 1 ? 1 : 0;
}

sub build_method_name_for_type { Carp::confess "Override in subclass" }

sub defined_method_types
{
  my($self) = shift;

  my @types = sort keys %{$self->{'method_name'} ||= {}};
  return wantarray ? @types : \@types;
}

sub method_maker_arguments
{
  my($self, $type) = @_;

  my $class = ref $self;

  Carp::confess "Missing required type argument"  unless(defined $type);

  my %opts = map { $_ => scalar $self->$_() } grep { defined scalar $self->$_() }
     $class->method_maker_argument_names($type);

  # This is done by method_maker_argument_names() above
  #$class->init_method_maker_info;

  my $mm_info = $Method_Maker_Info{$class}{$type} ||= {};

  $opts{'interface'} = $mm_info->{'interface'}  if(exists $mm_info->{'interface'});

  return wantarray ? %opts : \%opts;
}

sub make_methods
{
  my($self, %args) = @_;

  my $options = $args{'options'} || {};

  if(exists $args{'preserve_existing'})
  {
    $options->{'preserve_existing'} = $args{'preserve_existing'};
  }

  if(exists $args{'replace_existing'})
  {
    if($options->{'preserve_existing'})
    {
      Carp::croak "Cannot specify true values for both the ",
                  "'replace_existing' and 'preserve_existing' ",
                  "options";
    }

    $options->{'override_existing'} = $args{'replace_existing'};
  }

  $options->{'target_class'} ||= $args{'target_class'} || (caller)[0];

  my $types = $args{'types'} || [ $self->auto_method_types ];

  foreach my $type (@$types)
  {
    my $method_maker_class = $self->method_maker_class($type)
      or Carp::croak "No method maker class defined for method type '$type'";

    my $method_maker_type = $self->method_maker_type($type)
      or Carp::croak "No method maker type defined for method type '$type'";

    my $method_name = $self->method_name($type)
      or Carp::croak "No method name defined for method type '$type'";

    if(Rose::DB::Object->can($method_name))
    {
      Carp::croak "Cannot create method '$method_name' in class ",
        "$options->{'target_class'} - Rose::DB::Object defines a ",
        "method with the same name";
    }

    $method_maker_class->make_methods(
      $options,
      $method_maker_type => 
      [
        $method_name => { $self->method_maker_arguments($type) }
      ]);

    $self->made_method_type($type => $method_name);

    if($self->can('method_code'))
    {
      $self->method_code($type => undef);
    }
  }

  return;
}

sub made_method_type { }
sub made_method_types { }

1;



( run in 1.630 second using v1.01-cache-2.11-cpan-140bd7fdf52 )