]> Dogcows Code - chaz/homebank/blob - plugins/hello.pl
Merge branch 'master' into ext-perl
[chaz/homebank] / plugins / hello.pl
1
2 # NAME: Hello World
3 # VERSION: 0.01
4 # ABSTRACT: This is the "hello world" of HomeBank plugins.
5 # AUTHOR: Charles McGarvey <chazmcgarvey@brokenzipper.com>
6 # WEBSITE: http://acme.tld/
7 # (These comments are read, before the plugin is executed, to provide some
8 # information to HomeBank and the user about what this plugin is.)
9
10 eval { HomeBank->version } or die "Cannot run outside of HomeBank";
11
12 use warnings;
13 use strict;
14
15 use Scalar::Util qw/weaken/;
16
17 #use Moose;
18
19 #has "cool_beans",
20 #is => 'rw',
21 #isa => 'Str',
22 #lazy => 1,
23 #default => "Booya!!!";
24
25
26 our $counter = 0;
27 our $temp;
28
29 my $ACC;
30
31 sub new {
32 my $class = shift;
33 my $self = $class->SUPER::new(@_);
34
35 $self->on(account_inserted => sub {
36 my $acc = shift;
37 print "account inserted: ", Dumper($acc);
38 print "account name is ", $acc->name, " and balance is ", $acc->bank_balance, "\n";
39 #$acc->name("FOOOOBAR!");
40 if ($acc->name eq 'Vacation') {
41 $acc->remove;
42 $ACC = $acc;
43 }
44 print Dumper($acc->is_inserted);
45 if ($acc->is_inserted) {
46 print "IT IS INSERTED\n";
47 } else {
48 print "not inserted\n";
49 }
50 print Dumper($acc->transactions);
51 });
52
53 #print $self->cool_beans, "\n";
54 #$self->cool_beans(123);
55 #print $self->cool_beans, "\n";
56
57 $self;
58 }
59
60 sub on_create_main_window {
61 my $self = shift;
62 my $window = shift;
63
64 if (!$window) {
65 require Gtk3;
66 $window = HomeBank->main_window;
67 }
68
69 Dump($window);
70 print Dumper($window);
71 $window->set_title("foo bar baz");
72 print $window->get_title, "\n";
73
74 HomeBank->hook("my_hook", $window);
75 }
76
77 my $test_win;
78
79 sub on_test {
80 my $self = shift;
81 require Gtk3;
82
83 my $window = Gtk3::Window->new('toplevel');
84 use Devel::Peek;
85 Dump($window);
86 print Dumper($window);
87 $window->set_title("Hello World");
88 #$window->signal_connect(delete_event => sub { Gtk3->main_quit });
89 $window->signal_connect(delete_event => sub { undef $test_win });
90
91 my $button = Gtk3::Button->new('Click Me!');
92 Dump($button);
93 print Dumper($button);
94 $button->signal_connect(clicked => sub {
95 print "Hello Gtk3-Perl: $counter (perl plugin: $self)\n";
96 $counter++;
97 #if ($temp->is_inserted) {
98 #print "$temp is inserted\n";
99 #} else {
100 #print "$temp is NOT inserted\n";
101 #}
102 #if ($counter == 5) {
103 #$temp = undef;
104 #}
105 my $acc = HomeBank::Account->get(rand(10));
106 print "Changin account named ", $acc->name, " to ", $acc->name($acc), "\n";
107 HomeBank->main_window->queue_draw;
108
109 });
110 $window->add($button);
111
112 $window->show_all;
113 $test_win = $window;
114
115 weaken $self;
116 }
117
118 sub on_enter_main_loop {
119 my $self = shift;
120
121 use Data::Dumper;
122 print Dumper(\@_);
123 my $t = HomeBank::Transaction->new;
124 print "Transaction:::::::: $t: ", $t->amount, "\n";
125
126 $temp = HomeBank::Account->get(7);
127 print "retained account: ", $temp->name, "\n";
128
129 #require Gtk3;
130 #
131 my $txn = HomeBank::Transaction->new;
132 $txn->amount(12.3456);
133 print Dumper($txn), $txn->amount, "\n";
134 #$txn->open;
135
136 my @ret = HomeBank->hook("my_hook", @_, $temp, [qw/foo bar baz/, $txn], { asf => 42, quux => \1, meh => HomeBank->main_window });
137 #my @ret = HomeBank->hook("my_hook", @_, HomeBank->main_window, {
138 #foo => 'bar', baz => 42
139 #});
140 print Dumper(\@ret);
141
142 print "adding back account...\n";
143 $ACC->name("vacation with a different name");
144 $ACC->insert;
145 HomeBank::Account->compute_balances;
146 print "account name is ", $ACC->name, " and balance is ", $ACC->balance, "\n";
147 print Dumper($ACC->transactions);
148
149 my $cloned = $ACC->clone;
150 $cloned->name("vacation copy");
151 $cloned->insert;
152 #my $asdf = $cloned->open;
153 #$asdf->set_title("this is a new friggin account");
154
155 #my $z = HomeBank::Account->get_by_name('Checking');
156 for my $xc (HomeBank::File->transactions) {
157 use DateTime;
158 my $num = $xc->date;
159 my $date = DateTime->new($xc->date)->datetime;
160 print "transaction of amount: ", $xc->amount, "\t", $xc->wording, ", ", $xc->info, ", $num, $date\n";
161 }
162
163 HomeBank::File->owner('Billy Murphy');
164 #HomeBank::File->anonymize;
165 print HomeBank::File->owner, "\n";
166
167 HomeBank::File->baz($ACC);
168 }
169
170 sub on_deep_hook_recursion {
171 my $self = shift;
172 my $level = shift;
173 print STDERR "recursion is too deep ($level)\n";
174 exit -2;
175 }
176
177 sub on_my_hook {
178 my $self = shift;
179 print "This is MY HOOK!!!!!!\n";
180 print Dumper(\@_);
181
182 print Dumper($_[2]);
183 Dump($_[2]);
184 if ($_[2]) {
185 print "meh\n";
186 }
187 if ($_[2]->isa('HomeBank::Boolean')) {
188 print "it is a home;;boolean\n";
189 }
190 if ($_[2]->isa('Types::Serialiser::Boolean')) {
191 print "it is a types serialiser thingy\n";
192 }
193 if ($_[2]->isa('HomeBank::BooleanBase')) {
194 print "it is a base bool\n";
195 }
196
197 my $win = $_[6];
198 if ($win && ref($win) eq 'HASH') {
199 my $w = $win->{meh};
200 if ($w) {
201 $w->set_title("this is MY HOOK setting a window title");
202 }
203 }
204 #print Dumper($acc);
205 #print "transferred account: ", $acc->name, "\n";
206
207 #my $fff = HomeBank::File->foo({foo => 'asdf', bar => 123456789});
208 my $fff = HomeBank::File->meh([qw/hello this is a test 82/, \1, {foo => 'bar'}, 48]);
209 print Dumper($fff);
210
211 print "my hook done\n";
212 }
213
214 sub on_unhandled {
215 my ($self, $hook) = @_;
216 warn "Unhandled hook '$hook'\n";
217 #HomeBank->warn($hook, 'Hook not handled.');
218 }
219
220 sub DESTROY {
221 my $self = shift;
222 print "DESTROYING HELLO WORLD!!!!!!\n";
223 if ($test_win) {
224 print "there is a test_win...\n";
225 }
226 $test_win->destroy if $test_win;
227 }
228
229 sub EXECUTE {
230 print "the perl plugin is being configured.....\n";
231 HomeBank->info("Hello Prefs", "YEEEEEARGGH!!!!!");
232 }
233
234 #__PACKAGE__->meta->make_immutable;
This page took 0.050801 seconds and 4 git commands to generate.