line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RapidApp::AttributeHandlers; |
2
|
4
|
|
|
4
|
|
50
|
use RapidApp::Util qw(:all); |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
1752
|
|
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
29
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
108
|
|
5
|
4
|
|
|
4
|
|
30
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
163
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
unshift @UNIVERSAL::ISA, __PACKAGE__; |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
1919
|
use Attribute::Handlers; |
|
4
|
|
|
|
|
10484
|
|
|
4
|
|
|
|
|
21
|
|
10
|
|
|
|
|
|
|
#use strict; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Note: These handlers are ignored in DBIC classes with: |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# use base 'DBIx::Class'; |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# but do work with: |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# require base; base->import('DBIx::Class'); |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# and do work with: |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# use Moose; |
23
|
|
|
|
|
|
|
# use MooseX::NonMoose; |
24
|
|
|
|
|
|
|
# use namespace::autoclean; |
25
|
|
|
|
|
|
|
# extends 'DBIx::Class'; MooseX::NonMoose |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# This is probably a bug in DBIC. |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# See my IRC chat in #dbix-class on 2011-11-05: |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#[15:44] <vs> Attribute::Handlers with DBIC Component classes, is there a trick to get it to work properly? I want to be able to have custom attributes defined in a separate package, and then include it it with use base, or load_componenets, or anything that will actually work, and have those attributes available for setting on the subs in the DBIC class... Sub::Attribute works, but has less features than Attribute::Handlers... is there a reason it doesn't work with Attribute::Hanlders? |
32
|
|
|
|
|
|
|
#[15:45] <alnewkirk> vs, ... wtf? |
33
|
|
|
|
|
|
|
#[15:45] <vs> heh |
34
|
|
|
|
|
|
|
#[15:46] <alnewkirk> vs, DBIC already does this without any extra modules needed |
35
|
|
|
|
|
|
|
#[15:48] <vs> ok.... how/where? |
36
|
|
|
|
|
|
|
#[15:49] <vs> to clearify, I'm not talking about class accessors... I am talking about being able to define sub mysub :MyAttr { ... } and then be able to hook into the 'MyAttr' attribute |
37
|
|
|
|
|
|
|
#[15:50] <alnewkirk> vs, why? |
38
|
|
|
|
|
|
|
#[15:51] <vs> I'd like to use it for debug/introspection... but I really just want to be able t use it for any purposes that one would use attributes in any other regulat packages... |
39
|
|
|
|
|
|
|
#[15:51] <vs> just wanting to understand why it seems to be different for DBIC.. |
40
|
|
|
|
|
|
|
#[15:52] <vs> is it related to class:c3 stuff? |
41
|
|
|
|
|
|
|
#[16:04] <vs> Because it does work with MooseX::NonMoose/extends 'DBIx::Class', but does not work with use base 'DBIx::Class' ... I don't want to have to load Moose on my DBIC classes if I don't have to because of the extra overhead |
42
|
|
|
|
|
|
|
#[16:05] * siracusa (~siracusa@pool-96-233-50-4.bstnma.fios.verizon.net) has joined #dbix-class |
43
|
|
|
|
|
|
|
#[16:32] <@Caelum> vs: you need to put the ->load_components call into a BEGIN {} block |
44
|
|
|
|
|
|
|
#[16:32] <@Caelum> ner0x: the difference between has_one and belongs_to, is that belongs_to defines a foreign key on deploy |
45
|
|
|
|
|
|
|
#[16:32] <@Caelum> ner0x: so if you want a foreign key, use belongs_to |
46
|
|
|
|
|
|
|
#[16:32] <vs> Caelum: I did that |
47
|
|
|
|
|
|
|
#[16:33] <@Caelum> vs: still didn't work? |
48
|
|
|
|
|
|
|
#[16:33] <purl> Maybe you should change the code! Or your definition of "works". or like not good or nun violence never pays |
49
|
|
|
|
|
|
|
#[16:33] <vs> I tried that, and use base qw(MyAttrClass DBIx::Class) and neither work |
50
|
|
|
|
|
|
|
#[16:34] <vs> it does work with Sub::Attribute |
51
|
|
|
|
|
|
|
#[16:35] <vs> It doesn't throw errors about invalid CODE attributes, but the handle code never gets called... |
52
|
|
|
|
|
|
|
#[16:35] <@Caelum> so if you load your base class at runtime, it works, but at compile time it doesn't |
53
|
|
|
|
|
|
|
#[16:36] <vs> I can only get it to work if I put the atttribute definitions in the package directly |
54
|
|
|
|
|
|
|
#[16:36] <@Caelum> try: require base; base->import('DBIx::Class'); |
55
|
|
|
|
|
|
|
#[16:36] <@Caelum> that would be the equivalent of the Moose "extends" |
56
|
|
|
|
|
|
|
#[16:37] <vs> aha... ok, let me try that... |
57
|
|
|
|
|
|
|
#[16:38] <vs> yep, that works! |
58
|
|
|
|
|
|
|
#[16:38] <@Caelum> bonus points if you can figure out why and submit the appropriate RT tickets :) |
59
|
|
|
|
|
|
|
#[16:39] <vs> I've been beating my head against this for hours... it reminds me how much I still don't know about perl... |
60
|
|
|
|
|
|
|
#[16:41] <vs> but if I can figure it out, I'll send the feedback! |
61
|
|
|
|
|
|
|
#[16:41] <@Caelum> I think there was a MODIFY_CODE_ATTRIBUTES method in DBIx/Class.pm |
62
|
|
|
|
|
|
|
#[16:41] <@Caelum> I don't know why it's there |
63
|
|
|
|
|
|
|
#[16:42] <vs> yep, I know there is... because during some of my tests i saw messsages about it being redefined |
64
|
|
|
|
|
|
|
#[16:42] <vs> redefined by DBIx::Class.... |
65
|
|
|
|
|
|
|
#[16:42] <vs> I figured it had to be related to the c3 stuff |
66
|
|
|
|
|
|
|
#[16:43] <@Caelum> it isn't |
67
|
|
|
|
|
|
|
#[16:43] <@Caelum> ask ribasushi he probably knows |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub Debug :ATTR(CODE,BEGIN) { |
71
|
0
|
|
|
0
|
0
|
0
|
my ($package, $symbol, $referent, $attr, $data, $phase, $filename, $linenum) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
my $name = *{$symbol}{NAME}; |
|
0
|
|
|
|
|
0
|
|
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
0
|
|
|
0
|
die __PACKAGE__ . '::Debug(): invalid attribute data: "' . $data . '" - expected hash/list arguments' |
76
|
|
|
|
|
|
|
if (defined $data and ref($data) ne 'ARRAY'); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
scream_color(BOLD.CYAN,"debug_around set on: $package" . '::' . "$name at line $linenum"); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
my %opt = (pkg => $package, filename => $filename, line => $linenum); |
81
|
0
|
0
|
|
|
|
0
|
%opt = ( %opt, @$data ) if (ref($data) eq 'ARRAY'); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
return debug_around($name,%opt); |
84
|
4
|
|
|
4
|
|
638
|
} |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
26
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub nDebug :ATTR(CODE,BEGIN) { |
87
|
0
|
|
|
0
|
0
|
|
my ($package, $symbol, $referent, $attr, $data, $phase, $filename, $linenum) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $name = *{$symbol}{NAME}; |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
scream_color(BOLD.CYAN,"NOT setting debug_around on: $package" . '::' . "$name at line $linenum"); |
92
|
4
|
|
|
4
|
|
2229
|
} |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
17
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#use Sub::Attribute; |
96
|
|
|
|
|
|
|
# |
97
|
|
|
|
|
|
|
## Automatically setup 'debug_around' on methods with the 'Debug' attribute: |
98
|
|
|
|
|
|
|
#sub Debug :ATTR_SUB { |
99
|
|
|
|
|
|
|
# my ($package, $symbol, $referent, $attr, $data, $phase, $filename, $linenum) = @_; |
100
|
|
|
|
|
|
|
# |
101
|
|
|
|
|
|
|
# scream(join('', |
102
|
|
|
|
|
|
|
# ref($referent), " ", |
103
|
|
|
|
|
|
|
# *{$symbol}{NAME}, " ", |
104
|
|
|
|
|
|
|
# "($referent) ", "was just declared ", |
105
|
|
|
|
|
|
|
# "and ascribed the ${attr} attribute ", |
106
|
|
|
|
|
|
|
# "with data ($data)\n", |
107
|
|
|
|
|
|
|
# "in phase $phase\n", |
108
|
|
|
|
|
|
|
# "in file $filename at line $linenum\n" |
109
|
|
|
|
|
|
|
# )); |
110
|
|
|
|
|
|
|
# |
111
|
|
|
|
|
|
|
# |
112
|
|
|
|
|
|
|
# return debug_around(*{$symbol}{NAME}, pkg => $package, filename => $filename, line => $linenum); |
113
|
|
|
|
|
|
|
#} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |