| 1 | package DBIx::ActiveRecord::Arel; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use Storable; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Column; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Where; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Join; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Order; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Value; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Native; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use DBIx::ActiveRecord::Arel::NakidWhere; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use DBIx::ActiveRecord::Arel::SubQuery; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Query::Select; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Query::Insert; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Query::Update; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Query::Delete; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | ▶ | use DBIx::ActiveRecord::Arel::Query::Count; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 3 | ▶ | sub create { | ||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 22 | 3 | my ($self, $table_name) = @_; | |||||||||
| 23 | 3 | my $o = bless { | |||||||||
| 24 | table => $table_name, | ||||||||||
| 25 | query => undef, | ||||||||||
| 26 | }, $self; | ||||||||||
| 27 | 3 | $o->{query} = DBIx::ActiveRecord::Arel::Query::Select->new($o); | |||||||||
| 28 | 3 | $o; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 215 | ▶ | sub query {shift->{query}}; | ||||||||
|
Subroutine
query: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 32 | 212 | ▶ | sub table {shift->{table}} | ||||||||
|
Subroutine
table: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 33 | 37 | ▶ | sub binds {shift->query->binds} | ||||||||
|
Subroutine
binds: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | 39 | ▶ | sub to_sql {shift->query->to_sql} | ||||||||
|
Subroutine
to_sql: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 35 | 104 | ▶ | sub clone {Storable::dclone(shift)} | ||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | |||||||||||
| 37 | 121 | ▶ | sub _col { | ||||||||
|
Subroutine
_col: called CC=2 SCAR=6.9
| |||||||||||
| 38 | 121 | my ($self, $name) = @_; | |||||||||
| 39 | 121 | ▶ | $name = DBIx::ActiveRecord::Arel::Column->new($self, $name) if ref $name ne 'DBIx::ActiveRecord::Arel::Native'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 121 | $name; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 3 | ▶ | sub where { | ||||||||
|
Subroutine
where: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 44 | 3 | my $self = shift; | |||||||||
| 45 | 3 | my $statement = shift; | |||||||||
| 46 | 3 | my $o = $self->clone; | |||||||||
| 47 | 3 | $o->query->add_where(DBIx::ActiveRecord::Arel::NakidWhere->new($statement, \@_)); | |||||||||
| 48 | 3 | $o; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 37 | ▶ | sub _value2instance { | ||||||||
|
Subroutine
_value2instance: called CC=3 SCAR=11.0
| |||||||||||
| 52 | 37 | my ($self, $value) = @_; | |||||||||
| 53 | 37 | ▶ | return $value if ref $value eq 'DBIx::ActiveRecord::Arel::Native'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 37 | ▶ | return DBIx::ActiveRecord::Arel::SubQuery->new($value) if ref $value eq 'DBIx::ActiveRecord::Arel'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 36 | DBIx::ActiveRecord::Arel::Value->new($value); | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 37 | ▶ | sub _add_where { | ||||||||
|
Subroutine
_add_where: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 37 | my ($self, $operator, $key, $value) = @_; | |||||||||
| 60 | 37 | my $o = $self->clone; | |||||||||
| 61 | 37 | $value = $self->_value2instance($value); | |||||||||
| 62 | 37 | $o->query->add_where(DBIx::ActiveRecord::Arel::Where->new($operator, $self->_col($key), $value)); | |||||||||
| 63 | 37 | $o; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 20 | ▶ | sub eq { | ||||||||
|
Subroutine
eq: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 67 | 20 | my ($self, $key, $value) = @_; | |||||||||
| 68 | 20 | $self->_add_where('=', $key, $value); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 1 | ▶ | sub ne { | ||||||||
|
Subroutine
ne: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 72 | 1 | my ($self, $key, $value) = @_; | |||||||||
| 73 | 1 | $self->_add_where('!=', $key, $value); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 3 | ▶ | sub in { | ||||||||
|
Subroutine
in: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 77 | 3 | my ($self, $key, $value) = @_; | |||||||||
| 78 | 3 | $self->_add_where('IN', $key, $value); | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 1 | ▶ | sub not_in { | ||||||||
|
Subroutine
not_in: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 82 | 1 | my ($self, $key, $value) = @_; | |||||||||
| 83 | 1 | $self->_add_where('NOT IN', $key, $value); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 1 | ▶ | sub null { | ||||||||
|
Subroutine
null: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 87 | 1 | my ($self, $key) = @_; | |||||||||
| 88 | 1 | $self->_add_where('IS NULL', $key); | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 1 | ▶ | sub not_null { | ||||||||
|
Subroutine
not_null: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 92 | 1 | my ($self, $key) = @_; | |||||||||
| 93 | 1 | $self->_add_where('IS NOT NULL', $key); | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 1 | ▶ | sub gt { | ||||||||
|
Subroutine
gt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 97 | 1 | my ($self, $key, $value) = @_; | |||||||||
| 98 | 1 | $self->_add_where('>', $key, $value); | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 1 | ▶ | sub lt { | ||||||||
|
Subroutine
lt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 102 | 1 | my ($self, $key, $value) = @_; | |||||||||
| 103 | 1 | $self->_add_where('<', $key, $value); | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 2 | ▶ | sub ge { | ||||||||
|
Subroutine
ge: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 107 | 2 | my ($self, $key, $value) = @_; | |||||||||
| 108 | 2 | $self->_add_where('>=', $key, $value); | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | 2 | ▶ | sub le { | ||||||||
|
Subroutine
le: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 112 | 2 | my ($self, $key, $value) = @_; | |||||||||
| 113 | 2 | $self->_add_where('<=', $key, $value); | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 4 | ▶ | sub like { | ||||||||
|
Subroutine
like: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 117 | 4 | my ($self, $key, $value) = @_; | |||||||||
| 118 | 4 | $self->_add_where('LIKE', $key, $value); | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 1 | ▶ | sub contains { | ||||||||
|
Subroutine
contains: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 122 | 1 | my ($self, $key, $value) = @_; | |||||||||
| 123 | 1 | $self->like($key, "%$value%"); | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 1 | ▶ | sub starts_with { | ||||||||
|
Subroutine
starts_with: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 127 | 1 | my ($self, $key, $value) = @_; | |||||||||
| 128 | 1 | $self->like($key, "$value%"); | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 1 | ▶ | sub ends_with { | ||||||||
|
Subroutine
ends_with: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 132 | 1 | my ($self, $key, $value) = @_; | |||||||||
| 133 | 1 | $self->like($key, "%$value"); | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | 1 | ▶ | sub between { | ||||||||
|
Subroutine
between: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 137 | 1 | my ($self, $key, $value1, $value2) = @_; | |||||||||
| 138 | 1 | $self->ge($key, $value1)->le($key, $value2); | |||||||||
| 139 | } | ||||||||||
| 140 | |||||||||||
| 141 | 14 | ▶ | sub left_join { | ||||||||
|
Subroutine
left_join: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 142 | 14 | my ($self, $target, $opt) = @_; | |||||||||
| 143 | 14 | my $o = $self->clone; | |||||||||
| 144 | 14 | $o->query->merge_as($target->query); | |||||||||
| 145 | 14 | $o->query->add_join(DBIx::ActiveRecord::Arel::Join->new('LEFT JOIN', $self->_col($opt->{primary_key}), $target->_col($opt->{foreign_key}))); | |||||||||
| 146 | 14 | $o; | |||||||||
| 147 | } | ||||||||||
| 148 | |||||||||||
| 149 | 2 | ▶ | sub inner_join { | ||||||||
|
Subroutine
inner_join: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 150 | 2 | my ($self, $target, $opt) = @_; | |||||||||
| 151 | 2 | my $o = $self->clone; | |||||||||
| 152 | 2 | $o->query->merge_as($target->query); | |||||||||
| 153 | 2 | $o->query->add_join(DBIx::ActiveRecord::Arel::Join->new('INNER JOIN', $self->_col($opt->{foreign_key}), $target->_col($opt->{primary_key}))); | |||||||||
| 154 | 2 | $o; | |||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | 9 | ▶ | sub merge { | ||||||||
|
Subroutine
merge: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 158 | 9 | my ($self, $arel) = @_; | |||||||||
| 159 | 9 | my $o = $self->clone; | |||||||||
| 160 | 9 | my $s = $arel->clone; | |||||||||
| 161 | 9 | $o->query->merge($s->query); | |||||||||
| 162 | 9 | $o; | |||||||||
| 163 | } | ||||||||||
| 164 | |||||||||||
| 165 | 7 | ▶ | sub select { | ||||||||
|
Subroutine
select: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 166 | 7 | my $self = shift; | |||||||||
| 167 | 7 | my $o = $self->clone; | |||||||||
| 168 | 7 | $o->query->add_select($self->_col($_)) for @_; | |||||||||
| 169 | 7 | $o; | |||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | 1 | ▶ | sub limit { | ||||||||
|
Subroutine
limit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 173 | 1 | my ($self, $limit) = @_; | |||||||||
| 174 | 1 | my $o = $self->clone; | |||||||||
| 175 | 1 | $o->query->set_limit($limit); | |||||||||
| 176 | 1 | $o; | |||||||||
| 177 | } | ||||||||||
| 178 | |||||||||||
| 179 | 1 | ▶ | sub offset { | ||||||||
|
Subroutine
offset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 180 | 1 | my ($self, $offset) = @_; | |||||||||
| 181 | 1 | my $o = $self->clone; | |||||||||
| 182 | 1 | $o->query->set_offset($offset); | |||||||||
| 183 | 1 | $o; | |||||||||
| 184 | } | ||||||||||
| 185 | |||||||||||
| 186 | 1 | ▶ | sub lock { | ||||||||
|
Subroutine
lock: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 187 | 1 | my ($self) = @_; | |||||||||
| 188 | 1 | my $o = $self->clone; | |||||||||
| 189 | 1 | $o->query->set_lock; | |||||||||
| 190 | 1 | $o; | |||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | 5 | ▶ | sub group { | ||||||||
|
Subroutine
group: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 194 | 5 | my $self = shift; | |||||||||
| 195 | 5 | my $o = $self->clone; | |||||||||
| 196 | 5 | $o->query->add_group($o->_col($_)) for @_; | |||||||||
| 197 | 5 | $o; | |||||||||
| 198 | } | ||||||||||
| 199 | |||||||||||
| 200 | 3 | ▶ | sub asc { | ||||||||
|
Subroutine
asc: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 201 | 3 | my $self = shift; | |||||||||
| 202 | 3 | my $o = $self->clone; | |||||||||
| 203 | 3 | $o->query->add_order(DBIx::ActiveRecord::Arel::Order->new('', $self->_col($_))) for @_; | |||||||||
| 204 | 3 | $o; | |||||||||
| 205 | } | ||||||||||
| 206 | |||||||||||
| 207 | 4 | ▶ | sub desc { | ||||||||
|
Subroutine
desc: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 208 | 4 | my $self = shift; | |||||||||
| 209 | 4 | my $o = $self->clone; | |||||||||
| 210 | 4 | $o->query->add_order(DBIx::ActiveRecord::Arel::Order->new('DESC', $self->_col($_))) for @_; | |||||||||
| 211 | 4 | $o; | |||||||||
| 212 | } | ||||||||||
| 213 | |||||||||||
| 214 | 1 | ▶ | sub reorder { | ||||||||
|
Subroutine
reorder: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 215 | 1 | my $self = shift; | |||||||||
| 216 | 1 | my $o = $self->clone; | |||||||||
| 217 | 1 | $o->query->reset_order; | |||||||||
| 218 | 1 | $o; | |||||||||
| 219 | } | ||||||||||
| 220 | |||||||||||
| 221 | 0 | ▶ | sub reverse { | ||||||||
|
Subroutine
reverse: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 222 | 0 | my $self = shift; | |||||||||
| 223 | 0 | my $o = $self->clone; | |||||||||
| 224 | 0 | $o->query->reverse_order; | |||||||||
| 225 | 0 | $o; | |||||||||
| 226 | } | ||||||||||
| 227 | |||||||||||
| 228 | 3 | ▶ | sub as { | ||||||||
|
Subroutine
as: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 229 | 3 | my ($self, $alias) = @_; | |||||||||
| 230 | 3 | my $s = $self->clone; | |||||||||
| 231 | 3 | $s->query->add_as($s->table, $alias); | |||||||||
| 232 | 3 | $s; | |||||||||
| 233 | } | ||||||||||
| 234 | |||||||||||
| 235 | 1 | ▶ | sub insert { | ||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 236 | 1 | my ($self, $hash, $columns) = @_; | |||||||||
| 237 | 1 | my $o = $self->clone; | |||||||||
| 238 | 1 | $o->{query} = DBIx::ActiveRecord::Arel::Query::Insert->new($self, $hash, $columns); | |||||||||
| 239 | 1 | $o; | |||||||||
| 240 | } | ||||||||||
| 241 | |||||||||||
| 242 | 1 | ▶ | sub update { | ||||||||
|
Subroutine
update: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 243 | 1 | my ($self, $hash, $columns) = @_; | |||||||||
| 244 | 1 | my $o = $self->clone; | |||||||||
| 245 | 1 | $o->{query} = DBIx::ActiveRecord::Arel::Query::Update->new($self, $hash, $columns); | |||||||||
| 246 | 1 | $o; | |||||||||
| 247 | } | ||||||||||
| 248 | |||||||||||
| 249 | 1 | ▶ | sub delete { | ||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 250 | 1 | my ($self) = @_; | |||||||||
| 251 | 1 | my $o = $self->clone; | |||||||||
| 252 | 1 | $o->{query} = DBIx::ActiveRecord::Arel::Query::Delete->new($self); | |||||||||
| 253 | 1 | $o; | |||||||||
| 254 | } | ||||||||||
| 255 | |||||||||||
| 256 | 1 | ▶ | sub count { | ||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 257 | 1 | my ($self) = @_; | |||||||||
| 258 | 1 | my $o = $self->clone; | |||||||||
| 259 | 1 | $o->{query} = DBIx::ActiveRecord::Arel::Query::Count->new($self); | |||||||||
| 260 | 1 | $o; | |||||||||
| 261 | } | ||||||||||
| 262 | |||||||||||
| 263 | 2 | 1; | |||||||||