blib/lib/App/Netdisco/Web/Plugin/Device/Vlans.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 52 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::Web::Plugin::Device::Vlans;
2  
3 use strict;
4 use warnings;
5  
6 use Dancer ':syntax';
7 use Dancer::Plugin::Ajax;
8 use Dancer::Plugin::DBIC;
9 use Dancer::Plugin::Auth::Extensible;
10  
11 use App::Netdisco::Web::Plugin;
12  
13 register_device_tab({ tag => 'vlans', label => 'VLANs', provides_csv => 1 });
14  
15 get '/ajax/content/device/vlans' => require_login sub {
16 my $q = param('q');
17  
18 my $device = schema(vars->{'tenant'})->resultset('Device')
19 ->search_for_device($q) or send_error('Bad device', 400);
20 my @results = $device->vlans->search(
21 { vlan => { '>' => 0 } }, { order_by => 'vlan' } )->hri->all;
22  
23 return unless scalar @results;
24  
25 if (request->is_ajax) {
26 my $json = to_json( \@results );
27 template 'ajax/device/vlans.tt', { results => $json },
28 { layout => 'noop' };
29 }
30 else {
31 header( 'Content-Type' => 'text/comma-separated-values' );
32 template 'ajax/device/vlans_csv.tt', { results => \@results },
33 { layout => 'noop' };
34 }
35 };
36  
37 true;