summaryrefslogtreecommitdiff
path: root/lib/CIL/Base.pm
diff options
context:
space:
mode:
authorFrancois Marier <francois@debian.org>2008-06-29 21:52:52 +1200
committerFrancois Marier <francois@debian.org>2008-06-29 21:53:41 +1200
commit41ec963c1aace994072b6d62b20cdce5370e0e8e (patch)
tree487b4918b4ecce530f214212271382cbb801f1b2 /lib/CIL/Base.pm
parent1893ee23dbc1f69d9dd3b03b4d28f89003762d3d (diff)
parent03a60521d41962fb3d36e8e8002e9bba51796ff6 (diff)
Merge commit 'upstream/v0.3.0'
Conflicts: bin/cil
Diffstat (limited to 'lib/CIL/Base.pm')
-rw-r--r--lib/CIL/Base.pm47
1 files changed, 43 insertions, 4 deletions
diff --git a/lib/CIL/Base.pm b/lib/CIL/Base.pm
index ed5c3a8..f9b932f 100644
--- a/lib/CIL/Base.pm
+++ b/lib/CIL/Base.pm
@@ -25,6 +25,7 @@ use strict;
use warnings;
use Carp;
use DateTime;
+use CIL::Utils;
use base qw(Class::Accessor);
__PACKAGE__->mk_accessors(qw(CreatedBy Inserted Updated));
@@ -87,6 +88,30 @@ sub new_from_fh {
return $class->new_from_data( $name, $data );
}
+sub set_data {
+ my ($self, $data) = @_;
+
+ # loop through all the allowed fields
+ my $fields = $self->fields();
+ my $array_fields = $self->array_fields();
+
+ # save each field
+ foreach my $field ( @$fields ) {
+ next unless defined $data->{$field};
+
+ # make it an array if it should be one
+ if ( exists $array_fields->{$field} and ref $data->{$field} ne 'ARRAY' ) {
+ $data->{$field} = [ $data->{$field} ];
+ }
+
+ # modify the data directly, otherwise Updated will kick in
+ $self->set_no_update($field, $data->{$field});
+ }
+ $self->set_no_update('Changed', 1);
+
+ $self->{data} = $data;
+}
+
sub save {
my ($self, $cil) = @_;
@@ -96,12 +121,18 @@ sub save {
CIL::Utils->write_cil_file( $filename, $self->{data}, @$fields );
}
+sub as_output {
+ my ($self) = @_;
+ my $fields = $self->fields();
+ return CIL::Utils->format_data_as_output( $self->{data}, @$fields );
+}
+
sub create_filename {
my ($class, $cil, $name) = @_;
# create the filename from it's parts
my $prefix = $class->prefix();
- my $issue_dir = $cil->issue_dir;
+ my $issue_dir = $cil->IssueDir;
my $filename = "${issue_dir}/${prefix}_${name}.cil";
return $filename;
@@ -125,7 +156,7 @@ sub set {
# finish if both are defined and they're the same
if ( defined $orig and defined $value ) {
- return if eval { $orig eq $value };
+ return if $orig eq $value;
}
# finish if neither are defined
@@ -147,7 +178,7 @@ sub set_no_update {
sub set_inserted_now {
my ($self) = @_;
- my $time = DateTime->now;
+ my $time = DateTime->now->iso8601;
$self->{data}{Inserted} = $time;
$self->{data}{Updated} = $time;
$self->{Changed} = 1;
@@ -155,7 +186,7 @@ sub set_inserted_now {
sub set_updated_now {
my ($self) = @_;
- my $time = DateTime->now;
+ my $time = DateTime->now->iso8601;
$self->{data}{Updated} = $time;
$self->{Changed} = 1;
}
@@ -184,6 +215,14 @@ sub name {
return $self->{name};
}
+sub errors {
+ my $self = shift;
+ if( @_ ) {
+ $self->{errors} = $_[0];
+ }
+ return $self->{errors};
+}
+
## ----------------------------------------------------------------------------
1;
## ----------------------------------------------------------------------------