blib/lib/HTML/LBI.pm

filter: Statementstmt 82.1% 60 / 73 Branchbran 62.5% 15 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 78.7% 85 / 108 CC 16 SCAR 27.1
CC
16
Cov
77%
new
24.1
_wanted
2.0
BEGIN
1.0
CRAP 15.0
↑ Summary
1 package HTML::LBI;
2 #############################################################
3 # HTML::LBI
4 # Whyte.Wolf DreamWeaver HTML Library Module
5 # Version 2.00
6 #
7 # Copyright (c) 2002 by S.D. Campbell <whytwolf@spots.ab.ca>
8 #
9 # Created 03 February 2002; Revised 12 February 2002 by SDC
10 #
11 # Description:
12 # A perl module for use with CGI scripts that opens a
13 # Macromedia Dreamweaver library file (.lbi) and returns
14 # the resulting HTML code snippet.
15 #
16 #############################################################
17 #
18 # Construction:
19 # use HTML::LBI;
20 #
21 # $html = new HTML::LBI("file.lbi");
22 #
23 # Use:
24 # Create a new instance of HTML::LBI as above by passing
25 # a pathname to the library file (absolute or relative)
26 # to the constructor. The constructor will return
27 # the HTML from the .lbi file, which can then be printed out.
28 #
29 # Errors:
30 # Should the library file fail to open an error will be set
31 # in $HTML::LBI::errmsg
32 #
33 #############################################################
34 #
35 # This program is free software; you can redistribute it and/or
36 # modify it under the terms of the GNU General Public License
37 # as published by the Free Software Foundation; either version 2
38 # of the License, or (at your option) any later version.
39 #
40 # This program is distributed in the hope that it will be useful,
41 # but WITHOUT ANY WARRANTY; without even the implied warranty of
42 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 # GNU General Public License for more details.
44 #
45 # You should have received a copy of the GNU General Public License
46 # along with this program; if not, write to the Free Software
47 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
48 #############################################################
49  
50 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 1 @ISA = qw(Exporter);
56 1 @EXPORT = qw();
57 1 @EXPORT_OK = qw($errmsg);
58  
59 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use vars qw($errmsg $VERSION @ISA @EXPORT @EXPORT_OK $filepath $fname);
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 1 $VERSION = '2.00';
63  
64 1 $errmsg = "";
65 1 $filepath ='';
66 1 $fname = '';
67  
68 #############################################################
69 # new
70 #
71 # The constructor for the class. Requires a HTML Library
72 # filename. Returns a reference to the new object or undef
73 # on error.
74  
75 3 ▶sub new {
Subroutine new: called CC=15 SCAR=31.8
Pod undocumented
76 3 my $class = shift;
77 3 my %params = @_;
78 3 my @search = ();
79  
80 3 my $self = {};
81
82 3 ▶ if (!$params{filename}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($params{"filename"}) 1 2 3
83 1 $params{filename} = $_[0];
84 }
85
86 3 $$self{filename} = $params{filename};
87 3 $$self{lbi} = _beginLbi($$self{filename});
88
89 3 ▶ if (exists($params{path})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{'path'}) { } 1 2 3
90 1 ▶ if (ref($params{path}) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params{"path"} ne "ARRAY") 1 0 1
91 1 $$self{path} = [ $params{path} ];
92 }
93 1 $$self{path} = $params{path};
94 } else {
95 2 $$self{path} = './';
96 }
97  
98 3 foreach my $path ($$self{path}){
99 3 push @search, $path;
100 }
101
102 3 ▶ if ($ENV{'HTML_TEMPLATE_ROOT'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTML_TEMPLATE_ROOT"}) 0 3 3
103 0 my $temproot = $ENV{'HTML_TEMPLATE_ROOT'};
104 0 push @search, $temproot;
105 }
106
107 3 ▶ if ($ENV{'DOCUMENT_ROOT'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DOCUMENT_ROOT"}) 0 3 3
108 0 my $docroot = $ENV{'DOCUMENT_ROOT'};
109 0 push @search, $docroot;
110 }
111
112
113 3 ▶ if (substr($$self{filename}, 0, 1) ne '/') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($self->{'filename'}, 0, 1) ne '/') { } 3 0 3
elsif (substr($self->{'filename'}, 0, 8) eq '/Library') { } 0 0 0
114 3 $fname = $$self{filename};
115 3 foreach my $dir (@search){
116 3 find(\&_wanted, $dir);
117 }
118 3 ▶ if (!$filepath) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($HTML::LBI::filepath) 1 2 3
119 1 $filepath = $$self{filename};
120 }
121 } elsif (substr($$self{filename}, 0, 8) eq '/Library') {
122 0 my ($name, $path, $suffix) = fileparse($$self{filename}, '\.lbi');
123 0 $fname = $name . $suffix;
124 0 foreach my $dir (@search){
125 0 find(\&_wanted, $dir);
126 }
127 0 ▶ if (!$filepath) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($HTML::LBI::filepath) 0 0 0
128 0 $filepath = $$self{filename};
129 }
130 } else {
131 0 $filepath = $$self{filename};
132 }
133  
134 3 ▶ unless(open(LBI_FILE, $filepath)){
Branch: 1 branch
BranchTrueFalseTotal
unless (open LBI_FILE, $HTML::LBI::filepath) 0 3 3
135 0 $errmsg = "Library File $filepath not opened: $!\n";
136 0 return undef;
137 }
138  
139 3 ▶ while(<LBI_FILE>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline LBI_FILE)) 18 3 21
140 18 $$self{lbi} .= $_;
141 }
142  
143 3 $$self{lbi} .= _endLbi();
144  
145 3 bless $self, $class;
146 3 return $$self{lbi};
147 }
148  
149 #############################################################
150 # _beginLbi
151 #
152 # Returns the begin library string and file name back into
153 # the parsed HTML.
154  
155 3 ▶sub _beginLbi {
Subroutine _beginLbi: called CC=1 SCAR=0.0
156 3 my $filename = shift;
157 3 return "\n<!-- \#BeginLibraryItem \"$filename\" -->\n";
158 }
159  
160  
161 #############################################################
162 # _endLbi
163 #
164 # Returns the end library string back into the parsed HTML.
165  
166 3 ▶sub _endLbi {
Subroutine _endLbi: called CC=1 SCAR=0.0
167 3 return "\n<!-- \#EndLibraryItem -->\n";
168 }
169  
170 #############################################################
171 # _wanted
172 #
173 # Returns the path to a file (if it exists).
174  
175 114 ▶sub _wanted {
Subroutine _wanted: called CC=2 SCAR=6.9
176
177 114 ▶ /$fname$/ or return;
Branch: 1 branch
BranchTrueFalseTotal
/$HTML::LBI::fname$/ or return 1 113 114
178 1 $filepath = $File::Find::name;
179
180 }
181  
182  
183 1 1;
184 __END__
↑ Summary