view Lib/IMPL/Resources/Format.pm @ 93:0667064553ef

fixed _is_class in activator rewritten IMPL::Config::Resolve new features in the Abstract class
author wizard
date Wed, 28 Apr 2010 17:50:55 +0400
parents 16ada169ca75
children 196bf443b5e1
line wrap: on
line source

package IMPL::Resources::Format;
use strict;
use warnings;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(&FormatMessage);

sub FormatMessage {
    my ($string,$args) = @_;
    
    $string =~ s/%(\w+(?:\.\w+)*)%/_getvalue($args,$1,"\[$1\]")/ge;
    
    return $string;
}

sub _getvalue {
    my ($obj,$path,$default) = @_;
    
    foreach my $chunk (split /\./,$path) {
        if (eval { $obj->can( $chunk ) } ) {
            $obj = $obj->$chunk();
        } elsif (UNIVERSAL::isa($obj,'HASH')) {
            $obj = $obj->{$chunk};
        } else {
            return $default;
        }
    }
    return $obj;
}

1;