Insight.pm

filter: Statementstmt 87.3% 55 / 63 Branchbran 57.1% 8 / 14 Conditioncond 30.0% 3 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 74.2% 78 / 105 CC 14 SCAR 21.2
CC
14
Cov
76%
open
17.3
_load_device_role
3.1
_load_class
3.0
CRAP 8.3
« Insight/Device/Cisco/Catalyst.pm ↑ Summary Insight/MIB/QBridge.pm »
1 package SNMP::Insight;
2  
3 # ABSTRACT: SNMP Moose interface
4  
5 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.002'; # TRIAL VERSION:
10  
11 2 ▶use Module::Runtime 0.014 'use_package_optimistically';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Moose::Util 'is_role';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use SNMP::Insight::Device;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use SNMP::Insight::Utils qw(_debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶sub open {
Subroutine open: called CC=10 SCAR=28.5
Pod documented
20 1 my %args = @_;
21  
22 1 my $session = $args{session};
23 1 ▶ if ( !defined($session) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $session) 0 1 1
24 my $session_class
25 0 ▶ = $args{session_class} || 'SNMP::Insight::Session::NetSNMP';
Condition0%0/2
$args{'session_class'} || 'SNMP::Insight::Session::NetSNMP'
l!l
00
MC/DC0%0/1
$args{'session_class'} || 'SNMP::Insight::Session::NetSNMP'
$args{'session_class'}
Truth table0%0/2
A
A= $args{'session_class'}
Aresult
11
00
26 $session = _load_class(
27 $session_class,
28 0 'SNMP::Insight::Session', %{ $args{snmp_params} }
29 );
30 }
31  
32 1 my $device = SNMP::Insight::Device->new( session => $session );
33  
34 1 my $device_role;
35  
36 # if classifier exists but is undef it means we should not use any
37 # classifier
38  
39 1 ▶ if ( $args{classifier} || !exists $args{classifier} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"classifier"} or not exists $args{"classifier"}) 1 0 1
Condition33%1/3
$args{"classifier"} or not exists $args{"classifier"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{"classifier"} or not exists $args{"classifier"}
$args{"classifier"} not exists $args{"classifier"}
Truth table33%1/3
A or not(B)
A= $args{"classifier"}B= not exists $args{"classifier"}
ABresult
1X1
011
000
40  
41 1 my $classifier = $args{classifier};
42  
43 1 ▶ if ( !$classifier || !blessed($classifier) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($classifier and builtin::blessed($classifier)) 1 0 1
Condition33%1/3
$classifier and builtin::blessed($classifier)
!ll&&!rl&&r
100
MC/DC0%0/2
$classifier and builtin::blessed($classifier)
$classifier builtin::blessed($classifier)
Truth table33%1/3
A and B
A= $classifierB= builtin::blessed($classifier)
ABresult
0X0
100
111
44 1 ▶ my $classifier_class = $classifier || 'SNMP::Insight::Classifier';
Condition50%1/2
$classifier || 'SNMP::Insight::Classifier'
l!l
01
MC/DC0%0/1
$classifier || 'SNMP::Insight::Classifier'
$classifier
Truth table50%1/2
A
A= $classifier
Aresult
11
00
45 1 $classifier = _load_class(
46 $classifier_class, 'SNMP::Insight::Classifier',
47 device => $device
48 );
49 }
50  
51 1 $device_role = $classifier->classify();
52 }
53  
54 1 ▶ if ( !$device_role ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($device_role) 0 1 1
55 0 _debug("debug: no info from classifier");
56 0 return $device;
57 }
58  
59 1 _debug("debug: classifier returned $device_role");
60 1 my $role_package
61 = _load_device_role( $device_role, 'SNMP::Insight::Device' );
62 1 ▶ if ($role_package) {
Branch: 1 branch
BranchTrueFalseTotal
if ($role_package) { } 1 0 1
63 1 $role_package->meta->apply($device);
64 }
65 else {
66 0 warn "$role_package not found, using bare device";
67 }
68  
69 1 return $device;
70 }
71  
72 1 ▶sub _load_class {
Subroutine _load_class: called CC=3 SCAR=11.0
73 1 my ( $class_name, $search_base, %options ) = @_;
74  
75 1 my $possible_full_name = $search_base . "::" . $class_name;
76 1 my @possible = ( $possible_full_name, $class_name );
77 1 for my $name (@possible) {
78 2 my $package = use_package_optimistically($name);
79 2 ▶ $package->can('new') and return $package->new(%options);
Branch: 1 branch
BranchTrueFalseTotal
$package->can("new") and return $package->new(%options) 1 1 2
80 }
81  
82 0 return;
83 }
84  
85 1 ▶sub _load_device_role {
Subroutine _load_device_role: called CC=3 SCAR=11.2
86 1 my ( $role_name, $search_base ) = @_;
87  
88 1 my $possible_full_name = $search_base . "::" . $role_name;
89 1 my @possible = ( $possible_full_name, $role_name );
90 1 for my $name (@possible) {
91 1 my $package = use_package_optimistically($name);
92 1 use_package_optimistically($name);
93 1 ▶ is_role($package) and return $package;
Branch: 1 branch
BranchTrueFalseTotal
is_role($package) and return $package 1 0 1
94 }
95  
96 0 return;
97 }
98  
99 2 1; # End of SNMP::Insight
100  
101 # Local Variables:
102 # mode: cperl
103 # indent-tabs-mode: nil
104 # cperl-indent-level: 4
105 # cperl-indent-parens-as-block: t
106 # End:
107  
108 __END__
« Insight/Device/Cisco/Catalyst.pm ↑ Summary Insight/MIB/QBridge.pm »