Profile of SQL/Translator/Schema/View.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:38 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/SQL/Translator/Schema/View.pm
Statements | Executed 111 statements in 675µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
2 | 1 | 1 | 36µs | 102µs | SQL::Translator::Schema::View::::fieldsSQL::Translator::Schema::View::fields
4 | 2 | 1 | 18µs | 22µs | SQL::Translator::Schema::View::::orderSQL::Translator::Schema::View::order
1 | 1 | 1 | 17µs | 20µs | SQL::Translator::Schema::View::::BEGIN@44SQL::Translator::Schema::View::BEGIN@44
6 | 3 | 3 | 13µs | 13µs | SQL::Translator::Schema::View::::nameSQL::Translator::Schema::View::name
4 | 2 | 2 | 13µs | 13µs | SQL::Translator::Schema::View::::sqlSQL::Translator::Schema::View::sql
2 | 1 | 1 | 11µs | 12µs | SQL::Translator::Schema::View::::schemaSQL::Translator::Schema::View::schema
1 | 1 | 1 | 8µs | 34µs | SQL::Translator::Schema::View::::BEGIN@45SQL::Translator::Schema::View::BEGIN@45
1 | 1 | 1 | 7µs | 70µs | SQL::Translator::Schema::View::::BEGIN@47SQL::Translator::Schema::View::BEGIN@47
1 | 1 | 1 | 6µs | 44µs | SQL::Translator::Schema::View::::BEGIN@49SQL::Translator::Schema::View::BEGIN@49
2 | 1 | 1 | 3µs | 3µs | SQL::Translator::Schema::View::::CORE:matchSQL::Translator::Schema::View::CORE:match (opcode)
0 | 0 | 0 | 0s | 0s | SQL::Translator::Schema::View::::DESTROYSQL::Translator::Schema::View::DESTROY
0 | 0 | 0 | 0s | 0s | SQL::Translator::Schema::View::::equalsSQL::Translator::Schema::View::equals
0 | 0 | 0 | 0s | 0s | SQL::Translator::Schema::View::::is_validSQL::Translator::Schema::View::is_valid

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package SQL::Translator::Schema::View;
2 |  |  |  |  |
3 |  |  |  |  | # ----------------------------------------------------------------------
4 |  |  |  |  | # Copyright (C) 2002-2009 SQLFairy Authors
5 |  |  |  |  | #
6 |  |  |  |  | # This program is free software; you can redistribute it and/or
7 |  |  |  |  | # modify it under the terms of the GNU General Public License as
8 |  |  |  |  | # published by the Free Software Foundation; version 2.
9 |  |  |  |  | #
10 |  |  |  |  | # This program is distributed in the hope that it will be useful, but
11 |  |  |  |  | # WITHOUT ANY WARRANTY; without even the implied warranty of
12 |  |  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 |  |  |  |  | # General Public License for more details.
14 |  |  |  |  | #
15 |  |  |  |  | # You should have received a copy of the GNU General Public License
16 |  |  |  |  | # along with this program; if not, write to the Free Software
17 |  |  |  |  | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 |  |  |  |  | # 02111-1307 USA
19 |  |  |  |  | # -------------------------------------------------------------------
20 |  |  |  |  |
21 |  |  |  |  | =pod
22 |  |  |  |  |
23 |  |  |  |  | =head1 NAME
24 |  |  |  |  |
25 |  |  |  |  | SQL::Translator::Schema::View - SQL::Translator view object
26 |  |  |  |  |
27 |  |  |  |  | =head1 SYNOPSIS
28 |  |  |  |  |
29 |  |  |  |  | use SQL::Translator::Schema::View;
30 |  |  |  |  | my $view = SQL::Translator::Schema::View->new(
31 |  |  |  |  | name => 'foo', # name, required
32 |  |  |  |  | sql => 'select id, name from foo', # SQL for view
33 |  |  |  |  | fields => 'id, name', # field names in view
34 |  |  |  |  | );
35 |  |  |  |  |
36 |  |  |  |  | =head1 DESCRIPTION
37 |  |  |  |  |
38 |  |  |  |  | C<SQL::Translator::Schema::View> is the view object.
39 |  |  |  |  |
40 |  |  |  |  | =head1 METHODS
41 |  |  |  |  |
42 |  |  |  |  | =cut
43 |  |  |  |  |
44 | 3 | 20µs | 2 | 23µs | # spent 20µs (17+3) within SQL::Translator::Schema::View::BEGIN@44 which was called: # once (17µs+3µs) by SQL::Translator::Schema::BEGIN@52 at line 44 use strict; # spent 20µs making 1 call to SQL::Translator::Schema::View::BEGIN@44 # spent 3µs making 1 call to strict::import
45 | 3 | 20µs | 2 | 60µs | # spent 34µs (8+26) within SQL::Translator::Schema::View::BEGIN@45 which was called: # once (8µs+26µs) by SQL::Translator::Schema::BEGIN@52 at line 45 use SQL::Translator::Utils 'parse_list_arg'; # spent 34µs making 1 call to SQL::Translator::Schema::View::BEGIN@45 # spent 26µs making 1 call to Exporter::import
46 |  |  |  |  |
47 | 3 | 24µs | 2 | 134µs | # spent 70µs (7+63) within SQL::Translator::Schema::View::BEGIN@47 which was called: # once (7µs+63µs) by SQL::Translator::Schema::BEGIN@52 at line 47 use base 'SQL::Translator::Schema::Object'; # spent 70µs making 1 call to SQL::Translator::Schema::View::BEGIN@47 # spent 63µs making 1 call to base::import
48 |  |  |  |  |
49 | 3 | 484µs | 2 | 81µs | # spent 44µs (6+37) within SQL::Translator::Schema::View::BEGIN@49 which was called: # once (6µs+37µs) by SQL::Translator::Schema::BEGIN@52 at line 49 use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT); # spent 44µs making 1 call to SQL::Translator::Schema::View::BEGIN@49 # spent 37µs making 1 call to vars::import
50 |  |  |  |  |
51 | 1 | 700ns |  |  | $VERSION = '1.59';
52 |  |  |  |  |
53 |  |  |  |  | # ----------------------------------------------------------------------
54 |  |  |  |  |
55 | 1 | 5µs | 1 | 39µs | __PACKAGE__->_attributes( qw/ # spent 39µs making 1 call to SQL::Translator::Schema::Object::_attributes
56 |  |  |  |  | name sql fields schema order
57 |  |  |  |  | /);
58 |  |  |  |  |
59 |  |  |  |  | =pod
60 |  |  |  |  |
61 |  |  |  |  | =head2 new
62 |  |  |  |  |
63 |  |  |  |  | Object constructor.
64 |  |  |  |  |
65 |  |  |  |  | my $view = SQL::Translator::Schema::View->new;
66 |  |  |  |  |
67 |  |  |  |  | =cut
68 |  |  |  |  |
69 |  |  |  |  | # ----------------------------------------------------------------------
70 |  |  |  |  | # spent 102µs (36+65) within SQL::Translator::Schema::View::fields which was called 2 times, avg 51µs/call: # 2 times (36µs+65µs) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 51µs/call sub fields {
71 |  |  |  |  |
72 |  |  |  |  | =pod
73 |  |  |  |  |
74 |  |  |  |  | =head2 fields
75 |  |  |  |  |
76 |  |  |  |  | Gets and set the fields the constraint is on. Accepts a string, list or
77 |  |  |  |  | arrayref; returns an array or array reference. Will unique the field
78 |  |  |  |  | names and keep them in order by the first occurrence of a field name.
79 |  |  |  |  |
80 |  |  |  |  | $view->fields('id');
81 |  |  |  |  | $view->fields('id', 'name');
82 |  |  |  |  | $view->fields( 'id, name' );
83 |  |  |  |  | $view->fields( [ 'id', 'name' ] );
84 |  |  |  |  | $view->fields( qw[ id name ] );
85 |  |  |  |  |
86 |  |  |  |  | my @fields = $view->fields;
87 |  |  |  |  |
88 |  |  |  |  | =cut
89 |  |  |  |  |
90 | 44 | 36µs |  |  | my $self = shift;
91 |  |  | 2 | 66µs | my $fields = parse_list_arg( @_ ); # spent 66µs making 2 calls to SQL::Translator::Utils::parse_list_arg, avg 33µs/call
92 |  |  |  |  |
93 |  |  |  |  | if ( @$fields ) {
94 |  |  |  |  | my ( %unique, @unique );
95 |  |  |  |  | for my $f ( @$fields ) {
96 |  |  |  |  | next if $unique{ $f };
97 |  |  |  |  | $unique{ $f } = 1;
98 |  |  |  |  | push @unique, $f;
99 |  |  |  |  | }
100 |  |  |  |  |
101 |  |  |  |  | $self->{'fields'} = \@unique;
102 |  |  |  |  | }
103 |  |  |  |  |
104 |  |  |  |  | return wantarray ? @{ $self->{'fields'} || [] } : ($self->{'fields'} || '');
105 |  |  |  |  | }
106 |  |  |  |  |
107 |  |  |  |  | # ----------------------------------------------------------------------
108 |  |  |  |  | sub is_valid {
109 |  |  |  |  |
110 |  |  |  |  | =pod
111 |  |  |  |  |
112 |  |  |  |  | =head2 is_valid
113 |  |  |  |  |
114 |  |  |  |  | Determine whether the view is valid or not.
115 |  |  |  |  |
116 |  |  |  |  | my $ok = $view->is_valid;
117 |  |  |  |  |
118 |  |  |  |  | =cut
119 |  |  |  |  |
120 |  |  |  |  | my $self = shift;
121 |  |  |  |  |
122 |  |  |  |  | return $self->error('No name') unless $self->name;
123 |  |  |  |  | return $self->error('No sql') unless $self->sql;
124 |  |  |  |  |
125 |  |  |  |  | return 1;
126 |  |  |  |  | }
127 |  |  |  |  |
128 |  |  |  |  | # ----------------------------------------------------------------------
129 |  |  |  |  | # spent 13µs within SQL::Translator::Schema::View::name which was called 6 times, avg 2µs/call: # 2 times (5µs+0s) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 3µs/call # 2 times (5µs+0s) by SQL::Translator::Producer::SQLite::create_view at line 135 of SQL/Translator/Producer/SQLite.pm, avg 2µs/call # 2 times (3µs+0s) by SQL::Translator::Schema::add_view at line 424 of SQL/Translator/Schema.pm, avg 2µs/call sub name {
130 |  |  |  |  |
131 |  |  |  |  | =pod
132 |  |  |  |  |
133 |  |  |  |  | =head2 name
134 |  |  |  |  |
135 |  |  |  |  | Get or set the view's name.
136 |  |  |  |  |
137 |  |  |  |  | my $name = $view->name('foo');
138 |  |  |  |  |
139 |  |  |  |  | =cut
140 |  |  |  |  |
141 | 18 | 21µs |  |  | my $self = shift;
142 |  |  |  |  | $self->{'name'} = shift if @_;
143 |  |  |  |  | return $self->{'name'} || '';
144 |  |  |  |  | }
145 |  |  |  |  |
146 |  |  |  |  | # ----------------------------------------------------------------------
147 |  |  |  |  | # spent 22µs (18+3) within SQL::Translator::Schema::View::order which was called 4 times, avg 5µs/call: # 2 times (13µs+3µs) by SQL::Translator::Schema::add_view at line 423 of SQL/Translator/Schema.pm, avg 8µs/call # 2 times (6µs+0s) by SQL::Translator::Schema::get_views at line 701 of SQL/Translator/Schema.pm, avg 3µs/call sub order {
148 |  |  |  |  |
149 |  |  |  |  | =pod
150 |  |  |  |  |
151 |  |  |  |  | =head2 order
152 |  |  |  |  |
153 |  |  |  |  | Get or set the view's order.
154 |  |  |  |  |
155 |  |  |  |  | my $order = $view->order(3);
156 |  |  |  |  |
157 |  |  |  |  | =cut
158 |  |  |  |  |
159 | 12 | 29µs |  |  | my ( $self, $arg ) = @_;
160 |  |  |  |  |
161 |  |  | 2 | 3µs | if ( defined $arg && $arg =~ /^\d+$/ ) { # spent 3µs making 2 calls to SQL::Translator::Schema::View::CORE:match, avg 2µs/call
162 |  |  |  |  | $self->{'order'} = $arg;
163 |  |  |  |  | }
164 |  |  |  |  |
165 |  |  |  |  | return $self->{'order'} || 0;
166 |  |  |  |  | }
167 |  |  |  |  |
168 |  |  |  |  | # ----------------------------------------------------------------------
169 |  |  |  |  | # spent 13µs within SQL::Translator::Schema::View::sql which was called 4 times, avg 3µs/call: # 2 times (8µs+0s) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 4µs/call # 2 times (5µs+0s) by SQL::Translator::Producer::SQLite::create_view at line 149 of SQL/Translator/Producer/SQLite.pm, avg 3µs/call sub sql {
170 |  |  |  |  |
171 |  |  |  |  | =pod
172 |  |  |  |  |
173 |  |  |  |  | =head2 sql
174 |  |  |  |  |
175 |  |  |  |  | Get or set the view's SQL.
176 |  |  |  |  |
177 |  |  |  |  | my $sql = $view->sql('select * from foo');
178 |  |  |  |  |
179 |  |  |  |  | =cut
180 |  |  |  |  |
181 | 12 | 18µs |  |  | my $self = shift;
182 |  |  |  |  | $self->{'sql'} = shift if @_;
183 |  |  |  |  | return $self->{'sql'} || '';
184 |  |  |  |  | }
185 |  |  |  |  |
186 |  |  |  |  | # ----------------------------------------------------------------------
187 |  |  |  |  | # spent 12µs (11+1) within SQL::Translator::Schema::View::schema which was called 2 times, avg 6µs/call: # 2 times (11µs+1µs) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 6µs/call sub schema {
188 |  |  |  |  |
189 |  |  |  |  | =pod
190 |  |  |  |  |
191 |  |  |  |  | =head2 schema
192 |  |  |  |  |
193 |  |  |  |  | Get or set the view's schema object.
194 |  |  |  |  |
195 |  |  |  |  | $view->schema( $schema );
196 |  |  |  |  | my $schema = $view->schema;
197 |  |  |  |  |
198 |  |  |  |  | =cut
199 |  |  |  |  |
200 | 10 | 14µs |  |  | my $self = shift;
201 |  |  |  |  | if ( my $arg = shift ) {
202 |  |  | 2 | 2µs | return $self->error('Not a schema object') unless # spent 2µs making 2 calls to UNIVERSAL::isa, avg 750ns/call
203 |  |  |  |  | UNIVERSAL::isa( $arg, 'SQL::Translator::Schema' );
204 |  |  |  |  | $self->{'schema'} = $arg;
205 |  |  |  |  | }
206 |  |  |  |  |
207 |  |  |  |  | return $self->{'schema'};
208 |  |  |  |  | }
209 |  |  |  |  |
210 |  |  |  |  | # ----------------------------------------------------------------------
211 |  |  |  |  | sub equals {
212 |  |  |  |  |
213 |  |  |  |  | =pod
214 |  |  |  |  |
215 |  |  |  |  | =head2 equals
216 |  |  |  |  |
217 |  |  |  |  | Determines if this view is the same as another
218 |  |  |  |  |
219 |  |  |  |  | my $isIdentical = $view1->equals( $view2 );
220 |  |  |  |  |
221 |  |  |  |  | =cut
222 |  |  |  |  |
223 |  |  |  |  | my $self = shift;
224 |  |  |  |  | my $other = shift;
225 |  |  |  |  | my $case_insensitive = shift;
226 |  |  |  |  | my $ignore_sql = shift;
227 |  |  |  |  |
228 |  |  |  |  | return 0 unless $self->SUPER::equals($other);
229 |  |  |  |  | return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name;
230 |  |  |  |  | #return 0 unless $self->is_valid eq $other->is_valid;
231 |  |  |  |  |
232 |  |  |  |  | unless ($ignore_sql) {
233 |  |  |  |  | my $selfSql = $self->sql;
234 |  |  |  |  | my $otherSql = $other->sql;
235 |  |  |  |  | # Remove comments
236 |  |  |  |  | $selfSql =~ s/--.*$//mg;
237 |  |  |  |  | $otherSql =~ s/--.*$//mg;
238 |  |  |  |  | # Collapse whitespace to space to avoid whitespace comparison issues
239 |  |  |  |  | $selfSql =~ s/\s+/ /sg;
240 |  |  |  |  | $otherSql =~ s/\s+/ /sg;
241 |  |  |  |  | return 0 unless $selfSql eq $otherSql;
242 |  |  |  |  | }
243 |  |  |  |  |
244 |  |  |  |  | my $selfFields = join(":", $self->fields);
245 |  |  |  |  | my $otherFields = join(":", $other->fields);
246 |  |  |  |  | return 0 unless $case_insensitive ? uc($selfFields) eq uc($otherFields) : $selfFields eq $otherFields;
247 |  |  |  |  | return 0 unless $self->_compare_objects(scalar $self->extra, scalar $other->extra);
248 |  |  |  |  | return 1;
249 |  |  |  |  | }
250 |  |  |  |  |
251 |  |  |  |  | # ----------------------------------------------------------------------
252 |  |  |  |  | sub DESTROY {
253 |  |  |  |  | my $self = shift;
254 |  |  |  |  | undef $self->{'schema'}; # destroy cyclical reference
255 |  |  |  |  | }
256 |  |  |  |  |
257 | 1 | 3µs |  |  | 1;
258 |  |  |  |  |
259 |  |  |  |  | # ----------------------------------------------------------------------
260 |  |  |  |  |
261 |  |  |  |  | =pod
262 |  |  |  |  |
263 |  |  |  |  | =head1 AUTHOR
264 |  |  |  |  |
265 |  |  |  |  | Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
266 |  |  |  |  |
267 |  |  |  |  | =cut
|  |  |  |  | # spent 3µs within SQL::Translator::Schema::View::CORE:match which was called 2 times, avg 2µs/call: # 2 times (3µs+0s) by SQL::Translator::Schema::View::order at line 161, avg 2µs/call sub SQL::Translator::Schema::View::CORE:match; # opcode