Bootylicious
view release on metacpan or search on metacpan
lib/Bootylicious/Document.pm view on Meta::CPAN
sub _group {
my $self = shift;
my $group = shift;
my $method = shift;
if (@_) {
$self->{$group}->{$method} = $_[0];
return $self;
}
return $method ? $self->{$group}->{$method} : $self->{$group}
if exists $self->{$group};
my $group_loader = "${group}_loader";
$self->{$group} = $self->$group_loader->load;
return $method ? $self->{$group}->{$method} : $self->{$group};
}
sub is_modified {
my $self = shift;
return $self->created != $self->modified;
}
sub create {
my $self = shift;
my $path = shift;
my $hash = shift;
if ($hash && ref $hash eq 'HASH') {
foreach my $key (keys %$hash) {
$self->$key($hash->{$key});
}
$path .= '/'.
Bootylicious::Timestamp->new(epoch => time)->timestamp . '-'
. $self->name . '.'
. $self->format;
}
open my $file, '>:encoding(UTF-8)', $path or return;
$self->path($path);
my $metadata = '';
foreach my $key (sort keys %{$self->metadata}) {
my $value = $self->metadata->{$key};
next unless $value && $value ne '';
$metadata .= ucfirst $key . ': ' . $value;
$metadata .= "\n";
}
print $file $metadata;
print $file "\n";
print $file $self->content || '';
return $self;
}
sub update {
my $self = shift;
my $hash = shift;
$hash ||= {};
foreach my $key (keys %$hash) {
$self->$key($hash->{$key});
}
return $self->create($self->path);
}
sub delete {
my $self = shift;
unlink $self->path;
}
1;
( run in 0.983 second using v1.01-cache-2.11-cpan-df04353d9ac )