aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/DBIx/Class/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/DBIx/Class/FixMyStreet')
-rw-r--r--perllib/DBIx/Class/FixMyStreet/EncodedColumn.pm48
-rw-r--r--perllib/DBIx/Class/FixMyStreet/InflateColumn/DateTime.pm36
2 files changed, 84 insertions, 0 deletions
diff --git a/perllib/DBIx/Class/FixMyStreet/EncodedColumn.pm b/perllib/DBIx/Class/FixMyStreet/EncodedColumn.pm
new file mode 100644
index 000000000..0d86c7639
--- /dev/null
+++ b/perllib/DBIx/Class/FixMyStreet/EncodedColumn.pm
@@ -0,0 +1,48 @@
+package DBIx::Class::FixMyStreet::EncodedColumn;
+
+use strict;
+use warnings;
+
+use base qw/DBIx::Class::EncodedColumn/;
+
+# mySociety override to allow direct setting without double encryption
+sub set_column {
+ my $self = shift;
+ return DBIx::Class::Row::set_column($self, @_) unless defined $_[1] and not defined $_[2];
+ $self->next::method(@_);
+}
+
+1;
+
+__END__;
+
+=head1 NAME
+
+DBIx::Class::FixMyStreet::EncodedColumn - Automatically encode columns
+
+=head1 SYNOPSIS
+
+The same as DBIx::Class::EncodedColumn, but adding an extra optional second
+argument to set_column to allow skipping encryption (so if we hold an
+already-hashed password, we can set it directly).
+
+In your application code:
+
+ $row->password('plaintext');
+ $row->password('hashed-password', 1);
+
+=head1 EXTENDED METHODS
+
+The following L<DBIx::Class::Row> methods are extended by this module:
+
+=over 4
+
+=item B<set_column> - Encode values whenever column is set.
+
+=back
+
+=head1 SEE ALSO
+
+L<DBIx::Class::EncodedColumn>, L<DBIx::Class>
+
+=cut
diff --git a/perllib/DBIx/Class/FixMyStreet/InflateColumn/DateTime.pm b/perllib/DBIx/Class/FixMyStreet/InflateColumn/DateTime.pm
new file mode 100644
index 000000000..f2089d5a3
--- /dev/null
+++ b/perllib/DBIx/Class/FixMyStreet/InflateColumn/DateTime.pm
@@ -0,0 +1,36 @@
+package DBIx::Class::FixMyStreet::InflateColumn::DateTime;
+
+use strict;
+use warnings;
+use base qw/DBIx::Class::InflateColumn::DateTime/;
+use FixMyStreet;
+use namespace::clean;
+
+sub _post_inflate_datetime {
+ my $self = shift;
+ my $dt = $self->next::method(@_);
+ FixMyStreet->set_time_zone($dt);
+ return $dt;
+}
+
+sub _pre_deflate_datetime {
+ my $self = shift;
+ my $dt = $self->next::method(@_);
+ $dt->set_time_zone(FixMyStreet->local_time_zone);
+ return $dt;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+DBIx::Class::FixMyStreet::InflateColumn::DateTime
+
+=head1 DESCRIPTION
+
+This acts the same as DBIx::Class::InflateColumn::DateTime, as if a
+'local' timezone object was attached to every datetime column, plus
+alters the timezone upon inflation to the configured timezone if it
+has been set, and uses a singleton to prevent needless disc access.