Network/Community.pm

filter: Statementstmt 100% 35 / 35 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 93.1% 54 / 58 CC 6 SCAR 8.0
CC
6
Cov
91%
new
4.2
subcommunities
2.0
members
2.0
CRAP 2.2
« Network/Algorithm/Connectivity.pm ↑ Summary Network/Algorithm/HITS.pm »
1 package SNA::Network::Community;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use List::Util qw(sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 15 ▶use Object::Tiny::XS qw(network level members_ref index w_in w_tot);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 =head1 NAME
13  
14 SNA::Network::Community - Community class for SNA::Network
15  
16  
17 =head1 SYNOPSIS
18  
19 foreach my $community ($net->communities) {
20 print int $community->members;
21 ...
22 }
23 ...
24 ...
25  
26  
27 =head1 METHODS
28  
29 =head2 new
30  
31 Creates a new community with the given named parameters.
32 Not intended for external use.
33  
34 =cut
35  
36 190 ▶sub new {
Subroutine new: called CC=4 SCAR=14.5
Pod documented
37 190 my ($package, %params) = @_;
38 190 ▶ croak 'no network passed' unless $params{network};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"network"} 0 190 190
39 190 ▶ croak 'no index passed' unless defined $params{index};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"index"} 0 190 190
40 190 ▶ croak 'no members_ref passed' unless $params{members_ref};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"members_ref"} 0 190 190
41 190 my $self = bless { %params }, $package;
42 190 return $self;
43 }
44  
45  
46 =head2 network
47  
48 Returns the reference of the L<SNA::Network> object this community belongs to.
49  
50  
51 =head2 level
52  
53 Returns the level this community belongs to in a hierarchical structure.
54 B<0> indicates the finest-granular level.
55  
56  
57 =head2 index
58  
59 Returns the index number of this community.
60 All communities are sequentially numbered starting with 0.
61  
62  
63 =head2 members
64  
65 Returns a list of L<SNA::Network::Node> objects, which are members of this community.
66  
67 =cut
68  
69 497 ▶sub members {
Subroutine members: called CC=2 SCAR=6.9
Pod documented
70 497 my ($self) = @_;
71
72 497 ▶ if ( defined $self->members_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->members_ref) { } 493 4 497
73 493 return @{ $self->members_ref };
74 }
75 else {
76 return map {
77 4 $_->members
78 } $self->subcommunities;
79 }
80 }
81  
82  
83 =head2 members_ref
84  
85 Returns the reference to the list of L<SNA::Network::Node> objects, which are members of this community.
86  
87  
88 =head2 w_in
89  
90 Returns the sum of all edge weights between community nodes
91  
92  
93 =head2 w_tot
94  
95 Returns the sum of all community node's summed degrees.
96  
97  
98 =head2 module_value
99  
100 Returns the module value of this community
101  
102 =cut
103  
104 8 ▶sub module_value {
Subroutine module_value: called CC=1 SCAR=0.0
Pod documented
105 8 my ($self) = @_;
106 8 my $net_weight = $self->network->{total_weight};
107 8 return $self->w_in / $net_weight - ( ( $self->w_in + $self->w_tot ) / ( 2 * $net_weight ) ) ** 2;
108 }
109  
110  
111 =head2 subcommunities
112  
113 Returns a list of subcommunities of this community in a hierarchical structure.
114 Returns C<undef> if there are no subcommunities.
115  
116 =cut
117  
118 12 ▶sub subcommunities {
Subroutine subcommunities: called CC=2 SCAR=7.0
Pod documented
119 12 my ($self) = @_;
120 12 ▶ return undef unless defined $self->{subcommunities};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"subcommunities"} 0 12 12
121 12 return @{ $self->{subcommunities} };
122 }
123  
124  
125 =head1 AUTHOR
126  
127 Darko Obradovic, C<< <dobradovic at gmx.de> >>
128  
129 =head1 BUGS
130  
131 Please report any bugs or feature requests to C<bug-sna-network-node at rt.cpan.org>, or through
132 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SNA-Network>. I will be notified, and then you'll
133 automatically be notified of progress on your bug as I make changes.
134  
135  
136  
137  
138 =head1 SUPPORT
139  
140 You can find documentation for this module with the perldoc command.
141  
142 perldoc SNA::Network
143  
144  
145 You can also look for information at:
146  
147 =over 4
148  
149 =item * RT: CPAN's request tracker
150  
151 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SNA-Network>
152  
153 =item * AnnoCPAN: Annotated CPAN documentation
154  
155 L<http://annocpan.org/dist/SNA-Network>
156  
157 =item * CPAN Ratings
158  
159 L<http://cpanratings.perl.org/d/SNA-Network>
160  
161 =item * Search CPAN
162  
163 L<http://search.cpan.org/dist/SNA-Network>
164  
165 =back
166  
167  
168 =head1 ACKNOWLEDGEMENTS
169  
170  
171 =head1 COPYRIGHT & LICENSE
172  
173 Copyright 2012 Darko Obradovic, all rights reserved.
174  
175 This program is free software; you can redistribute it and/or modify it
176 under the same terms as Perl itself.
177  
178  
179 =cut
180  
181 15 1;
182  
« Network/Algorithm/Connectivity.pm ↑ Summary Network/Algorithm/HITS.pm »