[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]Archive::Zip[/green] [red]qw([/red][purple]:ERROR_CODES :CONSTANTS[/purple][red])[/red][red];[/red]
[black][b]use[/b][/black] [green]File::Find[/green][red];[/red]
[black][b]use[/b][/black] [green]File::Slurp[/green] [red]qw([/red][purple]read_file[/purple][red])[/red][red];[/red]
[black][b]use[/b][/black] [green]File::Spec::Functions[/green] [red]qw([/red][purple]abs2rel rel2abs updir catdir catfile[/purple][red])[/red][red];[/red]
[black][b]use[/b][/black] [green]strict[/green][red];[/red]
[black][b]use[/b][/black] [green]warnings[/green][red];[/red]
[gray][i]# The Directory to be zipped recursively[/i][/gray]
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$dir[/blue] = [maroon]rel2abs[/maroon][red]([/red][red]'[/red][purple]temp[/purple][red]'[/red][red])[/red][red];[/red]
[black][b]my[/b][/black] [blue]$parent[/blue] = [maroon]catdir[/maroon][red]([/red][blue]$dir[/blue], updir[red])[/red][red];[/red]
[black][b]my[/b][/black] [blue]$zip[/blue] = Archive::Zip->[maroon]new[/maroon][red]([/red][red])[/red][red];[/red]
[maroon]find[/maroon][red]([/red][red]{[/red]
[purple]no_chdir[/purple] => [fuchsia]1[/fuchsia],
[purple]wanted[/purple] => [url=http://perldoc.perl.org/functions/sub.html][black][b]sub[/b][/black][/url] [red]{[/red]
[black][b]my[/b][/black] [blue]$fqfn[/blue] = [blue]$File::Find::name[/blue][red];[/red]
[black][b]my[/b][/black] [blue]$rfn[/blue] = [maroon]abs2rel[/maroon][red]([/red][blue]$fqfn[/blue], [blue]$parent[/blue][red])[/red][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][url=http://perldoc.perl.org/functions/-X.html][black][b]-d[/b][/black][/url] [blue]$fqfn[/blue][red])[/red] [red]{[/red]
[blue]$zip[/blue]->[maroon]addDirectory[/maroon][red]([/red][blue]$fqfn[/blue], [blue]$rfn[/blue][red])[/red][red];[/red]
[red]}[/red] [olive][b]elsif[/b][/olive] [red]([/red][url=http://perldoc.perl.org/functions/-X.html][black][b]-f[/b][/black][/url] [blue]$fqfn[/blue][red])[/red] [red]{[/red]
[blue]$zip[/blue]->[maroon]addFile[/maroon][red]([/red][blue]$fqfn[/blue], [blue]$rfn[/blue][red])[/red][red];[/red]
[gray][i]### Replace above line with below two.[/i][/gray]
[gray][i]#my $data = read_file($fqfn, binmode => ':raw');[/i][/gray]
[gray][i]#$zip->addString(\$data, $rfn);[/i][/gray]
[red]}[/red] [olive][b]else[/b][/olive] [red]{[/red]
[url=http://perldoc.perl.org/functions/warn.html][black][b]warn[/b][/black][/url] [red]"[/red][purple]Unknown entity: [blue]$fqfn[/blue][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[red]}[/red]
[url=http://perldoc.perl.org/functions/return.html][black][b]return[/b][/black][/url][red];[/red]
[red]}[/red]
[red]}[/red], [blue]$dir[/blue][red])[/red][red];[/red]
[black][b]my[/b][/black] [blue]$archive[/blue] = [maroon]catfile[/maroon][red]([/red][blue]$parent[/blue], [red]'[/red][purple]temp.zip[/purple][red]'[/red][red])[/red][red];[/red]
[gray][i]# Save the Zip file[/i][/gray]
[olive][b]unless[/b][/olive] [red]([/red] [blue]$zip[/blue]->[maroon]writeToFileNamed[/maroon][red]([/red][blue]$archive[/blue][red])[/red] == AZ_OK [red])[/red] [red]{[/red]
[url=http://perldoc.perl.org/functions/die.html][black][b]die[/b][/black][/url] [red]'[/red][purple]write error[/purple][red]'[/red][red];[/red]
[red]}[/red]