| 1 | package DBIx::Class::ForceUTF8; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw/$VERSION/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | $VERSION = '0.0.2'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use base qw/DBIx::Class/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # Perl 5.8.0 doesn't have utf8::is_utf8() | ||||||||||||||||||||||||||||
| 12 | # Yes, 5.8.0 support for Unicode is suboptimal, but things like RHEL3 ship with it. | ||||||||||||||||||||||||||||
| 13 | 1 | ▶ | if ($] <= 5.008000) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 0 | require Encode; | |||||||||||||||||||||||||||
| 15 | } else { | ||||||||||||||||||||||||||||
| 16 | 1 | require utf8; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | DBIx::Class::ForceUTF8 - Force UTF8 (Unicode) flag on columns | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | package Artist; | ||||||||||||||||||||||||||||
| 27 | __PACKAGE__->load_components(qw/ForceUTF8 Core/); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # then belows return strings with utf8 flag | ||||||||||||||||||||||||||||
| 30 | $artist->name; | ||||||||||||||||||||||||||||
| 31 | $artist->get_column('description'); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # with DBIx::Class::Schema::Loader | ||||||||||||||||||||||||||||
| 34 | package My::Schema; | ||||||||||||||||||||||||||||
| 35 | use base qw/DBIx::Class::Schema::Loader/; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | __PACKAGE__->loader_options( | ||||||||||||||||||||||||||||
| 38 | components => [qw/ForceUTF8/], | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | DBIx::Class::ForceUTF8 allows you to get columns data that have Unicode flag without specifying a column name. | ||||||||||||||||||||||||||||
| 45 | Best used with DBIx::Class::Schema::Loader. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | L<DBIx::Class::Schema::Loader>, L<DBIx::Class::UTF8Columns>. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head1 EXTENDED METHODS | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head2 get_column | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub get_column { | ||||||||||||||||||||||||||
|
Subroutine
get_column: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | my ( $self, $column ) = @_; | |||||||||||||||||||||||||||
| 59 | 0 | my $value = $self->next::method($column); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( defined $value and !ref $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and not ref $value
MC/DC0%0/2
defined $value and not ref $value
defined $value
not ref $value
Truth table0%0/3
A and not(B)
A= defined $valueB= not ref $value
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($] <= 5.008000) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | Encode::_utf8_on($value) unless Encode::is_utf8($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | utf8::decode($value) unless utf8::is_utf8($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | $value; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head2 get_columns | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub get_columns { | ||||||||||||||||||||||||||
|
Subroutine
get_columns: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 0 | my %data = $self->next::method(@_); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | foreach my $col ( grep { !ref $data{$_} } keys %data ) { | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($] <= 5.008000) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | Encode::_utf8_on($data{$col}) unless Encode::is_utf8($data{$col}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | utf8::decode($data{$col}) unless utf8::is_utf8($data{$col}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | %data; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head2 store_column | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub store_column { | ||||||||||||||||||||||||||
|
Subroutine
store_column: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | my ( $self, $column, $value ) = @_; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( defined $value and !ref $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and not ref $value
MC/DC0%0/2
defined $value and not ref $value
defined $value
not ref $value
Truth table0%0/3
A and not(B)
A= defined $valueB= not ref $value
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($] <= 5.008000) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | Encode::_utf8_off($value) if Encode::is_utf8($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | } else { | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | utf8::encode($value) if utf8::is_utf8($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | $self->next::method( $column, $value ); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | Takahiro Horikawa <horikawa.takahiro@gmail.com> | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||
| 118 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | The full text of the license can be found in the | ||||||||||||||||||||||||||||
| 121 | LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 1 | 1; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||