Skip to content

Commit 7bd7e4c

Browse files
committed
For [GH #117] - Introduce $vfs_item->item_key.
* change keys for actions in `$folder->{Item}` to use `"do\0$name"`. These match to item_key.
1 parent b002169 commit 7bd7e4c

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

Lite/CGen/Perl.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ use YATT::Lite::Constants;
124124
(my MY $self, my Action $action) = @_;
125125
# XXX: 改行の調整が必要。
126126
my @src = ($self->sync_curline($action->{cf_startln})
127-
, "sub $$action{cf_name} {");
127+
, "sub do_$$action{cf_name} {");
128128
my $src = $self->{curtmpl}->source_substr
129129
($action->{cf_bodypos}, $action->{cf_bodylen});
130130

Lite/Core.pm

+11-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ use YATT::Lite::Breakpoint ();
4646
, -constants => [[public => 0]]
4747
, [Widget => -fields => [qw(tree var_dict has_required_arg)]
4848
, [Page => (), -constants => [[public => 1]]]]
49-
, [Action => (), -constants => [[public => 1]]]
49+
, [Action => (), -constants => [[public => 1],
50+
[item_category => 'do'],
51+
]]
5052
, [Data => ()]]
5153

5254
, [Template => -base => MY->File
@@ -72,18 +74,18 @@ use YATT::Lite::Breakpoint ();
7274
(my Part $part) = @_;
7375
$part->{cf_name};
7476
}
75-
sub YATT::Lite::Core::Action::public_name {
76-
(my Action $action) = @_;
77-
substr($action->{cf_name}, 3);
78-
}
7977
sub YATT::Lite::Core::Part::method_name {...}
8078
sub YATT::Lite::Core::Widget::method_name {
8179
(my Widget $widget) = @_;
8280
"render_$widget->{cf_name}";
8381
}
8482
sub YATT::Lite::Core::Action::method_name {
8583
(my Action $action) = @_;
86-
$action->{cf_name};
84+
"do_$action->{cf_name}";
85+
}
86+
sub YATT::Lite::Core::Action::item_key {
87+
(my Action $action) = @_;
88+
"do\0$action->{cf_name}";
8789
}
8890

8991
sub YATT::Lite::Core::Part::configure_folder {
@@ -356,6 +358,7 @@ sub synerror {
356358

357359
if (UNIVERSAL::isa($self->{root}, Template)) {
358360
# Special case.
361+
# XXX: Should add action tests for this case.
359362
$tmpl = $self->{root};
360363

361364
$part = $tmpl->{Item}{$partName}
@@ -387,7 +390,7 @@ sub synerror {
387390
}
388391

389392
sub _itemKey_page { shift; ($_[0], "render_$_[0]") }
390-
sub _itemKey_action { shift; ("do_$_[0]") x 2; }
393+
sub _itemKey_action { shift; ("do\0$_[0]", "do_$_[0]"); }
391394

392395
#
393396
# Action name => sub {}
@@ -403,7 +406,7 @@ sub synerror {
403406

404407
*{globref($root->{cf_entns}, $action_name)} = $sub;
405408

406-
$root->{Item}{$action_name}
409+
$root->{Item}{"do\0$name"}
407410
= $self->Action->new(name => $action_name, kind => 'action'
408411
, folder => $root
409412
, startln => $lineno

Lite/LRXML.pm

+5-12
Original file line numberDiff line numberDiff line change
@@ -552,18 +552,10 @@ sub build {
552552
, folder => $self->{template}
553553
, startpos => $self->{startpos}, @_);
554554
}
555-
# 今度はこっちが今一ね。
555+
556556
sub build_widget { shift->Widget->new(@_) }
557557
sub build_page { shift->Page->new(@_) }
558-
sub build_action {
559-
(my MY $self, my (%opts)) = @_;
560-
561-
# XXX: This is a workaround to have renderers and actions
562-
# in the same hash table $template->{Item}.
563-
$opts{name} = "do_$opts{name}";
564-
565-
$self->Action->new(%opts);
566-
}
558+
sub build_action { shift->Action->new(@_) }
567559
sub build_data { shift->Data->new(@_) }
568560

569561
#========================================
@@ -676,15 +668,16 @@ sub namespace {
676668
#========================================
677669
sub add_part {
678670
(my MY $self, my Template $tmpl, my Part $part) = @_;
679-
if (defined $tmpl->{Item}{$part->{cf_name}}) {
671+
my $itemKey = $part->item_key;
672+
if (defined $tmpl->{Item}{$itemKey}) {
680673
die $self->synerror_at($self->{startln}, q{Conflicting part name! '%s'}, $part->{cf_name});
681674
}
682675
if ($tmpl->{partlist} and my Part $prev = $tmpl->{partlist}[-1]) {
683676
$prev->{cf_endln} = $self->{endln};
684677
}
685678
$part->{cf_startln} = $self->{startln};
686679
$part->{cf_bodyln} = $self->{endln};
687-
push @{$tmpl->{partlist}}, $tmpl->{Item}{$part->{cf_name}} = $part;
680+
push @{$tmpl->{partlist}}, $tmpl->{Item}{$itemKey} = $part;
688681
}
689682

690683
sub add_text {

Lite/VFS.pm

+8-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require File::Basename;
2020
sub MY () {__PACKAGE__}
2121
use YATT::Lite::Types
2222
([Item => -fields => [qw(cf_name cf_public cf_type)]
23-
, -constants => [[can_generate_code => 0]]
23+
, -constants => [[can_generate_code => 0], [item_category => '']]
2424
, [Folder => -fields => [qw(Item cf_path cf_parent cf_base
2525
cf_entns)]
2626
, -eval => q{use YATT::Lite::Util qw(cached_in);}
@@ -32,6 +32,10 @@ require File::Basename;
3232
, -alias => 'vfs_dir']]]);
3333

3434
sub YATT::Lite::VFS::Item::after_create {}
35+
sub YATT::Lite::VFS::Item::item_key {
36+
(my Item $item) = @_;
37+
$item->{cf_name};
38+
}
3539
sub YATT::Lite::VFS::Folder::configure_parent {
3640
my MY $self = shift;
3741
# 循環参照対策
@@ -466,8 +470,9 @@ require File::Basename;
466470
(data => {}, name => $name, parent => $folder);
467471
}
468472
# XXX: path を足すと、memory 動作の時に困る
469-
$folder->{Item}{$lastName} = $vfs->create
470-
(data => $data, name => $lastName, parent => $folder);
473+
my Item $item = $vfs->create
474+
(data => $data, name => $lastName, parent => $folder);
475+
$folder->{Item}{$item->item_key} = $item;
471476
}
472477
#========================================
473478
sub root {(my VFS $vfs) = @_; $vfs->{root}}

0 commit comments

Comments
 (0)