From f7df6b907bf6b36627d542a1d6c2677ab496ca65 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 23 Apr 2018 08:12:57 +0100 Subject: [PATCH] copy munge_highspeed from SNMP::Info to avoid having dependency from web frontend --- .../Netdisco/Web/Plugin/Device/Neighbors.pm | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm index c97a4f93..485372d6 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm @@ -5,7 +5,6 @@ use Dancer::Plugin::Ajax; use Dancer::Plugin::DBIC; use Dancer::Plugin::Auth::Extensible; -use SNMP::Info (); use List::Util 'first'; use List::MoreUtils (); use App::Netdisco::Util::Permission 'check_acl_only'; @@ -77,9 +76,33 @@ ajax '/ajax/data/device/netmappositions' => require_login sub { } }; +# copied from SNMP::Info to avoid introducing dependency to web frontend +sub munge_highspeed { + my $speed = shift; + my $fmt = "%d Mbps"; + + if ( $speed > 9999999 ) { + $fmt = "%d Tbps"; + $speed /= 1000000; + } + elsif ( $speed > 999999 ) { + $fmt = "%.1f Tbps"; + $speed /= 1000000.0; + } + elsif ( $speed > 9999 ) { + $fmt = "%d Gbps"; + $speed /= 1000; + } + elsif ( $speed > 999 ) { + $fmt = "%.1f Gbps"; + $speed /= 1000.0; + } + return sprintf( $fmt, $speed ); +} + sub to_speed { my $speed = shift or return ''; - ($speed = SNMP::Info::munge_highspeed($speed / 1_000_000)) =~ s/(?:\.0 |bps$)//g; + ($speed = munge_highspeed($speed / 1_000_000)) =~ s/(?:\.0 |bps$)//g; return $speed; }