lib/NetAddr/BridgeID.pm

filter: Statementstmt 90.9% 50 / 55 Branchbran 66.6% 12 / 18 Conditioncond 53.8% 7 / 13 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 76.7% 79 / 103 CC 15 SCAR 26.0
CC
15
Cov
80%
__ANON__
19.3
bridge_id
2.0
BEGIN
1.0
CRAP 13.5
↑ Summary
1 package NetAddr::BridgeID;
2  
3 3 our $VERSION = '0.97'; # VERSION
4 # ABSTRACT: Object for BridgeIDs (priority/MAC combos)
5  
6 3 ▶use sanity;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use NetAddr::MAC;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use MooX::Types::MooseLike::Base qw/InstanceOf Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use MooX::Types::CLike qw/UShort/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 has original => (
15 is => 'ro',
16 isa => Str,
17 required => 1,
18 );
19 3 has priority => (
20 is => 'ro',
21 isa => UShort,
22 required => 1,
23 );
24 has mac_obj => (
25 is => 'ro',
26 isa => InstanceOf['NetAddr::MAC'],
27 required => 1,
28 handles => {
29 3 (map { $_ => $_ } qw(
30 is_eui48
31 is_eui64
32 is_multicast
33 is_unicast
34 is_local
35 is_universal
36 as_basic
37 as_bpr
38 as_cisco
39 as_ieee
40 as_ipv6_suffix
41 as_microsoft
42 as_singledash
43 as_sun
44 as_tokenring
45 to_eui48
46 to_eui64
47 )),
48 qw(
49 mac original
50 ),
51 },
52 );
53  
54 0 ▶sub bridge_id { $_[0]->priority.'#'.$_[0]->as_cisco; }
Subroutine bridge_id: not called CC=1 SCAR=6.9
Pod documented
55  
56  
57 4 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=15 SCAR=29.6
58 4 my ($orig, $self) = (shift, shift);
59 4 my %opts;
60  
61 4 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 2 2 4
62 2 my $arg = pop;
63 2 ▶ if (blessed $arg) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($arg)) { } 2 0 2
elsif (ref $arg eq 'ARRAY') { } 0 0 0
elsif (ref $arg eq 'HASH') { } 0 0 0
64 2 ▶ if ($arg->isa('NetAddr::BridgeID')) { $opts{bridge_id} = $arg->original; }
Branch: 2 branches
BranchTrueFalseTotal
if ($arg->isa('NetAddr::BridgeID')) { } 1 1 2
elsif ($arg->isa('NetAddr::MAC')) { } 1 0 1
65 1 elsif ($arg->isa('NetAddr::MAC')) { $opts{mac_obj} = $arg; }
66 0 else { $opts{bridge_id} = $arg; }
67 }
68 0 elsif (ref $arg eq 'ARRAY') { %opts = @$arg; }
69 0 elsif (ref $arg eq 'HASH') { %opts = %$arg; }
70 0 else { $opts{bridge_id} = $arg; }
71 }
72 2 else { %opts = @_; }
73  
74 # parse vars from bridge_id
75 4 ▶ if (defined $opts{bridge_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"bridge_id"}) 2 2 4
76 2 $opts{bridge_id} =~ /^(\d+)\#(.+)$/;
77 2 ▶ $opts{priority} //= $1;
Condition33%1/3
$opts{"priority"} //= $1
l!l&&r!l&&!r
020
MC/DC0%0/2
$opts{"priority"} //= $1
$opts{"priority"} $1
Truth table33%1/3
A //= B
A= $opts{"priority"}B= $1
ABresult
1X1
011
000
78 2 ▶ $opts{mac} //= $2;
Condition33%1/3
$opts{"mac"} //= $2
l!l&&r!l&&!r
020
MC/DC0%0/2
$opts{"mac"} //= $2
$opts{"mac"} $2
Truth table33%1/3
A //= B
A= $opts{"mac"}B= $2
ABresult
1X1
011
000
79 }
80  
81 # parse mac from mac_obj
82 4 ▶ $opts{mac} //= $opts{mac_obj}->original if (defined $opts{mac_obj});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"mac_obj"} 1 3 4
Condition33%1/3
$opts{"mac"} //= $opts{"mac_obj"}->original
l!l&&r!l&&!r
010
MC/DC0%0/2
$opts{"mac"} //= $opts{"mac_obj"}->original
$opts{"mac"} $opts{"mac_obj"}->original
Truth table33%1/3
A //= B
A= $opts{"mac"}B= $opts{"mac_obj"}->original
ABresult
1X1
011
000
83  
84 # defaults
85 4 ▶ $opts{priority} //= 0;
Condition100%2/2
$opts{"priority"} //= 0
l!l
31
MC/DC100%1/1
$opts{"priority"} //= 0
$opts{"priority"}
Truth table100%2/2
A
A= $opts{"priority"}
Aresult
11
00
86 4 ▶ $opts{bridge_id} //= $opts{priority}.'#'.$opts{mac};
Condition100%2/2
$opts{"bridge_id"} //= $opts{"priority"} . '#' . $opts{"mac"}
l!l
22
MC/DC100%1/1
$opts{"bridge_id"} //= $opts{"priority"} . '#' . $opts{"mac"}
$opts{"bridge_id"}
Truth table100%2/2
A
A= $opts{"bridge_id"}
Aresult
11
00
87 #$opts{mac_obj} //= NetAddr::MAC->new( mac => $opts{mac} );
88
89 # NetAddr::MAC has some weird issues with MAC translation here
90 # (see https://rt.cpan.org/Ticket/Display.html?id=79915)
91 4 ▶ unless ($opts{mac_obj}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"mac_obj"}) 3 1 4
92 3 my $new_mac = $opts{mac};
93 3 $new_mac =~ s/[^\da-f]//gi;
94 3 $new_mac =~ s/(.{4})(?=.)/$1./g;
95 3 $opts{mac_obj} = NetAddr::MAC->new( mac => $new_mac );
96 3 $opts{mac_obj}->{original} = $opts{mac}; # Ugly and hacky; remove when bug is fixed
97 }
98
99 # bridge_id is actually 'original'
100 4 $opts{original} = delete $opts{bridge_id};
101 4 delete $opts{mac};
102  
103 4 $orig->($self, \%opts);
104 3 };
105  
106 3 1;
107  
108  
109  
110 =pod
111  
112 =encoding utf-8
113  
114 =head1 NAME
115  
116 NetAddr::BridgeID - Object for BridgeIDs (priority/MAC combos)
117  
118 =head1 SYNOPSIS
119  
120 use NetAddr::BridgeID;
121
122 my $bid;
123 $bid = NetAddr::BridgeID->new( '2#00:11:22:aa:bb:cc' );
124 $bid = NetAddr::BridgeID->new( bridge_id => '60#0011.22AA.BBCC' );
125
126 use NetAddr::MAC;
127 my $mac = NetAddr::MAC->new( mac => '0011.22AA.BBCC' );
128
129 $bid = NetAddr::BridgeID->new( priority => '60', mac_obj => $mac );
130 $bid = NetAddr::BridgeID->new( priority => '60', mac => '0011.22AA.BBCC' );
131  
132 =head1 DESCRIPTION
133  
134 This object class simply creates a L<NetAddr::MAC>-like object, with a priority for
135 STP Bridge IDs.
136  
137 =for Pod::Coverage BUILDARGS
138  
139 =head1 METHODS
140  
141 =head2 original
142  
143 The original bridge ID string, as it was passed to the constructor. If it was passed
144 in pieces (or if parts were left out), it will fill in the gaps to provide a full
145 bridge ID
146  
147 =head2 bridge_id
148  
149 The bridge ID, with a Cisco-style MAC address (like C<0000.1111.2222>).
150  
151 =head2 priority
152  
153 The priority number.
154  
155 =head2 mac_obj
156  
157 The L<NetAddr::MAC> object tied to this one.
158  
159 =head2 NetAddr::MAC Methods
160  
161 All of the C<is_* / as_* / to_*> methods are "handled" to the main BridgeID object, so
162 you can access them directly.
163  
164 =head1 AVAILABILITY
165  
166 The project homepage is L<https://github.com/SineSwiper/NetAddr-BridgeID/wiki>.
167  
168 The latest version of this module is available from the Comprehensive Perl
169 Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN
170 site near you, or see L<https://metacpan.org/module/NetAddr::BridgeID/>.
171  
172 =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
173  
174 =head1 SUPPORT
175  
176 =head2 Internet Relay Chat
177  
178 You can get live help by using IRC ( Internet Relay Chat ). If you don't know what IRC is,
179 please read this excellent guide: L<http://en.wikipedia.org/wiki/Internet_Relay_Chat>. Please
180 be courteous and patient when talking to us, as we might be busy or sleeping! You can join
181 those networks/channels and get help:
182  
183 =over 4
184  
185 =item *
186  
187 irc.perl.org
188  
189 You can connect to the server at 'irc.perl.org' and join this channel: #distzilla then talk to this person for help: SineSwiper.
190  
191 =back
192  
193 =head2 Bugs / Feature Requests
194  
195 Please report any bugs or feature requests via L<L<https://github.com/SineSwiper/NetAddr-BridgeID/issues>|GitHub>.
196  
197 =head1 AUTHOR
198  
199 Brendan Byrd <BBYRD@CPAN.org>
200  
201 =head1 COPYRIGHT AND LICENSE
202  
203 This software is Copyright (c) 2013 by Brendan Byrd.
204  
205 This is free software, licensed under:
206  
207 The Artistic License 2.0 (GPL Compatible)
208  
209 =cut
210  
211  
212 __END__
↑ Summary