Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DBIx/Class/ResultSource/View.pm |
Statements | Executed 47 statements in 334µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
8 | 3 | 2 | 77µs | 292µs | new | DBIx::Class::ResultSource::View::
1 | 1 | 1 | 14µs | 16µs | BEGIN@3 | DBIx::Class::ResultSource::View::
1 | 1 | 1 | 12µs | 12µs | BEGIN@6 | DBIx::Class::ResultSource::View::
1 | 1 | 1 | 12µs | 87µs | BEGIN@8 | DBIx::Class::ResultSource::View::
1 | 1 | 1 | 7µs | 15µs | BEGIN@4 | DBIx::Class::ResultSource::View::
0 | 0 | 0 | 0s | 0s | from | DBIx::Class::ResultSource::View::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DBIx::Class::ResultSource::View; | ||||
2 | |||||
3 | 3 | 19µs | 2 | 19µs | # spent 16µs (14+2) within DBIx::Class::ResultSource::View::BEGIN@3 which was called:
# once (14µs+2µs) by Class::C3::Componentised::ensure_class_loaded at line 3 # spent 16µs making 1 call to DBIx::Class::ResultSource::View::BEGIN@3
# spent 2µs making 1 call to strict::import |
4 | 3 | 18µs | 2 | 23µs | # spent 15µs (7+8) within DBIx::Class::ResultSource::View::BEGIN@4 which was called:
# once (7µs+8µs) by Class::C3::Componentised::ensure_class_loaded at line 4 # spent 15µs making 1 call to DBIx::Class::ResultSource::View::BEGIN@4
# spent 8µs making 1 call to warnings::import |
5 | |||||
6 | 3 | 31µs | 1 | 12µs | # spent 12µs within DBIx::Class::ResultSource::View::BEGIN@6 which was called:
# once (12µs+0s) by Class::C3::Componentised::ensure_class_loaded at line 6 # spent 12µs making 1 call to DBIx::Class::ResultSource::View::BEGIN@6 |
7 | |||||
8 | 3 | 190µs | 2 | 163µs | # spent 87µs (12+76) within DBIx::Class::ResultSource::View::BEGIN@8 which was called:
# once (12µs+76µs) by Class::C3::Componentised::ensure_class_loaded at line 8 # spent 87µs making 1 call to DBIx::Class::ResultSource::View::BEGIN@8
# spent 76µs making 1 call to base::import |
9 | 1 | 6µs | 1 | 197µs | __PACKAGE__->load_components(qw/ResultSource/); # spent 197µs making 1 call to Class::C3::Componentised::load_components |
10 | 1 | 8µs | 1 | 224µs | __PACKAGE__->mk_group_accessors( # spent 224µs making 1 call to Class::Accessor::Grouped::mk_group_accessors |
11 | 'simple' => qw(is_virtual view_definition deploy_depends_on) ); | ||||
12 | |||||
13 | =head1 NAME | ||||
14 | |||||
15 | DBIx::Class::ResultSource::View - ResultSource object representing a view | ||||
16 | |||||
17 | =head1 SYNOPSIS | ||||
18 | |||||
19 | package MyApp::Schema::Result::Year2000CDs; | ||||
20 | |||||
21 | use base qw/DBIx::Class::Core/; | ||||
22 | |||||
23 | __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); | ||||
24 | |||||
25 | __PACKAGE__->table('year2000cds'); | ||||
26 | __PACKAGE__->result_source_instance->is_virtual(1); | ||||
27 | __PACKAGE__->result_source_instance->view_definition( | ||||
28 | "SELECT cdid, artist, title FROM cd WHERE year ='2000'" | ||||
29 | ); | ||||
30 | __PACKAGE__->add_columns( | ||||
31 | 'cdid' => { | ||||
32 | data_type => 'integer', | ||||
33 | is_auto_increment => 1, | ||||
34 | }, | ||||
35 | 'artist' => { | ||||
36 | data_type => 'integer', | ||||
37 | }, | ||||
38 | 'title' => { | ||||
39 | data_type => 'varchar', | ||||
40 | size => 100, | ||||
41 | }, | ||||
42 | ); | ||||
43 | |||||
44 | =head1 DESCRIPTION | ||||
45 | |||||
46 | View object that inherits from L<DBIx::Class::ResultSource> | ||||
47 | |||||
48 | This class extends ResultSource to add basic view support. | ||||
49 | |||||
50 | A view has a L</view_definition>, which contains a SQL query. The query can | ||||
51 | only have parameters if L</is_virtual> is set to true. It may contain JOINs, | ||||
52 | sub selects and any other SQL your database supports. | ||||
53 | |||||
54 | View definition SQL is deployed to your database on | ||||
55 | L<DBIx::Class::Schema/deploy> unless you set L</is_virtual> to true. | ||||
56 | |||||
57 | Deploying the view does B<not> translate it between different database | ||||
58 | syntaxes, so be careful what you write in your view SQL. | ||||
59 | |||||
60 | Virtual views (L</is_virtual> true), are assumed to not | ||||
61 | exist in your database as a real view. The L</view_definition> in this | ||||
62 | case replaces the view name in a FROM clause in a subselect. | ||||
63 | |||||
64 | =head1 EXAMPLES | ||||
65 | |||||
66 | Having created the MyApp::Schema::Year2000CDs schema as shown in the SYNOPSIS | ||||
67 | above, you can then: | ||||
68 | |||||
69 | $2000_cds = $schema->resultset('Year2000CDs') | ||||
70 | ->search() | ||||
71 | ->all(); | ||||
72 | $count = $schema->resultset('Year2000CDs') | ||||
73 | ->search() | ||||
74 | ->count(); | ||||
75 | |||||
76 | If you modified the schema to include a placeholder | ||||
77 | |||||
78 | __PACKAGE__->result_source_instance->view_definition( | ||||
79 | "SELECT cdid, artist, title FROM cd WHERE year = ?" | ||||
80 | ); | ||||
81 | |||||
82 | and ensuring you have is_virtual set to true: | ||||
83 | |||||
84 | __PACKAGE__->result_source_instance->is_virtual(1); | ||||
85 | |||||
86 | You could now say: | ||||
87 | |||||
88 | $2001_cds = $schema->resultset('Year2000CDs') | ||||
89 | ->search({}, { bind => [2001] }) | ||||
90 | ->all(); | ||||
91 | $count = $schema->resultset('Year2000CDs') | ||||
92 | ->search({}, { bind => [2001] }) | ||||
93 | ->count(); | ||||
94 | |||||
95 | =head1 SQL EXAMPLES | ||||
96 | |||||
97 | =over | ||||
98 | |||||
99 | =item is_virtual set to false | ||||
100 | |||||
101 | $schema->resultset('Year2000CDs')->all(); | ||||
102 | |||||
103 | SELECT cdid, artist, title FROM year2000cds me | ||||
104 | |||||
105 | =item is_virtual set to true | ||||
106 | |||||
107 | $schema->resultset('Year2000CDs')->all(); | ||||
108 | |||||
109 | SELECT cdid, artist, title FROM | ||||
110 | (SELECT cdid, artist, title FROM cd WHERE year ='2000') me | ||||
111 | |||||
112 | =back | ||||
113 | |||||
114 | =head1 METHODS | ||||
115 | |||||
116 | =head2 is_virtual | ||||
117 | |||||
118 | __PACKAGE__->result_source_instance->is_virtual(1); | ||||
119 | |||||
120 | Set to true for a virtual view, false or unset for a real | ||||
121 | database-based view. | ||||
122 | |||||
123 | =head2 view_definition | ||||
124 | |||||
125 | __PACKAGE__->result_source_instance->view_definition( | ||||
126 | "SELECT cdid, artist, title FROM cd WHERE year ='2000'" | ||||
127 | ); | ||||
128 | |||||
129 | An SQL query for your view. Will not be translated across database | ||||
130 | syntaxes. | ||||
131 | |||||
132 | =head2 deploy_depends_on | ||||
133 | |||||
134 | __PACKAGE__->result_source_instance->deploy_depends_on( | ||||
135 | ["MyApp::Schema::Result::Year","MyApp::Schema::Result::CD"] | ||||
136 | ); | ||||
137 | |||||
138 | Specify the views (and only the views) that this view depends on. | ||||
139 | Pass this an array reference of fully qualified result classes. | ||||
140 | |||||
141 | =head1 OVERRIDDEN METHODS | ||||
142 | |||||
143 | =head2 from | ||||
144 | |||||
145 | Returns the FROM entry for the table (i.e. the view name) | ||||
146 | or the SQL as a subselect if this is a virtual view. | ||||
147 | |||||
148 | =cut | ||||
149 | |||||
150 | sub from { | ||||
151 | my $self = shift; | ||||
152 | return \"(${\$self->view_definition})" if $self->is_virtual; | ||||
153 | return $self->name; | ||||
154 | } | ||||
155 | |||||
156 | =head1 OTHER METHODS | ||||
157 | |||||
158 | =head2 new | ||||
159 | |||||
160 | The constructor. | ||||
161 | |||||
162 | =cut | ||||
163 | |||||
164 | # spent 292µs (77+215) within DBIx::Class::ResultSource::View::new which was called 8 times, avg 36µs/call:
# 4 times (29µs+87µs) by DBIx::Class::Schema::_register_source at line 1366 of DBIx/Class/Schema.pm, avg 29µs/call
# 2 times (23µs+71µs) by DBIx::Class::ResultSourceProxy::Table::table at line 91 of DBIx/Class/ResultSourceProxy/Table.pm, avg 47µs/call
# 2 times (25µs+57µs) by DBIx::Class::Schema::clone at line 1041 of DBIx/Class/Schema.pm, avg 41µs/call | ||||
165 | 32 | 58µs | my ( $self, @args ) = @_; | ||
166 | 8 | 59µs | my $new = $self->next::method(@args); # spent 59µs making 8 calls to next::method, avg 7µs/call | ||
167 | $new->{deploy_depends_on} = | ||||
168 | { map { $_ => 1 } | ||||
169 | @{ $new->{deploy_depends_on} || [] } } | ||||
170 | unless ref $new->{deploy_depends_on} eq 'HASH'; | ||||
171 | return $new; | ||||
172 | } | ||||
173 | |||||
174 | 1 | 4µs | 1; | ||
175 | |||||
176 | =head1 AUTHORS | ||||
177 | |||||
178 | See L<DBIx::Class/CONTRIBUTORS>. | ||||
179 | |||||
180 | =head1 LICENSE | ||||
181 | |||||
182 | You may distribute this code under the same terms as Perl itself. | ||||
183 | |||||
184 | =cut | ||||
185 |