| 1 | package Plucene::SearchEngine::Index::XLS; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.001'; # VERSION | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: a Plucene backend for indexing Microsoft Excel spreadsheets | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use parent qw(Plucene::SearchEngine::Index::Base); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | __PACKAGE__->register_handler('application/xls', '.xls'); | |||||||||||||||||||||||||||
| 10 | 1 | ▶ | use File::Temp qw/tmpnam/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Spreadsheet::ParseExcel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub gather_data_from_file { | ||||||||||||||||||||||||||
|
Subroutine
gather_data_from_file: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 17 | 0 | ▶ | return unless $file =~ m/\.xls$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if ($file =~ m/\.xls$/) { # Process only xls file data. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 0 | my $txtfile = tmpnam(); | |||||||||||||||||||||||||||
| 21 | 0 | _exceltotext($file, $txtfile); | |||||||||||||||||||||||||||
| 22 | 0 | $file = $txtfile; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 0 | my $in; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | if (exists $self->{encoding}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | my $encoding = $self->{encoding}{data}[0]; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | open $in, "<:encoding($encoding)", $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | or die "Couldn't open $file: $!"; | ||||||||||||||||||||||||||||
| 29 | } else { | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | open $in, '<', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | or die "Couldn't open $file: $!"; | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | while (<$in>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | $self->add_data('text' => 'UnStored' => $_); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 0 | unlink $file; #Remove the text file, part of maintenance. | |||||||||||||||||||||||||||
| 37 | 0 | return $self; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub _exceltotext { | ||||||||||||||||||||||||||
|
Subroutine
_exceltotext: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 41 | ##This is the standard code taken from SpreadSheet::ParseExcel Module. | ||||||||||||||||||||||||||||
| 42 | 0 | my $excel = shift; | |||||||||||||||||||||||||||
| 43 | 0 | my $output = shift; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $oExcel = Spreadsheet::ParseExcel->new(); | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | open my $txt_out, '>', $output or die "Not able to open file : $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $oBook = $oExcel->Parse($excel); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | print $txt_out "FILE :", $oBook->{File} , "\n"; | |||||||||||||||||||||||||||
| 51 | 0 | print $txt_out "COUNT :", $oBook->{SheetCount} , "\n"; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | print $txt_out "AUTHOR:", $oBook->{Author} , "\n" | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if defined $oBook->{Author}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | my $oWkS = $oBook->{Worksheet}[$iSheet]; | |||||||||||||||||||||||||||
| 58 | 0 | print OUTPUT $oWkS->{Name}, "\n"; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | for(my $iR = $oWkS->{MinRow} ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $oWkS->{"MaxRow"} and $iR <= $oWkS->{"MaxRow"}
MC/DC0%0/2
defined $oWkS->{"MaxRow"} and $iR <= $oWkS->{"MaxRow"}
defined $oWkS->{"MaxRow"}
$iR <= $oWkS->{"MaxRow"}
Truth table0%0/3
A and B
A= defined $oWkS->{"MaxRow"}B= $iR <= $oWkS->{"MaxRow"}
| |||||||||||||||||||||||||||||
| 60 | defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; | ||||||||||||||||||||||||||||
| 61 | $iR++) | ||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | for(my $iC = $oWkS->{MinCol} ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $oWkS->{"MaxCol"} and $iC <= $oWkS->{"MaxCol"}
MC/DC0%0/2
defined $oWkS->{"MaxCol"} and $iC <= $oWkS->{"MaxCol"}
defined $oWkS->{"MaxCol"}
$iC <= $oWkS->{"MaxCol"}
Truth table0%0/3
A and B
A= defined $oWkS->{"MaxCol"}B= $iC <= $oWkS->{"MaxCol"}
| |||||||||||||||||||||||||||||
| 64 | defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ; | ||||||||||||||||||||||||||||
| 65 | $iC++) | ||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||
| 67 | 0 | my $oWkC = $oWkS->{Cells}[$iR][$iC]; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | print OUTPUT $oWkC->Value, "\n" if($oWkC); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 0 | close($txt_out); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||