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.2 |
our $VERSION = do{my @r=(q$Revision: 1.1 $=~/\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 |
|
|
$template{$self->{name}}; |
57 |
|
|
} else { |
58 |
|
|
$definition{$self->{name}}->{template}; |
59 |
|
|
} |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
sub properties ($;\%) { |
63 |
|
|
my ($self, $new) = @_; |
64 |
|
|
if (ref $new) { |
65 |
|
|
$definition{$self->{name}} = $new; |
66 |
|
|
} elsif (!ref $definition{$self->{name}}) { |
67 |
|
|
$definition{$self->{name}} = {}; |
68 |
|
|
} |
69 |
|
|
$definition{$self->{name}}; |
70 |
|
|
} |
71 |
|
|
|
72 |
wakaba |
1.2 |
sub property ($$;\%) { |
73 |
|
|
my ($self, $key, $new) = @_; |
74 |
|
|
if (defined $new) { |
75 |
|
|
$definition{$self->{name}}->{$key} = $new; |
76 |
|
|
} |
77 |
|
|
$definition{$self->{name}}->{$key}; |
78 |
|
|
} |
79 |
|
|
|
80 |
wakaba |
1.1 |
sub defined ($) { |
81 |
|
|
my $self = shift; |
82 |
|
|
ref $definition{$self->{name}} && ref $definition{$self->{name}}->{media}; |
83 |
|
|
} |
84 |
|
|
sub check ($\%) { |
85 |
|
|
my $self = shift; |
86 |
|
|
ref $definition{$self->{name}}->{check} ? |
87 |
|
|
&{$definition{$self->{name}}->{check}} (shift) |
88 |
|
|
: |
89 |
|
|
$self->defined |
90 |
|
|
; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
sub definitions ($) { |
94 |
|
|
return keys %definition; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
=back |
98 |
|
|
|
99 |
|
|
=head1 LICENSE |
100 |
|
|
|
101 |
|
|
Copyright 2003 Wakaba <w@suika.fam.cx> |
102 |
|
|
|
103 |
|
|
This program is free software; you can redistribute it and/or |
104 |
|
|
modify it under the same terms as Perl itself. |
105 |
|
|
|
106 |
|
|
=cut |
107 |
|
|
|
108 |
wakaba |
1.2 |
1; # $Date: 2003/04/03 01:08:17 $ |