------
$dom->fill_form_fields($item);  
-------

--
## Need to cope with the loop...
## could solve with a subtemplate or dom->adopt

my $component_handler_registry = Template::Lace::ComponentHandlerRegistry->new;

$component_handler_registry
  ->add(Template::Lace::ComponentHandler::CodeRef->new(
      code=>sub { my ($self, $dom, $attrs) = @_; ... });

my $user_template_factory = Template::Lace::Factory->new(
  class=>'MyApp::Template::User',
  component_handlers=>$component_handler_registry);
    

  my $registry = Template::Lace::Registry->new(
    component_handlers

  my $template_factory = Template::Lace::Factory


  package MyApp::DisplayModel::User;

  use Moose;
  use Lace::AttributeAnnotations;
  use MyApp::Types;

  has 'name', (
    is=>'ro',
    isa=>String,
    display_html=>sub {
      my ($self, $data, $dom) = @_;
      $dom->at('#user-name', $data);
    });

  has 'friends, (
    is=>'ro',
    isa=>ArrayRef[Person],
    display_hmtl=> sub {
      my ($self, $data, $dom) = @_;
      $dom->ul('#friends, $data)
  );

# This idea will work better with binds

== How to let a compent control the init args of subcomponents

# The idea is that the sub component gets it args from
# the contaiing componet
 <lace-form errors='$.form.errors' ...>
  <input errors='$.errors.age' value='$.values.age' title='$self.title' />
 </lace-form>

Starting to lean toward something like

$dom->at('#content')
  ->content( $self->process_components( $self->content))

or mayb $self->content->process_components( ctx=>$self->formdata, ...)

might have to move the concept of compoents into Template::Lace::DOM 
to get this right. 

Ok now if we move components to the DOM we can support 
->attach

==== END

=== Form ideas
-- fill and smart_content for matching input[name= same as class and id.
  ?this maybe is overloading fill to much perhaps a ->fill_form would be
  better.
  
$dom->form('#login',
  \%attrs, sub {
    $_->ctx($self->fif, sub {
      
    },
  },
)

maybe instead some sort of MOP on forms like WWW::Mech
== END

'ul li' => Repeat {
  Fill('~', $_),
  '~@id+' => $_->id,
  '~@class' => do { $_->completed ? 'completed' : undef },
  '.update' => $self->uri('/task/update', [$_->todo_id]),
  'label' => [
    '~@data_task' => $_->todo_id,
    '~' => $_->title,
  'input[name="title"]' => $_->title,

} $self->list,

  $dom->at('label')
    ->attr('data-task', $_->todo_id)
    ->content($_->label);

  $dom->'#id'->class("completed")

====
letting a template 'reach into' a component

<Lace-Status.show>
<p>
  This is a test <info:status/>.  For More information
  click <a info:href >here</a>
</p>
</Lace-Status.show>

package MyApp::Lace::Status;

sub show {
  my ($self, $dom) = @_;
  $dom->bind('info', 
    status => $self->status,
    href => $self->uri('info'), # canonically +{ href => $self->uri('info') },
  );
}

<section id="todos">
  <lace-todos.count>
    <p>
      Hi there <person:name />! Here's you're work list!
    </p>
    <ol>
      <li data-person='todos'><todo:name/></li>
    </ol>
  </lace-todos.count>
</section>

package MyApp::Lace::Todos;

sub dispatch { 
  my ($self, $name, @args) = @_;
  return $self->display(@args) if $name eq 'count';
}

sub display {
  my ($self, $dom) = @_;
  $dom->bind('person', 
    name => $self->person->name,
    todos => sub { $self->list_todos($_) },
  );
}

sub list_todos {
  my ($self, $dom) = @_;
  $dom->repeat(sub {
    my ($dom, $todo) = @_;
    $dom->bind('todo', name => $todo->name)
  }, $self->person->todos);
}

# =================

sub process_dom {
  my ($self, $dom) = @_;
  $dom->bind('links',
    add_task => { action=>$self->uri('add') },
    clear_completed => { action=>$self->uri('clear_completed') },
    show_all => $self->build_summary_url('all'),
    show_active => $self->build_summary_url('active'),
    show_completed => $self->build_summary_url('completed'),
  )->bind('todos',
    active_count => $self->active_task_count,
    set => sub { $self->list_todos($_) },
  );
}

sub build_summary_url {
  my ($self, $set) = @_;
  return +{
    action => $self->uri('summary',{q=>$set}),
    class => $self->set eq $set ? 'selected':undef,
  };
}

sub list_todos {
  my ($self, $dom) = @_;
  $dom->repeat(sub {
    my ($dom, $todo) = @_;
    $dom->bind('todo',
      update_action => +{ action => $self->uri('/task/update', [$todo->todo_id]) },
      destroy_action => +{ action => $self->uri('/task/delete', [$todo->todo_id]) },
      display_label => $todo->title,
      title_input => sub { $_->value($todo->title) }
      task_id => +{ 'id+' => $todo->id },
      form_id => +{ 'id+' => $todo->id },
      data_id => +{ 'data-task' => $todo->id },
      completed => sub { $self->mark_completed($_) },
    );
  }, $self->todos);
}

sub mark_completed {
  my ($self, $dom) = @_;
  $dom->data('is_complete',
    'checkbox@checked' => $self->completed,
    'display_class@class' => ($todo->completed ? "completed": undef),
  );
}


=======


<section id="todos">
  <lace-todos.count>
    <p>
      Hi there <span data-person='name'>PERSON</span>! Here's you're work list!
    </p>
      <ol>    
        <li data-person='todos'>
          <span data-todo='title'>THING TODO</span>
        </li>
      </ol>
  </view-todos>
</section>

package MyApp::Lace::Todos;

sub dispatch { 
  my ($self, $name, @args) = @_;
  return $self->display(@args) if $name eq 'count';
}

sub display {
  my ($self, $dom) = @_;
  $dom->data('person', 
    name => $self->person->name,
    todos => sub { $self->list_todos($_) },
  );
}

sub list_todos {
  my ($self, $dom) = @_;
  $dom->repeat(sub {
    my ($dom, $todo) = @_;
    $dom->data('todo', name => $todo->name)
  }, $self->person->todos);
}

=======

<section id="todos">
    <p data-lace='$.info>
      Hi there <span data-person='name'>
        <a data-person@href='resumelink'>
          PERSON
        </a></span>! Here's you're work list!
    </p>
      <ol>
        <li data-lace='@.list-todos'>
          <span data-todo='title Str'>THING TODO</span>
        </li>
      </ol>
</section>

package MyApp::Lace::Todos;

sub info {
  $_{person}
    ->name($_->person->name)
    ->resumelink($_->person->resume_link);
}

sub list_todos {
  return $_->person
    ->todos
    ->map(sub {
      $_{todo}->clone
        ->title($_->title);
    });
}

---
<li class=[.listclass]>
  ...
</li>


sub listclass {
  my ($self, $li) = @_;
  return $self->completed ? 'completed : undef;
}

##===

Placeholders
<lace:person>Example</lace:person>


<ui-checkbox label=(
  <label>asdsd</label>
  ) />


---

sub template {qq[
  <ol>
    <view-todo task=$.task />
  </ol>
]}

sub process_dom {
  my ($self, $dom) = @_;
  $dom->component('view-todo')
    ->first
    ->repeat(sub {
        my ($dom, $task) = @_;
        $dom->process_component({task=>$task})
      }, $self->tasks);
}

---

sub template { '<ol></ol>' }

sub process_dom {
  my ($self, $dom) = @_;
  $dom->append_child($self->ctx->view('Todo', task=>$_)
    for @{$self->tasks};
}

----

sub template {qq[
  <ol>
    <view-todo task=@.tasks />
  </ol>
]}

sub process_dom {
  my ($self, $dom) = @_;
}


