[Dbix-class] Fw: Namespaces for own components
Daisuke Murase
typester at cpan.org
Thu Mar 2 11:38:54 CET 2006
Matt S Trout <dbix-class at trout.me.uk> wrote:
> I'd probably say Plugin::*, but it's really a matter of taste.
>
> One thing I'd politely ask is could you ask me for svn hosting in the bast
> repo if you want to develop a DBIC add-on - keeping them all in one place
> means we can better keep track of them, and means if I want to change something
> I believe isn't being used externally I can do a quick recursive grep to
> check I'm not going to screw anybody over.
Well I'd just wrote DBIx::Class::UTF8Columns that I needed.
That module forces utf8 flag on column data when get_column().
package Artist;
__PACKAGE__->load_components(qw/UTF8Columns Core/);
__PACKAGE__->utf8_columns(qw/name description/);
# then belows return strings with utf8 flag
$artist->name;
$artist->get_column('description');
Is there other better way to do this ?
Regards.
--
Daisuke Murase <typester at cpan.org>
-------------- next part --------------
package DBIx::Class::UTF8Columns;
use strict;
use warnings;
use base qw/DBIx::Class/;
use Encode;
__PACKAGE__->mk_classdata( force_utf8_columns => [] );
our $VERSION = '0.01';
=head1 NAME
DBIx::Class::UTF8Columns - Force UTF8 (Unicode) flag on columns
=head1 SYNOPSIS
package Artist;
__PACKAGE__->load_components(qw/UTF8Columns Core/);
__PACKAGE__->utf8_columns(qw/name description/);
# then belows return strings with utf8 flag
$artist->name;
$artist->get_column('description');
=head1 DESCRIPTION
This module allows you to get columns data that have utf8 (Unicode) flag.
=head1 SEE ALSO
L<Template::Stash::ForceUTF8>
=head1 METHODS
=head2 utf8_columns
=cut
sub utf8_columns {
my $self = shift;
for (@_) {
$self->throw_exception("column $_ doesn't exist")
unless $self->has_column($_);
}
$self->force_utf8_columns( \@_ );
}
=head1 EXTENDED METHODS
=head2 get_column
=cut
sub get_column {
my ( $self, $column ) = @_;
my $column_data = $self->next::method($column);
if ( { map { $_ => 1 } @{ $self->force_utf8_columns } }->{$column} ) {
Encode::_utf8_on($column_data) unless Encode::is_utf8($column_data);
}
return $column_data;
}
=head1 AUTHOR
Daisuke Murase E<lt>typester at cpan.orgE<gt>
=head1 COPYRIGHT
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=cut
1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060302/b9c5e235/attachment.pgp
More information about the Dbix-class
mailing list