Simplify guarded pass-through added to CDBI in ee333775
[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 use namespace::clean;
11
12 =head1 NAME
13
14 DBIx::Class::CDBICompat::Copy - Emulates Class::DBI->copy($new_id)
15
16 =head1 SYNOPSIS
17
18 See DBIx::Class::CDBICompat for usage directions.
19
20 =head1 DESCRIPTION
21
22 Emulates C<<Class::DBI->copy($new_id)>>.
23
24 =cut
25
26
27 # CDBI's copy will take an id in addition to a hash ref.
28 sub copy {
29     my($self, $arg) = @_;
30     return $self->next::method($arg) if ref $arg;
31
32     my @primary_columns = $self->primary_columns;
33     croak("Need hash-ref to edit copied column values")
34         if @primary_columns > 1;
35
36     return $self->next::method({ $primary_columns[0] => $arg });
37 }
38
39 =head1 FURTHER QUESTIONS?
40
41 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
42
43 =head1 COPYRIGHT AND LICENSE
44
45 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
46 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
47 redistribute it and/or modify it under the same terms as the
48 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
49
50 =cut
51
52 1;