Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

liol (5527)

liol
  (email not shown publicly)
http://www.template-toolkit.ru/

Perl programmer as expected. First experience I got in past century. I'm living in World Wide Web and sometimes in Yekaterinburg (Russia). 2 sons and 1 wife.

Journal of liol (5527)

Thursday March 31, 2005
04:00 AM

Template::Toolkit::HTML::BBCode 0.01 released on CPAN

This week I have uploaded TT2 wrapper around HTML::BBCode.

Module provides filter which converts BBCode to HTML.

[% USE HTML::BBCode %]
[% FILTER bbcode %]
  [b]Bold[/b]
  [i]Italic[/i]
  etc
[% END %]

Friday January 28, 2005
01:54 PM

new japh

#!/usr/bin/perl
$=-=$=;tie$;,'main';$_{$;,$;,$;,$;,$;,$;,$;,$;,$;,$;,$;,$;,$;}= $=;($_=
each%_)?print:_;sub TIESCALAR{bless[split'',"jtqq\x1C\x5chhl_[g\x14c".
"Wc\x5C\x0FVNOVO[\x09"],$_[$ =--];}sub FETCH{chr ord($_[0]->[$=])+$=++}

Thursday January 13, 2005
08:25 AM

First japh

#!/usr/bin/perl
eval qq{#line $$ "just another perl hacker"\ndie};$@=~/j.+r/;print$&;

Wednesday December 22, 2004
01:07 AM

Beautiful perl

Enjoy!

#!/usr/bin/perl

@a = @b = ( "%s %s\n", 'a', 'b' );

print sprintf( @a );
print sprintf( shift @a, @a );
printf( @b );
printf( shift @b, @b );

Tuesday December 21, 2004
01:09 PM

Convert from/to UTF8 TT2 filter plugin (unreleased).

This is not released on CPAN module. After discussion in Template Toolkit mailing list it was decided not to publish it. Neighthertheless I'm saving it here. In two words, this is a wrapper around Unicode::MapUTF8. It provides two filters from_utf8 and to_utf8.

#==================================================== -*-Perl-*-
#
# MyOrg::Template::Plugin::Unicode::MapUTF8
#
# DESCRIPTION
#   Wrapper around Unicode::MapUTF8 module which converts
#   text in different charsets into UTF8
#
# AUTHOR
#   Igor Lobanov   <*@*>
#
# COPYRIGHT
#   Copyright (C) 2004 Igor Lobanov.  All Rights Reserved.
#
#   This module is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
#===============================================================

package MyOrg::Template::Plugin::Unicode::MapUTF8;

use strict;
use vars qw( $VERSION );
use Template::Plugin;
use Template::Exception;
use base qw( Template::Plugin );
use Unicode::MapUTF8 qw( to_utf8 from_utf8 utf8_supported_charset );

$VERSION = sprintf("%d.%02d", q$Revision: 0.01 $ =~ /(\d+)\.(\d+)/);

# Use this charset in filters by default
my $DEFAULT_CHARSET = 'ISO-8859-1';
# Type name of TT exception
my $EXCEPTION_TYPE = 'MapUTF8';

# Hash with filter subs for each requested charset
my $filter_set = {};

sub new {
    my ( $class, $context ) = @_;
    $context->define_filter( 'to_utf8', [ \&to_utf8_filter, 1 ] );
    $context->define_filter( 'from_utf8', [ \&from_utf8_filter, 1 ] );
    bless {}, $class;
}

sub to_utf8_filter {
    my ( $context, $charset ) = @_;
    $charset ||= $DEFAULT_CHARSET;
    utf8_supported_charset( $charset )
        or die Template::Exception->new(
            $EXCEPTION_TYPE,
            "character set '$charset' is not supported" );
    # Create filter sub for charset only once and reuse it later
    $filter_set->{$charset}->{'utf8'} ||= sub {
        my $text = shift;
        to_utf8( -string => $text, -charset => $charset );
    };
    return $filter_set->{$charset}->{'utf8'};
}

sub from_utf8_filter {
    my ( $context, $charset ) = @_;
    $charset ||= $DEFAULT_CHARSET;
    utf8_supported_charset( $charset )
        or die Template::Exception->new(
            $EXCEPTION_TYPE,
            "character set '$charset' is not supported" );
    $filter_set->{'utf8'}->{$charset} ||= sub {
        my $text = shift;
        from_utf8( -string => $text, -charset => $charset );
    };
    return $filter_set->{'utf8'}->{$charset};
}

1;

__END__

=head1 NAME

MyOrg::Template::Plugin::Unicode::MapUTF8 - Template Toolkit
plugin wrapper around Unicode::MapUTF8.

=head1 SYNOPSIS

code:

use Template;
...
my $template = new Template(
     ...
     PLUGIN_BASE    => 'MyOrg::Template::Plugin'
     ...
);

template:

[% USE Unicode::MapUTF8 %]

[%# From cyrillic KOI8-R to UTF-8 #%]
[% FILTER from_utf8( 'koi8-r' ) %]
...
here UTF8 text
...
[% END %]

[%# From ISO-8859-1 (by default) to UTF-8 #%]
[% FILTER to_utf8 %]
...
here ISO-8859-1 text
...
[% END %]

=head1 DESCRIPTION

This Template Toolkit plugin implements two filters for
conversions to and from arbitrary character sets and UTF8.
Plugin uses Benjamin Franz module L<Unicode::MapUTF8>.

=head2 to_utf8

[% FILTER to_utf8( charset ) %]
...
here text in
...
[% END %]

Converts text inside block to UTF8 from the specified source
charset. Default B<charset> value is I<ISO-8859-1>.

=head2 from_utf8

[% FILTER from_utf8( charset ) %]
...
here UTF8 text
...
[% END %]

Converts text inside block from UTF8 to the specified source
charset. Default B<charset> value is I<ISO-8859-1>.

=head1 SEE ALSO

L<Template|Template>, L<Unicode::MapUTF8|Unicode::MapUTF8>

=head1 AUTHOR

Igor Lobanov, E<lt>*@*E<gt>

=head1 COPYRIGHT

Copyright (C) 2004 Igor Lobanov. All Rights Reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=cut

Saturday December 18, 2004
01:42 PM

My first...

This week I got my first PAUSE experience. CPAN inside is beautiful. I suspected this but now I know.

My first published module is very specific one - plugin to Template Toolkit which implements filter for cyrillic to translit conversion (Template::Plugin::Translit::RU).