File Coverage

blib/lib/SWF/File.pm
Criterion Covered Total %
statement 56 59 94.9
branch 14 22 63.6
condition 3 7 42.8
subroutine 10 11 90.9
pod 6 7 85.7
total 89 106 83.9


line stmt bran cond sub pod time code
1             package SWF::File;
2            
3 1     1   4860 use strict;
  1         3  
  1         50  
4            
5 1     1   7 use SWF::Element;
  1         2  
  1         24  
6 1     1   2408 use SWF::BinStream::File;
  1         5  
  1         42  
7 1     1   10 use Carp;
  1         3  
  1         1866  
8            
9             our $VERSION = '0.033';
10             our @ISA = ('SWF::BinStream::Write::SubStream');
11            
12             sub new {
13 1     1 1 21 my ($class, $file, %header) = @_;
14 1         15 my $stream = SWF::BinStream::File::Write->new($file, $header{Version});
15 1         12 my $self = $stream->sub_stream;
16            
17 1   33     10 bless $self, ref($class)||$class;
18            
19 1         10 $self->{_header_CompressFlag} = 0;
20 1   50     12 $self->FrameRate( $header{FrameRate} || 12 );
21 1   50     13 $self->FrameSize( $header{FrameSize} || [0, 0, 12800, 9600] );
22 1         6 $self;
23             }
24            
25             sub FrameRate {
26 3 100   3 1 216 $_[0]->{_header_FrameRate} = $_[1] if defined $_[1];
27 3         20 $_[0]->{_header_FrameRate};
28             }
29            
30             sub FrameCount {
31 1 50   1 1 5 $_[0]->{_framecount} = $_[1] if defined $_[1];
32 1         7 $_[0]->{_framecount};
33             }
34            
35            
36             sub FrameSize {
37 3     3 1 51 my $self = shift;
38            
39 3 100       15 return $self->{_header_FrameSize} if @_==0;
40            
41 2 50       5 if (eval{$_[0]->isa('SWF::Element::RECT')}) {
  2         31  
42 0         0 $self->{_header_FrameSize} = $_[0]->clone;
43             } else {
44 2         4 my @param;
45            
46 2 100       8 if (ref($_[0]) eq 'ARRAY') {
47 1         2 @param = @{$_[0]};
  1         4  
48             } else {
49 1         4 @param = @_;
50             }
51 2 50       9 @param = map {(qw/Xmin Ymin Xmax Ymax/)[$_], $param[$_]} (0..3) if (@param == 4);
  8         28  
52 2         22 $self->{_header_FrameSize} = SWF::Element::RECT->new(@param);
53             }
54             }
55            
56             sub compress {
57 1     1 1 7 my ($self, $flag) = @_;
58            
59 1 50       6 $flag = 1 unless defined $flag;
60            
61 1 50       14 if ($self->Version < 6) {
62 0         0 croak "Compressed SWF is supported by version 6 or higher ";
63             } else {
64 1         4 $self->{_header_CompressedFlag} = $flag;
65             }
66             }
67            
68             sub close {
69 1     1 1 2 my ($self, $file) = @_;
70 1         3 my $file_stream = $self->{_parent};
71 1         3 my $cf = $self->{_header_CompressedFlag};
72            
73 1 50       4 $file_stream->open($file) if defined $file;
74 1 50       14 $file_stream->set_string( $cf ? 'CWS' : 'FWS' );
75 1         10 $file_stream->set_UI8($self->Version);
76 1         9 my $temp = $file_stream->sub_stream;
77 1         12 $self->FrameSize->pack($temp);
78 1         16 $file_stream->set_UI32( 3+1+4+ $temp->tell +2+2+ $self->tell); # Total File Length
79 1 50       9 if ($cf) {
80 1         7 $file_stream->add_codec('Zlib');
81             }
82 1         11 $temp->flush_stream;
83 1         8 $file_stream->set_UI16($self->FrameRate * 256);
84 1         6 $file_stream->set_UI16($self->FrameCount);
85 1         10 $self->SUPER::flush_stream;
86 1         8 $file_stream->close;
87             }
88            
89             *SWF::File::save = \&close;
90            
91 0     0 0   sub flush_stream {}
92            
93             1;
94             __END__