| 1 | package Data::Dataset::Classic::Titanic; | ||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:GENE'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Provide the classic Titanic survivor dataset | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.0103'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Text::CSV_XS (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use File::ShareDir qw(dist_dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | sub as_file { | ||||||||||||||||||||||||||
|
Subroutine
as_file: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 4 | my $file = eval { dist_dir('Data-Dataset-Classic-Titanic') . '/titanic.csv' }; | |||||||||||||||||||||||||||
| 18 | 4 | ▶ | $file = 'share/titanic.csv' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$file and -e $file
MC/DC0%0/2
$file and -e $file
$file
-e $file
Truth table33%1/3
A and B
A= $fileB= -e $file
| |||||||||||||||||||||||||||||
| 19 | unless $file && -e $file; | ||||||||||||||||||||||||||||
| 20 | 4 | return $file; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub as_list { | ||||||||||||||||||||||||||
|
Subroutine
as_list: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 1 | my $file = as_file(); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | my @data; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | my $csv = Text::CSV_XS->new({ binary => 1 }); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | open my $fh, '<', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | or die "Can't read $file: $!"; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | my $counter = 0; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | while (my $row = $csv->getline($fh)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 892 | $counter++; | |||||||||||||||||||||||||||
| 38 | 892 | ▶ | next if $counter == 1; # Skip the header | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 891 | push @data, $row; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | close $fh; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | return @data; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub as_hash { | ||||||||||||||||||||||||||
|
Subroutine
as_hash: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 1 | my $file = as_file(); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | my %data; | |||||||||||||||||||||||||||
| 52 | my @headers; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | my $csv = Text::CSV_XS->new({ binary => 1 }); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | ▶ | open my $fh, '<', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | or die "Can't read $file: $!"; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | my $counter = 0; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | while (my $row = $csv->getline($fh)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 892 | $counter++; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # If we are on the first row, grab the headers and skip the row | ||||||||||||||||||||||||||||
| 65 | 892 | ▶ | if ($counter == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 1 | push @headers, @$row; | |||||||||||||||||||||||||||
| 67 | 1 | @data{@headers} = undef; | |||||||||||||||||||||||||||
| 68 | 1 | next; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Add each row item to the growing header lists | ||||||||||||||||||||||||||||
| 72 | 891 | for my $i (0 .. @headers - 1) { | |||||||||||||||||||||||||||
| 73 | 10692 | push @{ $data{ $headers[$i] } }, $row->[$i]; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | close $fh; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | return %data; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub headers { | ||||||||||||||||||||||||||
|
Subroutine
headers: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 1 | my $file = as_file(); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | my @data; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | my $csv = Text::CSV_XS->new({ binary => 1 }); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | ▶ | open my $fh, '<', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | or die "Can't read $file: $!"; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | while (my $row = $csv->getline($fh)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 1 | push @data, @$row; | |||||||||||||||||||||||||||
| 95 | 1 | last; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | close $fh; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | return @data; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | 1; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||