Subject: | Inserting data in original order |
Date: | Wed, 28 Oct 2015 12:11:19 +0000 |
To: | bug-DBIx-Class-Fixtures [...] rt.cpan.org |
From: | Andrew Beverley <andy [...] andybev.com> |
Hi,
Would it be possible to have Fixtures populate data in the original
order please? Currently the fixtures are read from the relevant
directory, but in an apparent random order.
The following patch works as a proof of concept (it's not possible to
use IO:All's all() method, as that returns the files sorted
alphanumerically, not numerically):
--- a/Fixtures-old.pm
+++ b/Fixtures-new.pm
@@ -1361,8 +1361,10 @@ sub populate {
my $rs = $schema->resultset($source);
my $source_dir = io->catdir($tmp_fixture_dir, $self->_name_for_source($rs->result_source));
next unless (-e "$source_dir");
+ # Disable numeric warnings?
+ my @all = sort { int($a->filename) <=> int($b->filename) } $source_dir->all;
my @rows;
- while (my $file = $source_dir->next) {
+ foreach my $file (@all)
+ {
next unless ($file =~ /\.fix$/);
next if $file->is_dir;
my $contents = $file->slurp;
Thanks,
Andy