]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/DB/ResultSet/Arch.pm
572ed0ae9df3ebe3d3559d3e427c8b36474aa3bf
[debbugs.git] / Debbugs / DB / ResultSet / Arch.pm
1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 # Copyright 2016 by Don Armstrong <don@donarmstrong.com>.
5 use utf8;
6 package Debbugs::DB::ResultSet::Arch;
7
8 =head1 NAME
9
10 Debbugs::DB::ResultSet::Arch - Architecture result set operations
11
12 =head1 SYNOPSIS
13
14
15
16 =head1 DESCRIPTION
17
18
19
20 =cut
21
22 use strict;
23 use warnings;
24
25 use base 'DBIx::Class::ResultSet';
26
27 # required for hash slices
28 use v5.20;
29
30 sub get_archs {
31     my ($self,@archs) = @_;
32     my %archs;
33     for my $a ($self->result_source->schema->resultset('Arch')->
34                search(undef,
35                      {result_class => 'DBIx::Class::ResultClass::HashRefInflator',
36                       columns => [qw[id arch]],
37                      })->all()) {
38         $archs{$a->{arch}} = $a->{id};
39     }
40     for my $a (grep {not exists $archs{$_}} @archs) {
41         $archs{$a} =
42             $self->result_source->schema->resultset('Arch')->
43             find_or_create({arch => $a},
44                           {columns => [qw[id arch]],
45                           }
46                           )->id;
47     }
48
49     return {%archs{@archs}};
50 }
51
52
53 1;
54
55 __END__