Remove Class::Data::Inheritable and use CAG 'inherited' style accessors
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / Copy.pm
1 package # hide from PAUSE
2     DBIx::Class::CDBICompat::Copy;
3
4 use strict;
5 use warnings;
6
7 use base 'DBIx::Class';
8
9 use Carp;
10
11 =head1 NAME
12
13 DBIx::Class::CDBICompat::Copy - Emulates Class::DBI->copy($new_id)
14
15 =head1 SYNOPSIS
16
17 See DBIx::Class::CDBICompat for usage directions.
18
19 =head1 DESCRIPTION
20
21 Emulates C<<Class::DBI->copy($new_id)>>.
22
23 =cut
24
25
26 # CDBI's copy will take an id in addition to a hash ref.
27 sub copy {
28     my($self, $arg) = @_;
29     return $self->next::method($arg) if ref $arg;
30
31     my @primary_columns = $self->primary_columns;
32     croak("Need hash-ref to edit copied column values")
33         if @primary_columns > 1;
34
35     return $self->next::method({ $primary_columns[0] => $arg });
36 }
37
38 =head1 FURTHER QUESTIONS?
39
40 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
41
42 =head1 COPYRIGHT AND LICENSE
43
44 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
45 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
46 redistribute it and/or modify it under the same terms as the
47 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
48
49 =cut
50
51 1;