From d6523fe5432e3a7bc91b5e0dc57e3e57a451d97a Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 5 Aug 2017 22:01:49 +0100 Subject: [PATCH] $job->device is always a DBIC row --- lib/App/Netdisco/Backend/Job.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/App/Netdisco/Backend/Job.pm b/lib/App/Netdisco/Backend/Job.pm index b4c27ccc..9b09fa2e 100644 --- a/lib/App/Netdisco/Backend/Job.pm +++ b/lib/App/Netdisco/Backend/Job.pm @@ -1,5 +1,7 @@ package App::Netdisco::Backend::Job; +use App::Netdisco::Util::Device 'get_device'; + use Moo; use namespace::clean; @@ -24,6 +26,18 @@ foreach my $slot (qw/ ); } +# $job->device is always a DBIC row +around BUILDARGS => sub { + my ( $orig, $class, @args ) = @_; + my $params = $args[0] or return $class->$orig(@args); + + if ((ref {} eq ref $params) and ref $params->{device}) { + $params->{device} = get_device( $params->{device} ); + } + + return $class->$orig(@args); +}; + =head1 METHODS =head2 summary