package t::lib::My::Shopping;
use Moose;

with qw(XML::Writer::Compiler::AutoPackage);

use Data::Dumper;
use HTML::Element::Library;

use XML::Element;

has 'data' => (
    is      => 'rw',
    trigger => \&maybe_morph
);
has 'writer' => ( is => 'rw', isa => 'XML::Writer' );
has 'string' => ( is => 'rw', isa => 'XML::Writer::String' );

sub tagshopping {
    my ($self) = @_;

    my $root = $self->data;

    my $elementdata = $self->DIVE( $root, qw(shopping) );

    my ( $attr, $data ) = $self->EXTRACT($elementdata);
    $self->writer->startTag( shopping => @$attr );

    $self->tagitem;
    $self->writer->endTag;
}

sub tagitem {
    my ($self) = @_;

    my $root = $self->data;

    my $elementdata = $self->DIVE( $root, qw(shopping item) );

    my ( $attr, $data ) = $self->EXTRACT($elementdata);
    $self->writer->startTag( item => @$attr );

    $self->writer->characters($data);
    $self->writer->endTag;
}

sub xml {
    my ($self) = @_;
    my $method = 'tagshopping';
    $self->$method;
    $self->writer->end;
    $self;
}

sub tree {
    my $self = shift;
    my $href = shift;
    XML::Element->new_from_lol( $self->lol );
}

1;
