File Coverage

blib/lib/Data/PerlSurvey2007.pm
Criterion Covered Total %
statement 27 27 100.0
branch 6 8 75.0
condition 2 3 66.6
subroutine 4 4 100.0
pod 2 2 100.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             package Data::PerlSurvey2007;
2              
3 3     3   71322 use warnings;
  3         8  
  3         102  
4 3     3   16 use strict;
  3         6  
  3         1605  
5              
6             =head1 NAME
7              
8             Data::PerlSurvey2007 - Data results and simple code for the results of Perl Survey 2007
9              
10             =head1 VERSION
11              
12             Version 1.00
13              
14             =cut
15              
16             our $VERSION = '1.00';
17              
18             our @columns;
19              
20             =head1 SYNOPSIS
21              
22             Now you can do your own analyses of the data from Perl Survey 2007.
23              
24             use Data::PerlSurvey2007;
25              
26             my @responses = Data::PerlSurvey2007::read_responses( 'results.csv' );
27              
28             Each element of the responses coming back is a hashref that looks like this
29              
30             {
31             'Attended Perl Mongers' => '1',
32             'Attended Perl Mongers (non-local)' => '0',
33             'Attended conference' => '1',
34             'Attended conference (non-local)' => '0',
35             'CPAN modules maintained' => '12',
36             'Contributed to CPAN' => '1',
37             'Contributed to Perl 5' => '0',
38             'Contributed to Perl 6' => '0',
39             'Contributed to other projects' => '1',
40             'Contributed to websites' => '1',
41             'Country of birth' => 'au',
42             'Country of residence' => 'au',
43             'Date survey completed' => '2007-07-26 12:49:37',
44             'ID' => '25',
45             'Income' => '80000-89999',
46             'Industry/ies' => [
47             'Internet',
48             'Real Estate'
49             ],
50             'Led other projects' => '1',
51             'Other programming languages known' => [],
52             'Perl versions' => [
53             '5.005',
54             '5.6.1',
55             '5.8.4',
56             '5.8.5',
57             '5.8.8'
58             ],
59             'Perlmonks' => '0',
60             'Platforms' => [
61             'BSD - FreeBSD',
62             'Linux - Debian',
63             'Linux - Ubuntu',
64             'Mac OS/X',
65             'Windows XP'
66             ],
67             'Posted to Perl Mongers list' => '1',
68             'Posted to other list' => '1',
69             'Presented at conference' => '1',
70             'Primary language spoken' => 'English',
71             'Programming languages known' => [
72             'JavaScript',
73             'MOO',
74             'PHP',
75             'Ruby'
76             ],
77             'Proportion of Perl' => '90',
78             'Provided feedback' => '1',
79             'Sex' => 'female',
80             'Subscribed to Perl Mongers list' => '1',
81             'Subscribed to other list' => '1',
82             'Year of birth' => '1975',
83             'Years programming (total)' => '22',
84             'Years programming Perl' => '11'
85             },
86              
87             =head1 FUNCTIONS
88              
89             =head2 read_responses( $filename )
90              
91             Reads in the responses from F<$filename> and returns an array of them.
92              
93             =cut
94              
95             sub read_responses {
96 1     1 1 8 my $filename = shift;
97              
98 1         2 my @responses = ();
99              
100 1 50       47 open( my $fh, '<', $filename ) or die "Unable to read $filename: $!\n";
101 1         41 while ( <$fh> ) {
102 4580         5415 chomp;
103 4580 100 66     25020 next if /^#/ || !/./;
104              
105 4576         7315 my @fields = split_csv( $_ );
106 4576         10087 my $nfields = @fields;
107 4576 50       8795 $nfields == 34 or die "I need 34 fields, but line $. has $nfields";
108 4576 100       7609 if ( @columns ) {
109 4575         3864 my %response;
110              
111             # Turn the multi-value responses into arrayrefs
112 4575         6004 for my $col ( 7, 10, 11, 13, 14 ) {
113 22875         109168 $fields[$col] = [ split( /\s*;\s*/, $fields[$col] ) ];
114             }
115 4575         88478 @response{ @columns } = @fields;
116 4575         52310 push( @responses, \%response );
117             }
118             else {
119 1         18 @columns = @fields;
120             }
121             }
122 1         1844 return @responses;
123             }
124              
125              
126             =head2 split_csv( $str )
127              
128             Split the CSV fields into individual columns, and get rid of the quotes.
129              
130             =cut
131              
132             sub split_csv {
133 4577     4577 1 5118 my $str = shift;
134              
135 4577         159109 my @cols = ( $str =~ /(?:^|,)("(?:[^"]+|"")*"|[^,]*)/g );
136              
137 4577         90982 s/^"(.*)"$/$1/ for @cols;
138              
139 4577         51136 return @cols;
140             }
141              
142             =head1 AUTHOR
143              
144             Andy Lester, C<< >>
145              
146             =head1 BUGS
147              
148             Please report any bugs or feature requests to
149             C, or through the web interface at
150             L.
151             I will be notified, and then you'll automatically be notified of progress on
152             your bug as I make changes.
153              
154             =head1 SUPPORT
155              
156             You can find documentation for this module with the perldoc command.
157              
158             perldoc Data::PerlSurvey2007
159              
160             You can also look for information at:
161              
162             =over 4
163              
164             =item * AnnoCPAN: Annotated CPAN documentation
165              
166             L
167              
168             =item * CPAN Ratings
169              
170             L
171              
172             =item * RT: CPAN's request tracker
173              
174             L
175              
176             =item * Search CPAN
177              
178             L
179              
180             =back
181              
182             =head1 ACKNOWLEDGEMENTS
183              
184             =head1 COPYRIGHT & LICENSE
185              
186             Copyright 2007 Andy Lester, all rights reserved.
187              
188             This program is free software; you can redistribute it and/or modify it
189             under the same terms as Perl itself.
190              
191             =cut
192              
193             1; # End of Data::PerlSurvey2007