DBIO

 view release on metacpan or  search on metacpan

lib/DBIO/Candy.pm  view on Meta::CPAN

      $i->indices(@_);
    }
  }
}

sub gen_rename_proxy {
  my ($self, $inheritor, $set_table, %aliases) = @_;
  sub {
    my ($class, $name) = @_;
    my $meth = $aliases{$name};
    my $i = $inheritor;
    sub { $set_table->(); $i->$meth(@_) }
  }
}

sub gen_proxy {
  my ($self, $inheritor, $set_table) = @_;
  sub {
    my ($class, $name) = @_;
    my $i = $inheritor;
    sub { $set_table->(); $i->$name(@_) }
  }
}

sub installer {
  my ($self) = @_;
  sub {
    Sub::Exporter::default_installer @_;
    my %subs = @{ $_[1] };
    namespace::clean->import( -cleanee => $_[0]{into}, keys %subs )
  }
}

sub set_base {
   my ($self, $inheritor, $base) = @_;

   # inlined from parent.pm
   for ( my @useless = $self->base($base) ) {
      s{::|'}{/}g;
      require "$_.pm"; # dies if the file is not found
   }

   {
      no strict 'refs';
      # Idempotent: skip if already in @ISA (needed for Loader reload)
      my @base = $self->base($base);
      my %seen = map { $_ => 1 } @{"$inheritor\::ISA"};
      my @new = grep { !$seen{$_} } @base;
      @{"$inheritor\::ISA"} = (@{"$inheritor\::ISA"}, @new) if @new;
   }
}

sub gen_INIT {
  my ($self, $perl_version, $custom_aliases, $custom_methods, $inheritor, $experimental) = @_;
  sub {
    my $orig = $_[1]->{import_args};
    $_[1]->{import_args} = [];
    %$custom_aliases = ();
    @$custom_methods = ();

    strict->import;
    warnings->import;

    if ($perl_version) {
       require feature;
       feature->import(":5.$perl_version")
    }

    if ($experimental) {
       require experimental;
       die 'experimental arg must be an arrayref!'
          unless ref $experimental && ref $experimental eq 'ARRAY';
       # to avoid experimental referring to the method
       experimental::->import(@$experimental)
    }

    mro::set_mro($inheritor, 'c3');

    1;
  }
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

DBIO::Candy - Sugar syntax for defining DBIO result classes

=head1 VERSION

version 0.900002

=head1 SYNOPSIS

 package MyApp::Schema::Result::Artist;
 use DBIO::Candy;

 table 'artists';

 primary_column id => {
     data_type => 'integer',
     is_auto_increment => 1,
 };

 column name => {
     data_type => 'varchar',
     size => 100,
 };

 column bio => {
     data_type => 'text',
     is_nullable => 1,
 };

 column created_at => {



( run in 0.461 second using v1.01-cache-2.11-cpan-941387dca55 )