File Coverage

blib/lib/Data/Tersify/Plugin/DBIx/Class.pm
Criterion Covered Total %
statement 14 14 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 24 25 96.0


line stmt bran cond sub pod time code
1             package Data::Tersify::Plugin::DBIx::Class;
2              
3 2     2   11085 use strict;
  2         5  
  2         61  
4 2     2   20 use warnings;
  2         5  
  2         52  
5              
6 2     2   1891 use DateTime;
  2         983793  
  2         419  
7              
8             our $VERSION = '1.001';
9             $VERSION = eval $VERSION;
10              
11             =head1 NAME
12              
13             Data::Tersify::Plugin::DBIx::Class - tersify DBIx::Class objects
14              
15             =head1 VERSION
16              
17             This is version 1.001.
18              
19             =head1 SYNOPSIS
20              
21             In e.g. the perl debugger
22              
23             DB<1> use Data::Tersify;
24             DB<2> my $dbic_row = $schema->resultset(...)->find(...);
25             DB<3> x Data::Tersify::tersify($dbic_row)
26              
27             produces something like
28              
29             0 Data::Tersify::Summary::...::TableName (0xdeadbeef)=HASH(0xcafebabe)
30             '_column_data' => HASH(0x1b32ca80)
31             'date_created' => '2020-03-04 20:19:47'
32             'id' => 558
33             'status' => 'active'
34             '_in_storage' => 1
35             '_inflated_column' => HASH(0x1b318618)
36             empty hash
37             '_result_source' => Data::Tersify::Summary=SCALAR(0xbeefdead)
38             -> 'DBIx::Class::ResultSource::Table (0xbabecafe) table_name'
39             'related_resultsets' => HASH(0x7235e68)
40             'related_table' => Data::Tersify::Summary=SCALAR(0x12345678)
41             -> 'DBIx::Class::ResultSet (0x9abcdef0) ...::RelatedTable'
42              
43             rather than screenfuls of stuff you don't care about.
44              
45             If you delve into the guts of the result sources or result sets, you'll get
46             more chatty stuff, but it'll still be limited to amounts that the human brain
47             can deal with.
48              
49             =head1 DESCRIPTION
50              
51             This class provides terse description for various types of DBIx::Class
52             objects, when used with L<Data::Tersify>.
53              
54             =head2 handles
55              
56             It handles DBIx::Class::ResultSource::Table, DBIx::Class::ResultSource::View
57             and DBIx::Class::ResultSet objects. Surprisingly, that appears to be enough.
58              
59             =cut
60              
61             sub handles {
62             (
63 1     1 1 2807 'DBIx::Class::ResultSource::Table',
64             'DBIx::Class::ResultSource::View',
65             'DBIx::Class::ResultSet'
66             );
67             }
68              
69             =head2 tersify
70              
71             It tersifies DBIx::Class::ResultSource::Table or
72             DBIx::Class::ResultSource::View objects into just the name of
73             the table or view respectively.
74              
75             It tersifies DBIx::Class::ResultSet into the name of the result class.
76              
77             This tends to be the source of the vast majority of the unwanted chaff that
78             fills your screen.
79              
80             =cut
81              
82             sub tersify {
83 3     3 1 5549 my ($self, $dbic_object) = @_;
84              
85 3 100       21 if (ref($dbic_object) =~ /^ DBIx::Class::ResultSource /x) {
    50          
86 2         28 return $dbic_object->{name};
87             } elsif (ref($dbic_object) eq 'DBIx::Class::ResultSet') {
88 1         5 return $dbic_object->{_result_class};
89             }
90             }
91              
92             1;
93