Commits

Burak Gürsoy  committed eac0364

Cleanup.
Remove stupid functions.
Remove useless test.

  • Participants
  • Parent commits ba520ae

Comments (0)

Files changed (12)

    => Get rid of IS_FLOCK as Win9x is dead and irrelevant.
    => Renamed some constants.
    => visualize_whitespace() is now in ::Util.
+   => Removed ref type checking functions.
+   => Removed interface test.
 
 0.86 Mon Mar  5 22:10:12 2012
    => Fixed a stupid error where I forgot to unpack @_.
 t/011-cache-mem.t
 t/012-cache-disk.t
 t/013-cache-other.t
-t/014-interface.t
 t/015-connector.t
 t/016-include-static.t
 t/017-include-dynamic.t

File lib/Text/Template/Simple.pm

 our $VERSION = '0.87';
 
 use File::Spec;
+
+use Text::Template::Simple::Cache;
+use Text::Template::Simple::Cache::ID;
+use Text::Template::Simple::Caller;
+use Text::Template::Simple::Compiler;
+use Text::Template::Simple::Compiler::Safe;
 use Text::Template::Simple::Constants qw(:all);
 use Text::Template::Simple::Dummy;
-use Text::Template::Simple::Compiler;
-use Text::Template::Simple::Compiler::Safe;
-use Text::Template::Simple::Caller;
+use Text::Template::Simple::IO;
 use Text::Template::Simple::Tokenizer;
-use Text::Template::Simple::Util qw(:all);
-use Text::Template::Simple::Cache::ID;
-use Text::Template::Simple::Cache;
-use Text::Template::Simple::IO;
+use Text::Template::Simple::Util      qw(:all);
 
 use base qw(
    Text::Template::Simple::Base::Compiler
    Text::Template::Simple::Base::Parser
 );
 
-my %CONNECTOR = ( # Default classes list
-   'Cache'     => 'Text::Template::Simple::Cache',
-   'Cache::ID' => 'Text::Template::Simple::Cache::ID',
-   'IO'        => 'Text::Template::Simple::IO',
-   'Tokenizer' => 'Text::Template::Simple::Tokenizer',
+my %CONNECTOR = qw(
+   Cache       Text::Template::Simple::Cache
+   Cache::ID   Text::Template::Simple::Cache::ID
+   IO          Text::Template::Simple::IO
+   Tokenizer   Text::Template::Simple::Tokenizer
 );
 
 my %DEFAULT = ( # default object attributes
 sub tts {
    my @args = @_;
    fatal('tts.main.tts.args') if ! @args;
-   my @new  = ishref($args[0]) ? %{ shift @args } : ();
+   my @new  = ref $args[0] eq 'HASH' ? %{ shift @args } : ();
    return __PACKAGE__->new( @new )->compile( @args );
 }
 
 
 sub compile {
    my($self, @args) = @_;
-   my $rv    = $self->_compile( @args );
+   my $rv = $self->_compile( @args );
    # we need to reset this to prevent false positives
    # the trick is: this is set in _compile() and sub includes call _compile()
    # instead of compile(), so it will only be reset here
 sub _init {
    my $self = shift;
    my $d    = $self->[DELIMITERS];
-   my $bogus_args = $self->[ADD_ARGS] && ! isaref($self->[ADD_ARGS]);
+   my $bogus_args = $self->[ADD_ARGS] && ref $self->[ADD_ARGS] ne 'ARRAY';
 
    fatal('tts.main.bogus_args')   if $bogus_args;
-   fatal('tts.main.bogus_delims') if ! isaref( $d ) || $#{ $d } != 1;
+   fatal('tts.main.bogus_delims') if ref $d ne 'ARRAY' || $#{ $d } != 1;
    fatal('tts.main.dslen')        if length($d->[DELIM_START]) < 2;
    fatal('tts.main.delen')        if length($d->[DELIM_END])   < 2;
    fatal('tts.main.dsws')         if $d->[DELIM_START] =~ m{\s}xms;
    $self->[FAKER_HASH]     = $self->_output_buffer_var('hash');
    $self->[FAKER_SELF]     = $self->_output_buffer_var('self');
    $self->[INSIDE_INCLUDE] = RESET_FIELD;
-   $self->[NEEDS_OBJECT]   =  0; # the template needs $self ?
-   $self->[DEEP_RECURSION] =  0; # recursion detector
+   $self->[NEEDS_OBJECT]   = 0; # the template needs $self ?
+   $self->[DEEP_RECURSION] = 0; # recursion detector
 
    fatal('tts.main.init.thandler')
-      if $self->[USER_THANDLER] && ! iscref($self->[USER_THANDLER]);
+      if $self->[USER_THANDLER] && ref $self->[USER_THANDLER] ne 'CODE';
 
    fatal('tts.main.init.include')
-      if $self->[INCLUDE_PATHS] && ! isaref($self->[INCLUDE_PATHS]);
+      if $self->[INCLUDE_PATHS] && ref $self->[INCLUDE_PATHS] ne 'ARRAY';
 
    $self->[IO_OBJECT] = $self->connector('IO')->new(
                            @{ $self }[ IOLAYER, INCLUDE_PATHS, TAINT_MODE ],

File lib/Text/Template/Simple/Base/Compiler.pm

    my $self = shift;
    my $opt  = shift || {};
 
-   fatal('tts.base.compiler._compile.opt') if ! ishref( $opt );
+   fatal('tts.base.compiler._compile.opt') if ref $opt ne 'HASH';
 
    # set defaults
    $opt->{id}       ||= EMPTY_STRING; # id is AUTO
 
    # first element is the shared names. if it's not defined, then there
    # are no shared variables from top level
-   if ( isaref($opt->{_share}) && ! defined $opt->{_share}[0] ) {
+   if ( ref $opt->{_share} eq 'ARRAY' && ! defined $opt->{_share}[0] ) {
       delete $opt->{_share};
    }
 
    my $param = shift || [];
    my $opt   = $self->_init_compile_opts( shift );
 
-   fatal('tts.base.compiler._compile.param') if ! isaref($param);
+   fatal('tts.base.compiler._compile.param') if ref $param ne 'ARRAY';
 
    my $tmp = $self->_examine( $tmpx );
    return $tmp if $self->[TYPE] eq 'ERROR';
    my $param    = shift || fatal('tts.base.compiler._mini_compiler.noparam');
    my $opt      = shift || {};
 
-   fatal('tts.base.compiler._mini_compiler.opt')   if ! ishref($opt  );
-   fatal('tts.base.compiler._mini_compiler.param') if ! ishref($param);
+   fatal('tts.base.compiler._mini_compiler.opt')   if ref $opt   ne 'HASH';
+   fatal('tts.base.compiler._mini_compiler.param') if ref $param ne 'HASH';
 
    foreach my $var ( keys %{ $param } ) {
       my $str = $param->{$var};

File lib/Text/Template/Simple/Base/Examine.pm

    return EMPTY_STRING ,  $TMP if ! $ref;
    return GLOB         => $TMP if   $ref eq 'GLOB';
 
-   if ( isaref( $TMP ) ) {
+   if ( ref $TMP eq 'ARRAY' ) {
       my $ftype  = shift @{ $TMP } || fatal('tts.base.examine._examine_type.ftype');
       my $fthing = shift @{ $TMP } || fatal('tts.base.examine._examine_type.fthing');
       fatal('tts.base.examine._examine_type.extra') if @{ $TMP };

File lib/Text/Template/Simple/Cache.pm

 
 use Carp qw( croak );
 use Text::Template::Simple::Constants qw(:all);
-use Text::Template::Simple::Util      qw( DEBUG LOG ishref fatal );
+use Text::Template::Simple::Util      qw( DEBUG LOG fatal );
 
 our $VERSION = '0.85';
 
    my $self  = shift;
    my $type  = shift || 'structure';
    my $param = shift || {};
-   fatal('tts.cache.dumper.hash')        if not ishref $param;
+   fatal('tts.cache.dumper.hash')        if ref $param ne 'HASH';
    my %valid = map { ($_, $_) } qw( ids structure );
    fatal('tts.cache.dumper.type', $type) if not $valid{ $type };
    my $method = '_dump_' . $type;

File lib/Text/Template/Simple/Caller.pm

 use constant HINTS      => 8;
 use constant BITMASK    => 9;
 
-use Text::Template::Simple::Util      qw( ishref fatal );
+use Text::Template::Simple::Util      qw( fatal );
 use Text::Template::Simple::Constants qw( EMPTY_STRING );
 
 our $VERSION = '0.85';
 sub stack {
    my $self    = shift;
    my $opt     = shift || {};
-   fatal('tts.caller.stack.hash') if ! ishref($opt);
+   fatal('tts.caller.stack.hash') if ref $opt ne 'HASH';
    my $frame   = $opt->{frame} || 0;
    my $type    = $opt->{type}  || EMPTY_STRING;
    my(@callers, $context);

File lib/Text/Template/Simple/Dummy.pm

 sub stack { # just a wrapper
    my $opt = shift || {};
    Text::Template::Simple::Util::fatal('tts.caller.stack.hash')
-      if ! Text::Template::Simple::Util::ishref($opt);
+      if ref $opt ne 'HASH';
    $opt->{frame} = 1;
    return Text::Template::Simple::Caller->stack( $opt );
 }

File lib/Text/Template/Simple/IO.pm

 use Text::Template::Simple::Util qw(
    binary_mode
    fatal
-   ishref
    DEBUG
    LOG
 );

File lib/Text/Template/Simple/Tokenizer.pm

 
 sub _get_command_chars {
    my($self, $str) = @_;
-   my($first_cmd, $second_cmd, $last_cmd);
-   # $first is the left-cmd, $last is the right-cmd. $second is the extra
-   $first_cmd  = substr $str, SUBSTR_OFFSET_FIRST , SUBSTR_LENGTH if $str ne EMPTY_STRING;
-   $second_cmd = substr $str, SUBSTR_OFFSET_SECOND, SUBSTR_LENGTH if $str ne EMPTY_STRING;
-   $last_cmd   = substr $str, length($str) - 1    , SUBSTR_LENGTH if $str ne EMPTY_STRING;
-   return $first_cmd  || EMPTY_STRING,
-          $second_cmd || EMPTY_STRING,
-          $last_cmd   || EMPTY_STRING;
+   return
+      $str ne EMPTY_STRING # left
+         ? substr $str, SUBSTR_OFFSET_FIRST , SUBSTR_LENGTH : EMPTY_STRING,
+      $str ne EMPTY_STRING # extra
+         ? substr $str, SUBSTR_OFFSET_SECOND, SUBSTR_LENGTH : EMPTY_STRING,
+      $str ne EMPTY_STRING # right
+         ? substr $str, length($str) - 1    , SUBSTR_LENGTH : EMPTY_STRING,
+   ;
 }
 
 sub _user_commands {

File lib/Text/Template/Simple/Util.pm

 our $VERSION = '0.85';
 
 BEGIN {
-   # create a wrapper for binmode() 
    if ( UNICODE_PERL ) {
       # older perl binmode() does not accept a second param
       *binary_mode = sub {
       *binary_mode = sub { binmode $_[0] };
    }
    our %EXPORT_TAGS = (
-      macro => [qw( isaref      ishref iscref                  )],
       util  => [qw( binary_mode DIGEST trim rtrim ltrim escape )],
       debug => [qw( fatal       DEBUG  LOG  L                  )],
       misc  => [qw( visualize_whitespace                       )],
 my $DEBUG = 0; # Disabled by default
 my $DIGEST;    # Will hold digester class name.
 
-sub isaref { my $x = shift; return ref($x) eq 'ARRAY' };
-sub ishref { my $x = shift; return ref($x) eq 'HASH'  };
-sub iscref { my $x = shift; return ref($x) eq 'CODE'  };
-
 sub L {
    my($type, $id, @param) = @_;
    croak q{Type parameter to L() is missing} if ! $type;
    return $str;
 }
 
+*LOG = __PACKAGE__->can('MYLOG') || sub {
+   my @args = @_;
+   my $self    = ref $args[0] ? shift @args : undef;
+   my $id      = shift @args;
+   my $message = shift @args;
+      $id      = 'DEBUG'        if not defined $id;
+      $message = '<NO MESSAGE>' if not defined $message;
+      $id      =~ s{_}{ }xmsg;
+   $message = sprintf q{[ % 15s ] %s}, $id, $message;
+   warn "$message\n";
+   return;
+};
+
 sub DEBUG {
    my $thing = shift;
 
    return $DIGEST->new;
 }
 
-sub LOG {
-   my @args = @_;
-   return MYLOG( @args ) if defined &MYLOG;
-   my $self    = ref $args[0] ? shift @args : undef;
-   my $id      = shift @args;
-   my $message = shift @args;
-      $id      = 'DEBUG'        if not defined $id;
-      $message = '<NO MESSAGE>' if not defined $message;
-      $id      =~ s{_}{ }xmsg;
-   $message = sprintf q{[ % 15s ] %s}, $id, $message;
-   warn "$message\n";
-   return;
-}
-
 sub _is_parent_object {
    my $test = shift;
    return ! defined $test       ? 0
 
 Internal method.
 
-=head2 C<isaref THING>
-
-Returns true if C<THING> is an ARRAY.
-
-=head2 C<ishref THING>
-
-Returns true if C<THING> is a HASH.
-
-=head2 C<iscref THING>
-
-Returns true if C<THING> is a CODE.
-
 =head2 C<trim STRING>
 
 Returns the trimmed version of the C<STRING>.

File t/014-interface.t

-#!/usr/bin/env perl -w
-use strict;
-use warnings;
-use Test::More qw( no_plan );
-use Text::Template::Simple;
-use Text::Template::Simple::Constants qw(:all);
-use Text::Template::Simple::Dummy;
-use Text::Template::Simple::Compiler;
-use Text::Template::Simple::Compiler::Safe;
-use Text::Template::Simple::Caller;
-use Text::Template::Simple::Tokenizer;
-use Text::Template::Simple::Util qw(:all);
-use Text::Template::Simple::Cache::ID;
-use Text::Template::Simple::Cache;
-use Text::Template::Simple::IO;
-
-can_ok( 'Text::Template::Simple',
-        qw/
-            new
-            cache
-            io
-            compile
-            connector
-            _init
-            class_id
-            _output_buffer_var
-            _examine
-            _wrap_compile
-            _tidy
-            _parse
-            _add_stack
-            include
-            DESTROY
-        /
-    );
-can_ok( 'Text::Template::Simple::Constants',
-        qw/
-            UNICODE_PERL
-            IS_WINDOWS
-            COMPILER
-            COMPILER_SAFE
-            DUMMY_CLASS
-            MAX_FILENAME_LENGTH
-            CACHE_EXT
-            PARENT
-            DISK_CACHE_MARKER
-            DELIM_START
-            DELIM_END
-            DELIMS
-            DELIMITERS
-            AS_STRING
-            DELETE_WS
-            FAKER
-            FAKER_HASH
-            CACHE
-            CACHE_DIR
-            CACHE_OBJECT
-            IO_OBJECT
-            STRICT
-            SAFE
-            HEADER
-            ADD_ARGS
-            WARN_IDS
-            TYPE
-            COUNTER
-            CID
-            FILENAME
-            IOLAYER
-            STACK
-            USER_THANDLER
-            MAXOBJFIELD
-            DIGEST_MODS
-            STAT_MTIME
-            RE_DUMP_ERROR
-            STAT_SIZE
-            RE_NONFILE
-        /
-    );
-can_ok( 'Text::Template::Simple::Dummy',
-        qw/
-            stack
-        /
-    );
-can_ok( 'Text::Template::Simple::Compiler',
-        qw/
-            compile
-        /
-    );
-can_ok( 'Text::Template::Simple::Compiler::Safe',
-        qw/
-            compile
-            _object
-            _permit
-        /
-    );
-can_ok( 'Text::Template::Simple::Caller',
-        qw/
-            PACKAGE
-            FILENAME
-            LINE
-            SUBROUTINE
-            HASARGS
-            WANTARRAY
-            EVALTEXT
-            IS_REQUIRE
-            HINTS
-            BITMASK
-            stack
-            _string
-            _html_comment
-            _html_table
-            _html_table_blank_check
-            _text_table
-        /
-    );
-can_ok( 'Text::Template::Simple::Tokenizer',
-        qw/
-            CMD_CHAR
-            CMD_ID
-            CMD_CALLBACK
-            TOKEN_ID
-            TOKEN_STR
-            LAST_TOKEN
-            ID_DS
-            ID_DE
-            SUBSTR_OFFSET_FIRST
-            SUBSTR_OFFSET_SECOND
-            SUBSTR_LENGTH
-            new
-            tokenize
-            _token_code
-            _user_commands
-            tilde
-            quote
-        /
-    );
-can_ok( 'Text::Template::Simple::Util',
-        qw/
-            binary_mode
-            isaref
-            ishref
-            fatal 
-            DEBUG
-            DIGEST
-            LOG
-            _is_parent_object
-        /
-    );
-can_ok( 'Text::Template::Simple::Cache::ID',
-        qw/
-            new
-            get
-            set
-            generate
-            _custom
-        /
-    );
-can_ok( 'Text::Template::Simple::Cache',
-        qw/
-            new
-            id
-            type
-            reset
-            dumper
-            _dump_ids
-            _dump_structure
-            _dump_disk_cache
-            size
-            has
-            hit
-            populate
-            DESTROY
-        /
-    );
-can_ok( 'Text::Template::Simple::IO',
-        qw/
-            new
-            validate
-            layer
-            slurp
-            DESTROY
-        /
-    );