Browse Source

use strict and use warnings on Markup.pm and Image.pm.

pull/1/head
Brennen Bearnes 17 years ago
parent
commit
1ece8138ec
2 changed files with 43 additions and 43 deletions
  1. +22
    -26
      Display/Image.pm
  2. +21
    -17
      Display/Markup.pm

+ 22
- 26
Display/Image.pm View File

@ -1,15 +1,16 @@
package Display::Image;
use strict;
use warnings;
use base qw(Exporter);
our @EXPORT_OK = qw(image_size image_markup gallery);
# Figure out if certain dependencies are available:
#my $has_imgsize = eval 'use Image::Size;';
#my $has_imager = eval 'use Imager;';
use Image::Size;
$has_imgsize = 1;
use Imager;
my $has_imgsize = 1;
=item gallery
Returns an HTML gallery of images for a given directory.
@ -37,13 +38,16 @@ sub gallery {
my ($x, $y) = thumbnail($dir, $image);
$output .= <<"HTML";
<a href="$baseurl/$image"><img src="$baseurl/Thumbs/$image"
width="$x" height="$y" /></a>
<a href="$baseurl/$image">
<img src="$baseurl/Thumbs/$image"
width="$x"
height="$y" />
</a>
HTML
}
return $output;
return "<p>$output</p>";
}
sub thumbnail {
@ -51,22 +55,20 @@ sub thumbnail {
my $thumb_dir = "$dir/Thumbs";
my ($x, $y);
if (-e "$thumb_dir/$image") {
($x, $y) = image_size("$thumb_dir/$image");
# Return a size for the existing image:
return image_size("$thumb_dir/$image");
} else {
#return unless $has_imager; # without this, there's not much we can do -
# and we already know there's not an existing
# thumbnail.
# Make a new thumbnail and save a copy:
my $img = Imager->new;
$img->read(file => "$dir/$image") or die $img->errstr;
$scaled = $img->scale(xpixels => 128);
$img->read(file => "$dir/$image")
or die $img->errstr;
my $scaled = $img->scale(xpixels => 128);
$scaled->write(file => "$thumb_dir/$image");
($x, $y) = ($scaled->getwidth, $scaled->getheight);
# Return the thumbnail size:
return ($scaled->getwidth, $scaled->getheight);
}
return ($x, $y);
}
@ -82,18 +84,12 @@ and Andrew Tong.
=cut
sub image_size {
my ($image_file) = shift;
my ($x, $y, $type);
if ($has_imgsize) {
($x, $y, $type) = imgsize($image_file);
return imgsize($_[0]);
}
else {
($x, $y) = wwwis($image_file);
return wwwis($_[0]);
}
return ($x, $y);
}


+ 21
- 17
Display/Markup.pm View File

@ -1,5 +1,8 @@
package Display::Markup;
use strict;
use warnings;
use base qw(Exporter);
our @EXPORT_OK = qw(line_parse);
@ -50,16 +53,16 @@ Parses some special markup, specifically:
sub line_parse {
my ($everything, $file) = (@_);
# take care of wala markup
# Take care of wala markup:
$everything =~ s/<wala>(.*?)<\/wala>/Wala::wikify($1)/seg;
# take care of textile markup, if we've got any
# Take care of textile markup, if we've got any:
textile_process($everything);
# evaluate <gallery> tags.
# Evaluate <gallery> tags:
$everything =~ s!<gallery>(.*?)</gallery>!gallery_markup($file, $1)!seg;
# evaluate <image> tags.
# Evaluate <image> tags:
$everything =~ s!<image>(.*?)</image>!image_markup($file, $1)!seg;
foreach my $key (keys %tags) {
@ -70,26 +73,27 @@ sub line_parse {
$dashes{$key} = " -- " unless $dashes{$key};
while ($everything =~ m/(<$key>.*?<\/$key>)/s) {
my $block = $1;
# save the bits between instances of the block --
# Save the bits between instances of the block:
my (@interstice_array) = split /\Q$block\E/s, $everything;
# now, transform the contents of the block we've found:
# Transform the contents of the block:
# tags that surround the block
# Tags that surround the block:
$block =~ s/\n?<$key>\n?/<$tags{$key}>/gs;
$block =~ s!\n?</$key>\n?!</$end_tags{$key}>!gs;
# dashes
# Dashes:
$block = dashes($dashes{$key}, $block);
# blank lines within the block
# Blank lines within the block:
$block =~ s/\n\n/$blank_lines{$key}/gs;
$block = newlines($newlines{$key}, $block);
# and slap it all back together as $everything
# ...and slap it all back together as $everything
$everything = join $block, @interstice_array;
}
@ -101,18 +105,18 @@ sub line_parse {
sub newlines {
my ($replacement, $block) = @_;
# single newlines (i.e., line ends) within the block
# Single newlines (i.e., line ends) within the block,
# except those preceded by a double-quote, which probably
# indicates a still-open tag:
$block =~ s/(?<=[^"\n]) # not a double-quote or newline
# don't capture
$block =~ s/(?<=[^"\n]) # not a double-quote or newline
# don't capture
\n # end-of-line
\n # end-of-line
(?=[^\n]) # not a newline
# don't capture
/$replacement/xgs;
(?=[^\n]) # not a newline
# don't capture
/$replacement/xgs;
return $block;


|||||||
x
 
000:0
Loading…
Cancel
Save