Skip to content

Commit

Permalink
NativeTraits依存をやめる
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyoh committed Oct 27, 2010
1 parent 07a2b64 commit d0dc1c9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
44 changes: 28 additions & 16 deletions lib/Text/MTFormatBuilder/Entry.pm
Expand Up @@ -26,29 +26,13 @@ has metadata => (
has comment => (
is => 'rw',
isa => 'ArrayRef[Text::MTFormatBuilder::Comment]',
traits => ['Array'],
default => sub { [] },
handles => {
append_comment => 'push',
map_comments => 'map',
count_comments => 'count',
has_comment => 'count',
has_no_comments => 'is_empty',
},
);

has ping => (
is => 'rw',
isa => 'ArrayRef[Text::MTFormatBuilder::Ping]',
traits => ['Array'],
default => sub { [] },
handles => {
append_ping => 'push',
map_pings => 'map',
count_pings => 'count',
has_ping => 'count',
has_no_pings => 'is_empty',
},
);

no Any::Moose;
Expand All @@ -58,6 +42,34 @@ sub BUILD {
$self->metadata(Text::MTFormatBuilder::MetaData->new);
}

sub append_comment {
my $self = shift;
my $c = shift or die;
my @cs = @{ $self->comment };
push @cs, $c;
$self->comment(\@cs);
}

sub map_comments {
my $self = shift;
my $block = shift;
return map { $block->() } @{ $self->comment };
}

sub append_ping {
my $self = shift;
my $p = shift or die;
my @ps = @{ $self->ping };
push @ps, $p;
$self->ping(\@ps);
}

sub map_pings {
my $self = shift;
my $block = shift;
return map { $block->() } @{ $self->ping };
}

sub export {
my $self = shift;
my $text = '';
Expand Down
26 changes: 16 additions & 10 deletions lib/Text/MTFormatBuilder/MetaData.pm
Expand Up @@ -13,21 +13,27 @@ has [@booleans] => ( is => 'rw', isa => 'Bool', default => 1 );
has '+convert_breaks' => default => sub { 0 };
has '+content' => default => sub { 1 };

# no_entry

has category => (
traits => ['Array'],
is => 'ro',
is => 'rw',
isa => 'ArrayRef[Str]',
default => sub { [] },
handles => {
append_category => 'push',
map_categories => 'map',
count_categories => 'count',
has_category => 'count',
has_no_categories => 'is_empty',
},
);

# no_entry
sub append_category {
my $self = shift;
my $cat = shift or die;
my @cats = @{ $self->category };
push @cats, $cat;
$self->category(\@cats);
}

sub map_categories {
my $self = shift;
my $block = shift;
return map { $block->() } @{ $self->category };
}

sub export {
my $self = shift;
Expand Down

0 comments on commit d0dc1c9

Please sign in to comment.