Changeset 736

Show
Ignore:
Timestamp:
08/22/02 14:27:42
Author:
miyagawa
Message:

parse/set method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Template-Plugin-Properties/trunk/Changes

    r720 r736  
    11Revision history for Perl extension Template::Plugin::Properties 
     2 
     30.02  Thu Aug 22 14:26:22 JST 2002 
     4        * Added (undocumented) parse method 
    25 
    360.01  Thu Aug 15 21:51:58 2002 
  • Template-Plugin-Properties/trunk/Makefile.PL

    r720 r736  
    77        'Data::Properties' => 0.02, 
    88        'Template' => 2.08, 
     9        'IO::Scalar' => 0, 
    910    }, 
    1011); 
  • Template-Plugin-Properties/trunk/lib/Template/Plugin/Properties.pm

    r720 r736  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.01
     5$VERSION = 0.02
    66 
    77require Template::Plugin; 
     
    1010use Data::Properties; 
    1111use FileHandle; 
     12use IO::Scalar; 
     13 
     14use vars qw($DYNAMIC $FILTER_NAME); 
     15$DYNAMIC = 1; 
     16$FILTER_NAME = 'parse_property'; 
    1217 
    1318sub croak { require Carp; Carp::croak(@_); } 
     
    1520sub new { 
    1621    my($class, $context, $filename, $params) = @_; 
    17     my $handle = FileHandle->new($filename) or croak("$filename: $!"); 
    18     my $props  = Data::Properties->new; 
    19     $props->load($handle); 
     22    my $props = Data::Properties->new; 
     23    if ($filename) { 
     24        my $handle = FileHandle->new($filename) or croak("$filename: $!"); 
     25        $props->load($handle); 
     26    } 
    2027    bless { _props => $props }, $class; 
    2128} 
     
    2835} 
    2936 
     37sub set { 
     38    my($self, $param) = @_; 
     39    $self->props->set_property(%$param); 
     40    return; # set_property() returns 1 
     41} 
     42 
    3043sub names { 
    3144    my $self = shift; 
     
    3346} 
    3447 
     48sub parse { 
     49    my($self, $text) = @_; 
     50    my $handle = IO::Scalar->new(\$text); 
     51    $self->props->load($handle); 
     52    return; 
     53} 
    3554 
    36551; 
     
    5170  name is [% props.get('name', 'name (defaut)') %] 
    5271 
     72  # construct without file is ok 
     73  [% USE props = Properties %] 
     74  [% props.set('foo.bar' => 'baz') %] 
     75  foo.bar = [% props.get('foo.bar') %] 
     76 
    5377=head1 DESCRIPTION 
    5478 
  • Template-Plugin-Properties/trunk/t/01_properties.t

    r720 r736  
    1616foo = bar 
    1717baz = default baz 
     18 
     19--test-- 
     20[% USE props = Properties -%] 
     21[% props.set('foo.bar' => 'baz') -%] 
     22foo.bar = [% props.get('foo.bar') %] 
     23--expect-- 
     24foo.bar = baz 
     25 
     26--test-- 
     27[% USE props = Properties -%] 
     28[% text = BLOCK -%] 
     29foo.bar=baz 
     30[% END -%] 
     31[% props.parse(text) -%] 
     32foo.bar = [% props.get('foo.bar') %] 
     33--expect-- 
     34foo.bar = baz 
     35