File Coverage

blib/lib/SNA/Network/Community.pm
Criterion Covered Total %
statement 34 34 100.0
branch 6 10 60.0
condition n/a
subroutine 9 9 100.0
pod 4 4 100.0
total 53 57 92.9


line stmt bran cond sub pod time code
1             package SNA::Network::Community;
2              
3 14     14   56 use strict;
  14         19  
  14         512  
4 14     14   56 use warnings;
  14         16  
  14         264  
5              
6 14     14   52 use Carp;
  14         17  
  14         699  
7 14     14   58 use List::Util qw(sum);
  14         18  
  14         688  
8              
9 14     14   87 use Object::Tiny::XS qw(network level members_ref index w_in w_tot);
  14         37  
  14         129  
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             sub new {
37 190     190 1 389 my ($package, %params) = @_;
38 190 50       298 croak 'no network passed' unless $params{network};
39 190 50       278 croak 'no index passed' unless defined $params{index};
40 190 50       235 croak 'no members_ref passed' unless $params{members_ref};
41 190         569 my $self = bless { %params }, $package;
42 190         488 return $self;
43             }
44              
45              
46             =head2 network
47              
48             Returns the reference of the L 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 objects, which are members of this community.
66              
67             =cut
68              
69             sub members {
70 497     497 1 1038 my ($self) = @_;
71            
72 497 100       805 if ( defined $self->members_ref ) {
73 493         356 return @{ $self->members_ref };
  493         1177  
74             }
75             else {
76 6         9 return map {
77 4         9 $_->members
78             } $self->subcommunities;
79             }
80             }
81              
82              
83             =head2 members_ref
84              
85             Returns the reference to the list of L 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             sub module_value {
105 8     8 1 10 my ($self) = @_;
106 8         15 my $net_weight = $self->network->{total_weight};
107 8         45 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 if there are no subcommunities.
115              
116             =cut
117              
118             sub subcommunities {
119 12     12 1 14 my ($self) = @_;
120 12 50       20 return undef unless defined $self->{subcommunities};
121 12         12 return @{ $self->{subcommunities} };
  12         24  
122             }
123              
124              
125             =head1 AUTHOR
126              
127             Darko Obradovic, C<< >>
128              
129             =head1 BUGS
130              
131             Please report any bugs or feature requests to C, or through
132             the web interface at L. 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
152              
153             =item * AnnoCPAN: Annotated CPAN documentation
154              
155             L
156              
157             =item * CPAN Ratings
158              
159             L
160              
161             =item * Search CPAN
162              
163             L
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             1;
182