File Coverage

t/PerlySense-Document-Meta-sub.t
Criterion Covered Total %
statement 61 61 100.0
branch 1 2 50.0
condition n/a
subroutine 11 11 100.0
pod n/a
total 73 74 98.6


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2 1     1   167137 use strict;
  1         2  
  1         71  
3              
4 1     1   507 use Test::More tests => 22;
  1         16346  
  1         6  
5 1     1   668 use Test::Exception;
  1         2518  
  1         3  
6              
7 1     1   672 use Data::Dumper;
  1         5722  
  1         59  
8 1     1   7 use File::Basename;
  1         2  
  1         81  
9 1     1   818 use File::Spec::Functions;
  1         484  
  1         62  
10              
11 1     1   270 use lib "../lib";
  1         533  
  1         3  
12              
13 1     1   74733 use_ok("Devel::PerlySense");
  1         623  
  1         2  
  1         1  
  1         6  
14 1     1   272 use_ok("Devel::PerlySense::Document");
  1         73  
  1         1  
  1         1  
  1         7  
15 1     1   194 use_ok("Devel::PerlySense::Document::Meta");
  1         250  
  1         1  
  1         2  
  1         9  
16              
17              
18 1 50   1   1718 BEGIN { -d "t" and chdir("t"); }
19              
20              
21 1         194 ok(my $oDocument = Devel::PerlySense::Document->new(oPerlySense => Devel::PerlySense->new()), "new ok");
22              
23              
24 1         186 my $dirData = "data/simple-lib";
25 1         3 my $fileOrigin = "$dirData/lib/Win32/Word/Writer.pm";
26              
27 1         4 ok($oDocument->parse(file => $fileOrigin), "Parsed file ok");
28              
29 1         1246 my $oMeta = $oDocument->oMeta;
30              
31 1         5 is(scalar(@{$oMeta->raLocationSub}), 33, " Correct number of pod chunks found");
  1         27  
32              
33 1         687 my $oLocation;
34              
35 1         645 ok($oLocation = $oMeta->raLocationSub->[3], "Got a POD chunk (head1 inside pod)");
36 1         556 is($oLocation->row, 314, " row");
37 1         505 is($oLocation->col, 1, " col");
38 1         425 is($oLocation->rhProperty->{nameSub}, "SaveAs", " nameSub");
39 1         418 is($oLocation->rhProperty->{namePackage}, "Win32::Word::Writer", " namePackage");
40 1         445 is($oLocation->rhProperty->{source}, q'sub SaveAs {
41             my $self = shift;
42             my ($file, %hOpt) = @_;
43             my $format = $hOpt{format} || "Document";
44              
45             defined(my $formatConst = $self->rhConst->{"wdFormat$format"}) or croak("Invalid format ($format), use Document, DOSText, DOSTextLineBreaks, EncodedText, HTML, RTF, Template, Text, TextLineBreaks, UnicodeText");
46              
47             $file = File::Spec->rel2abs($file);
48              
49             eval { $self->oDocument->SaveAs({ FileName => $file, FileFormat => $formatConst }) };
50             if($@) {
51             my $err = $@;
52             if($err =~ /OLE exception from "Microsoft Word":\n\n(.+?)\nWin32::OLE/si) {
53             die("Could not save file ($file): $1\n");
54             }
55             die($err);
56             }
57              
58             return(1);
59             }', " sourceSub");
60 1         422 is($oLocation->rhProperty->{oLocationEnd}->row, 333, " end row");
61 1         460 is($oLocation->rhProperty->{oLocationEnd}->col, 2, " end col");
62              
63              
64              
65              
66 1         1134 ok($oLocation = $oMeta->raLocationSub->[32], "Got a POD chunk (head1 inside pod)");
67 1         431 is($oLocation->row, 1031, " row");
68 1         417 is($oLocation->col, 1, " col");
69 1         605 is($oLocation->rhProperty->{nameSub}, "DESTROY", " nameSub");
70 1         424 is($oLocation->rhProperty->{namePackage}, "Win32::Word::Writer", " namePackage");
71 1         550 is($oLocation->rhProperty->{source}, q/sub DESTROY {
72             my $self = shift;
73             $self->oTable(undef);
74              
75             $self->oWord->{DisplayAlerts} = $rhConst->{wdAlertsNone};
76             $self->MarkDocumentAsSaved(); ##workaround: wdAlertsNone doesn't work in Word2000 so we insist that the document is already saved to avoid the dialog box
77              
78             $self->oWord->Quit();
79             $self->oWord(undef); #This destroys the OLE object
80              
81             #Save after quitting to keep Word from locking the file
82             if($self->fileTemp and -e $self->fileTemp) {
83             unlink($self->fileTemp) or ($^W and warn("Could not delete temp file (" . $self->fileTemp . "): $!\n"));
84             }
85             }/, " sourceSub");
86 1         424 is($oLocation->rhProperty->{oLocationEnd}->row, 1045, " end row");
87 1         424 is($oLocation->rhProperty->{oLocationEnd}->col, 2, " end col");
88              
89              
90              
91              
92              
93              
94             #print Dumper($oMeta);
95              
96              
97              
98             __END__