File Coverage

blib/lib/SNA/Network/Community.pm
Criterion Covered Total %
statement 27 27 100.0
branch 3 6 50.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             package SNA::Network::Community;
2              
3 14     14   76 use strict;
  14         26  
  14         435  
4 14     14   73 use warnings;
  14         26  
  14         390  
5              
6 14     14   72 use Carp;
  14         27  
  14         975  
7 14     14   85 use List::Util qw(sum);
  14         23  
  14         748  
8              
9 14     14   81 use Object::Tiny::XS qw(network members_ref index w_in w_tot);
  14         22  
  14         145  
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 619 my ($package, %params) = @_;
38 190 50       414 croak 'no network passed' unless $params{network};
39 190 50       378 croak 'no index passed' unless defined $params{index};
40 190 50       363 croak 'no members_ref passed' unless $params{members_ref};
41 190         948 my $self = bless { %params }, $package;
42 190         845 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 index
52              
53             Returns the index number of this community.
54             All communities are sequentially numbered starting with 0.
55              
56              
57             =head2 members
58              
59             Returns a list of L objects, which are members of this community.
60              
61             =cut
62              
63             sub members {
64 491     491 1 1850 my ($self) = @_;
65 491         481 return @{ $self->members_ref };
  491         2262  
66             }
67              
68              
69             =head2 members_ref
70              
71             Returns the reference to the list of L objects, which are members of this community.
72              
73              
74             =head2 w_in
75              
76             Returns the sum of all edge weights between community nodes
77              
78              
79             =head2 w_tot
80              
81             Returns the sum of all community node's summed degrees.
82              
83              
84             =head2 module_value
85              
86             Returns the module value of this community
87              
88             =cut
89              
90             sub module_value {
91 8     8 1 10 my ($self) = @_;
92 8         22 my $net_weight = $self->network->{total_weight};
93 8         65 return $self->w_in / $net_weight - ( ( $self->w_in + $self->w_tot ) / ( 2 * $net_weight ) ) ** 2;
94             }
95              
96              
97              
98             =head1 AUTHOR
99              
100             Darko Obradovic, C<< >>
101              
102             =head1 BUGS
103              
104             Please report any bugs or feature requests to C, or through
105             the web interface at L. I will be notified, and then you'll
106             automatically be notified of progress on your bug as I make changes.
107              
108              
109              
110              
111             =head1 SUPPORT
112              
113             You can find documentation for this module with the perldoc command.
114              
115             perldoc SNA::Network
116              
117              
118             You can also look for information at:
119              
120             =over 4
121              
122             =item * RT: CPAN's request tracker
123              
124             L
125              
126             =item * AnnoCPAN: Annotated CPAN documentation
127              
128             L
129              
130             =item * CPAN Ratings
131              
132             L
133              
134             =item * Search CPAN
135              
136             L
137              
138             =back
139              
140              
141             =head1 ACKNOWLEDGEMENTS
142              
143              
144             =head1 COPYRIGHT & LICENSE
145              
146             Copyright 2012 Darko Obradovic, all rights reserved.
147              
148             This program is free software; you can redistribute it and/or modify it
149             under the same terms as Perl itself.
150              
151              
152             =cut
153              
154             1;
155