Revision history for DBIx::Class
+
+ * New Features / Changes
+ - Allow schema cloning to mutate attributes.
+
+ * Fixes
- Fix issue where the query was becoming overly mangled when trying
to use pagination with a query that has a sub-select in the WHERE
clause.
=over 4
+=item Arguments: %attrs?
+
=item Return Value: $new_schema
=back
Clones the schema and its associated result_source objects and returns the
-copy.
+copy. The resulting copy will have the same attributes as the source schema,
+except for those attributes explicitly overriden by the provided C<%attrs>.
=cut
sub clone {
- my ($self) = @_;
- my $clone = { (ref $self ? %$self : ()) };
+ my $self = shift;
+
+ my $clone = {
+ (ref $self ? %$self : ()),
+ (@_ == 1 && ref $_[0] eq 'HASH' ? %{ $_[0] } : @_),
+ };
bless $clone, (ref $self || $self);
$clone->class_mappings({ %{$clone->class_mappings} });
no warnings qw/qw/;
+__PACKAGE__->mk_group_accessors(simple => 'custom_attr');
+
__PACKAGE__->load_classes(qw/
Artist
SequenceTest
my $schema = DBICTest->init_schema();
-my $clone = $schema->clone;
-cmp_ok ($clone->storage, 'eq', $schema->storage, 'Storage copied into new schema (not a new instance)');
+{
+ my $clone = $schema->clone;
+ cmp_ok ($clone->storage, 'eq', $schema->storage, 'Storage copied into new schema (not a new instance)');
+}
+
+{
+ is $schema->custom_attr, undef;
+ my $clone = $schema->clone(custom_attr => 'moo');
+ is $clone->custom_attr, 'moo', 'cloning can change existing attrs';
+}
+
+{
+ my $clone = $schema->clone({ custom_attr => 'moo' });
+ is $clone->custom_attr, 'moo', 'cloning can change existing attrs';
+}
+
done_testing;