| 1 |
wakaba |
1.1 |
# -*- perl -*- |
| 2 |
|
|
|
| 3 |
|
|
=head1 NAME |
| 4 |
|
|
|
| 5 |
|
|
SuikaWiki::View --- SuikaWiki: View |
| 6 |
|
|
|
| 7 |
|
|
=cut |
| 8 |
|
|
|
| 9 |
|
|
package SuikaWiki::View; |
| 10 |
|
|
use strict; |
| 11 |
|
|
our $VERSION = do{my @r=(q$Revision: 1.5 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 12 |
|
|
my %template; |
| 13 |
|
|
my %definition; |
| 14 |
|
|
|
| 15 |
|
|
use overload '""' => \&as_string, |
| 16 |
|
|
'.=' => \&add_line; |
| 17 |
|
|
|
| 18 |
|
|
=head1 METHODS FOR TEMPLATE |
| 19 |
|
|
|
| 20 |
|
|
=over 4 |
| 21 |
|
|
|
| 22 |
|
|
=item $t = SuikaWiki::View->template ($name) |
| 23 |
|
|
|
| 24 |
|
|
Returns a view template object |
| 25 |
|
|
|
| 26 |
|
|
=cut |
| 27 |
|
|
|
| 28 |
|
|
sub template ($$) { |
| 29 |
|
|
my $self = bless {type => 'template'}, shift; |
| 30 |
|
|
$self->{name} = shift; |
| 31 |
|
|
$self; |
| 32 |
|
|
} |
| 33 |
|
|
|
| 34 |
|
|
sub definition ($$;\%) { |
| 35 |
|
|
my $self = bless {type => 'definition'}, shift; |
| 36 |
|
|
$self->{name} = shift; |
| 37 |
|
|
my $p = shift; |
| 38 |
|
|
$definition{$self->{name}} = $p if ref $p; |
| 39 |
|
|
$self; |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
|
|
sub add_line ($$) { |
| 43 |
|
|
my $self = shift; |
| 44 |
|
|
if ($self->{type} eq 'template') { |
| 45 |
|
|
$template{$self->{name}} .= shift;; |
| 46 |
|
|
} else { |
| 47 |
|
|
$definition{$self->{name}}->{template} .= shift; |
| 48 |
|
|
} |
| 49 |
|
|
$self; |
| 50 |
|
|
} |
| 51 |
|
|
|
| 52 |
|
|
sub as_string ($) { |
| 53 |
|
|
my $self = shift; |
| 54 |
|
|
if ($self->{type} eq 'template') { |
| 55 |
|
|
$template{$self->{name}}; |
| 56 |
|
|
} else { |
| 57 |
|
|
$definition{$self->{name}}->{template}; |
| 58 |
|
|
} |
| 59 |
|
|
} |
| 60 |
|
|
|
| 61 |
|
|
sub properties ($;\%) { |
| 62 |
|
|
my ($self, $new) = @_; |
| 63 |
|
|
if (ref $new) { |
| 64 |
|
|
$definition{$self->{name}} = $new; |
| 65 |
|
|
} elsif (!ref $definition{$self->{name}}) { |
| 66 |
|
|
$definition{$self->{name}} = {}; |
| 67 |
|
|
} |
| 68 |
|
|
$definition{$self->{name}}; |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
|
sub defined ($) { |
| 72 |
|
|
my $self = shift; |
| 73 |
|
|
ref $definition{$self->{name}} && ref $definition{$self->{name}}->{media}; |
| 74 |
|
|
} |
| 75 |
|
|
sub check ($\%) { |
| 76 |
|
|
my $self = shift; |
| 77 |
|
|
ref $definition{$self->{name}}->{check} ? |
| 78 |
|
|
&{$definition{$self->{name}}->{check}} (shift) |
| 79 |
|
|
: |
| 80 |
|
|
$self->defined |
| 81 |
|
|
; |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
|
|
sub definitions ($) { |
| 85 |
|
|
return keys %definition; |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
|
|
=back |
| 89 |
|
|
|
| 90 |
|
|
=head1 LICENSE |
| 91 |
|
|
|
| 92 |
|
|
Copyright 2003 Wakaba <w@suika.fam.cx> |
| 93 |
|
|
|
| 94 |
|
|
This program is free software; you can redistribute it and/or |
| 95 |
|
|
modify it under the same terms as Perl itself. |
| 96 |
|
|
|
| 97 |
|
|
=cut |
| 98 |
|
|
|
| 99 |
|
|
1; # $Date: $ |