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