line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Widget::WithResultSet; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Catalyst::Plugin::Widget::WithResultSet - Widget having DBIx::ResultSet |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
3681
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
10
|
1
|
|
|
1
|
|
516
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
requires 'context'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package MyApp::Widget::Sample; |
19
|
|
|
|
|
|
|
use Moose; |
20
|
|
|
|
|
|
|
extends 'Catalyst::Plugin::Widget::Base'; |
21
|
|
|
|
|
|
|
with 'Catalyst::Plugin::Widget::WithResultSet'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has '+rs' => ( is => 'rw', default => 'Schema::User' ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 rs |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
L<DBIx::Class::ResultSet> instance or string shortcut for |
33
|
|
|
|
|
|
|
L<Catalyst-Model-DBIC-Schema>. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
subtype __PACKAGE__ . '::DBIx::Class::ResultSet' |
38
|
|
|
|
|
|
|
=> as 'Object' |
39
|
|
|
|
|
|
|
=> where { $_->isa('DBIx::Class::ResultSet') } |
40
|
|
|
|
|
|
|
; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has rs => ( is => 'rw', isa => __PACKAGE__ . '::DBIx::Class::ResultSet | Str', |
43
|
|
|
|
|
|
|
required => 1 ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 order_by |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Default ordering for 'resultset' (if any specified). |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has order_by => ( is => 'rw', isa => 'Str | Undef' ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 resultset |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
L<DBIx::Class::ResultSet> instance. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has resultset => ( is => 'rw', isa => __PACKAGE__ . '::DBIx::Class::ResultSet', |
62
|
|
|
|
|
|
|
init_arg => undef, lazy => 1, builder => '_resultset' ); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# builder for 'resultset'. |
65
|
|
|
|
|
|
|
sub _resultset { |
66
|
|
|
|
|
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $rs = ref $self->rs ? |
69
|
|
|
|
|
|
|
$self->rs : $self->context->model( $self->rs ) or |
70
|
|
|
|
|
|
|
croak "No such resultset: '" . $self->rs ."'"; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$rs = $rs->search( undef, { order_by => $self->order_by } ) |
73
|
|
|
|
|
|
|
if $self->order_by && ! $rs->is_ordered; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $rs; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|