File Coverage

blib/lib/DBIx/MoCo/Column.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition 2 2 100.0
subroutine 3 3 100.0
pod 0 1 0.0
total 14 15 93.3


line stmt bran cond sub pod time code
1             package DBIx::MoCo::Column;
2 15     15   55878 use strict;
  15         27  
  15         481  
3 15     15   78 use Carp;
  15         27  
  15         1653  
4              
5             sub new {
6 46     46 0 449 my $class = shift;
7 46   100     168 my $self = shift || ''; # scalar
8 46         384 bless \$self, $class;
9             }
10              
11             1;
12              
13             =head1 NAME
14              
15             DBIx::MoCo::Column - Scalar blessed class for inflating columns.
16              
17             =head1 SYNOPSIS
18              
19             Inflate column value by using DBIx::MoCo::Column::* plugins.
20             If you set up your plugin like this,
21              
22             package DBIx::MoCo::Column::URI;
23              
24             sub URI {
25             my $self = shift;
26             return URI->new($$self);
27             }
28              
29             sub URI_as_string {
30             my $class = shift;
31             my $uri = shift or return;
32             return $uri->as_string;
33             }
34              
35             1;
36              
37             Then, you can use column_as_MyColumn method as following,
38              
39             my $e = MyEntry->retrieve(..);
40             print $e->uri; # 'http://test.com/test'
41             print $e->uri_as_URI->host; # 'test.com';
42              
43             my $uri = URI->new('http://www.test.com/test');
44             $e->uri_as_URI($uri); # set uri by using URI instance
45              
46             The name of infrate method which will be imported must be same as the package name.
47              
48             If you don't define "as string" method (such as URI_as_string),
49             scalar evaluated value of given argument will be used for new value instead.
50              
51             =head1 SEE ALSO
52              
53             L, L
54              
55             =head1 AUTHOR
56              
57             Junya Kondo, Ejkondo@hatena.comE
58              
59             =head1 COPYRIGHT AND LICENSE
60              
61             Copyright (C) Hatena Inc. All Rights Reserved.
62              
63             This library is free software; you may redistribute it and/or modify
64             it under the same terms as Perl itself.
65              
66             =cut