[Cpan-forum-commit] rev 25 - in trunk: . lib/CPAN lib/CPAN/Forum t
svn at pti.co.il
svn at pti.co.il
Mon Jan 17 01:05:00 IST 2005
Author: gabor
Date: 2005-01-17 01:05:00 +0200 (Mon, 17 Jan 2005)
New Revision: 25
Added:
trunk/lib/CPAN/Forum/Markup.pm
Modified:
trunk/MANIFEST
trunk/lib/CPAN/Forum.pm
trunk/lib/CPAN/Forum/INC.pm
trunk/t/010-markup.t
Log:
separate the code dealing with the markup to another module
Modified: trunk/MANIFEST
===================================================================
--- trunk/MANIFEST 2005-01-16 22:51:33 UTC (rev 24)
+++ trunk/MANIFEST 2005-01-16 23:05:00 UTC (rev 25)
@@ -8,6 +8,7 @@
bin/setup.pl
lib/CPAN/Forum.pm
+lib/CPAN/Forum/Markup.pm
lib/CPAN/Forum/Build.pm
lib/CPAN/Forum/DBI.pm
lib/CPAN/Forum/INC.pm
Modified: trunk/lib/CPAN/Forum/INC.pm
===================================================================
--- trunk/lib/CPAN/Forum/INC.pm 2005-01-16 22:51:33 UTC (rev 24)
+++ trunk/lib/CPAN/Forum/INC.pm 2005-01-16 23:05:00 UTC (rev 25)
@@ -1,6 +1,7 @@
package CPAN::Forum::INC;
use CPAN::Forum;
+use CPAN::Forum::Markup;
use CPAN::Forum::Configure;
use CPAN::Forum::DBI;
use CPAN::Forum::Users;
Added: trunk/lib/CPAN/Forum/Markup.pm
===================================================================
--- trunk/lib/CPAN/Forum/Markup.pm 2005-01-16 22:51:33 UTC (rev 24)
+++ trunk/lib/CPAN/Forum/Markup.pm 2005-01-16 23:05:00 UTC (rev 25)
@@ -0,0 +1,64 @@
+package CPAN::Forum::Markup;
+use strict;
+use warnings;
+
+use CGI qw(escapeHTML);
+
+sub new {
+ my ($class) = @_;
+ bless {}, $class;
+}
+
+
+# will someone simplify this code ??
+sub posting_process {
+ my ($self, $t) = @_;
+
+ my ($text, $rest) = split /<code>/, $t, 2;
+ my $ret = $self->text_proc($text);
+ if (not $rest) {
+ if ($t =~ /<code>/) {
+ die "ERR open_code_without_closing\n";
+ } else {
+ return $ret;
+ }
+ }
+
+ die "ERR open_code_without_closing\n" if $rest !~ m{</code>};
+ my ($code, $more) = split /<\/code>/, $rest, 2;
+ $ret .= $self->code_proc($code);
+ $ret .= $self->posting_process($more) if $more;
+ return $ret;
+}
+
+
+sub text_proc {
+ my ($self, $text) = @_;
+ die "ERR no_less_sign\n" if $text =~ /</;
+ $self->line_width($text);
+ $text = escapeHTML $text;
+ return qq(<div class="text">$text</div>\n);
+}
+
+sub code_proc {
+ my ($self, $code) = @_;
+ $self->line_width($code);
+ #$code =~ s/</</g;
+ $code = escapeHTML $code;
+ return qq(<div class="code">$code</div>\n);
+}
+
+sub line_width {
+ my ($self, $str) = @_;
+ my @lines = split /\n/, $str;
+ foreach my $line (@lines) {
+ die "ERR line_too_long\n" if length $line > 70;
+ }
+ return 1;
+}
+
+
+
+
+1;
+
Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm 2005-01-16 22:51:33 UTC (rev 24)
+++ trunk/lib/CPAN/Forum.pm 2005-01-16 23:05:00 UTC (rev 25)
@@ -11,7 +11,6 @@
use Fcntl qw(:flock);
use POSIX qw(strftime);
use Carp qw(cluck carp);
-use CGI qw(escapeHTML);
use CPAN::Forum::INC;
@@ -1183,8 +1182,9 @@
# We will save the message only if the Submit button was pressed.
# When the editor first displayed and every time if an error was caught this button will be hidden.
+ my $markup = CPAN::Forum::Markup->new();
eval {
- _posting_process($new_text) ;
+ $markup->posting_process($new_text) ;
};
if ($@) {
push @errors, "text_format";
@@ -1261,7 +1261,8 @@
my ($text) = @_;
return "" if not $text;
- my $html = eval { _posting_process($text) };
+ my $markup = CPAN::Forum::Markup->new();
+ my $html = eval { $markup->posting_process($text) };
if ($@) {
warn "Error displaying already accepted text: '$text' $@";
return "Internal Error";
@@ -1618,53 +1619,6 @@
$t->output;
}
-sub _line_width {
- my $str = shift;
- my @lines = split /\n/, $str;
- foreach my $line (@lines) {
- die "ERR line_too_long\n" if length $line > 70;
- }
- return 1;
-}
-
-
-sub _text_proc {
- my $text = shift;
- die "ERR no_less_sign\n" if $text =~ /</;
- _line_width($text);
- $text = escapeHTML $text;
- return qq(<div class="text">$text</div>\n);
-}
-
-sub _code_proc {
- my $code = shift;
- _line_width($code);
- #$code =~ s/</</g;
- $code = escapeHTML $code;
- return qq(<div class="code">$code</div>\n);
-}
-
-# will someone simplify this code ??
-sub _posting_process {
- my ($t) = @_;
-
- my ($text, $rest) = split /<code>/, $t, 2;
- my $ret = _text_proc($text);
- if (not $rest) {
- if ($t =~ /<code>/) {
- die "ERR open_code_without_closing\n";
- } else {
- return $ret;
- }
- }
-
- die "ERR open_code_without_closing\n" if $rest !~ m{</code>};
- my ($code, $more) = split /<\/code>/, $rest, 2;
- $ret .= _code_proc($code);
- $ret .= _posting_process($more) if $more;
- return $ret;
-}
-
=head2 rss
Provide RSS feed
Modified: trunk/t/010-markup.t
===================================================================
--- trunk/t/010-markup.t 2005-01-16 22:51:33 UTC (rev 24)
+++ trunk/t/010-markup.t 2005-01-16 23:05:00 UTC (rev 25)
@@ -6,8 +6,10 @@
use Test::Exception;
use lib "blib/lib";
-use CPAN::Forum;
+use CPAN::Forum::Markup;
+my $markup = CPAN::Forum::Markup->new();
+
my %cases = (
'apple' => qr(\s*<div class="text">apple</div>\s*),
'apple<code><</code>' => qr(\s*<div class="text">apple</div>\s*<div class="code"><</div>\s*),
@@ -35,7 +37,7 @@
sub f {
- CPAN::Forum::_posting_process(@_);
+ $markup->posting_process(@_);
}
More information about the Cpan-forum-commit
mailing list