]> Dogcows Code - chaz/homebank/blob - plugins/hello.pl
revert whitespace fixes
[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 $window->add($button);
110
111 $window->show_all;
112 $test_win = $window;
113
114 weaken $self;
115 }
116
117 sub on_enter_main_loop {
118 my $self = shift;
119
120 use Data::Dumper;
121 print Dumper(\@_);
122 my $t = HomeBank::Transaction->new;
123 print "Transaction:::::::: $t: ", $t->amount, "\n";
124
125 $temp = HomeBank::Account->get(7);
126 print "retained account: ", $temp->name, "\n";
127
128 #require Gtk3;
129 #
130 my $txn = HomeBank::Transaction->new;
131 $txn->amount(12.3456);
132 print Dumper($txn), $txn->amount, "\n";
133 #$txn->open;
134
135 my @ret = HomeBank->hook("my_hook", @_, $temp, [qw/foo bar baz/, $txn], { asf => 42, quux => \1, meh => HomeBank->main_window });
136 #my @ret = HomeBank->hook("my_hook", @_, HomeBank->main_window, {
137 #foo => 'bar', baz => 42
138 #});
139 print Dumper(\@ret);
140
141 print "adding back account...\n";
142 $ACC->name("vacation with a different name");
143 $ACC->insert;
144 HomeBank::Account->compute_balances;
145 print "account name is ", $ACC->name, " and balance is ", $ACC->balance, "\n";
146 print Dumper($ACC->transactions);
147
148 my $cloned = $ACC->clone;
149 $cloned->name("vacation copy");
150 $cloned->insert;
151 #my $asdf = $cloned->open;
152 #$asdf->set_title("this is a new friggin account");
153
154 #my $z = HomeBank::Account->get_by_name('Checking');
155 for my $xc (HomeBank::File->transactions) {
156 use DateTime;
157 my $num = $xc->date;
158 my $date = DateTime->new($xc->date)->datetime;
159 print "transaction of amount: ", $xc->amount, "\t", $xc->memo, ", ", $xc->info, ", $num, $date\n";
160 }
161
162 HomeBank::File->owner('Billy Murphy');
163 #HomeBank::File->anonymize;
164 print HomeBank::File->owner, "\n";
165
166 HomeBank::File->baz($ACC);
167 }
168
169 sub on_deep_hook_recursion {
170 my $self = shift;
171 my $level = shift;
172 print STDERR "recursion is too deep ($level)\n";
173 exit -2;
174 }
175
176 sub on_my_hook {
177 my $self = shift;
178 print "This is MY HOOK!!!!!!\n";
179 print Dumper(\@_);
180
181 print Dumper($_[2]);
182 Dump($_[2]);
183 if ($_[2]) {
184 print "meh\n";
185 }
186 if ($_[2]->isa('HomeBank::Boolean')) {
187 print "it is a home;;boolean\n";
188 }
189 if ($_[2]->isa('Types::Serialiser::Boolean')) {
190 print "it is a types serialiser thingy\n";
191 }
192 if ($_[2]->isa('HomeBank::BooleanBase')) {
193 print "it is a base bool\n";
194 }
195
196 my $win = $_[6];
197 if ($win && ref($win) eq 'HASH') {
198 my $w = $win->{meh};
199 if ($w) {
200 $w->set_title("this is MY HOOK setting a window title");
201 }
202 }
203 #print Dumper($acc);
204 #print "transferred account: ", $acc->name, "\n";
205
206 #my $fff = HomeBank::File->foo({foo => 'asdf', bar => 123456789});
207 my $fff = HomeBank::File->meh([qw/hello this is a test 82/, \1, {foo => 'bar'}, 48]);
208 print Dumper($fff);
209
210 print "my hook done\n";
211 }
212
213 sub on_unhandled {
214 my ($self, $hook) = @_;
215 warn "Unhandled hook '$hook'\n";
216 #HomeBank->warn($hook, 'Hook not handled.');
217 }
218
219 sub DESTROY {
220 my $self = shift;
221 print "DESTROYING HELLO WORLD!!!!!!\n";
222 if ($test_win) {
223 print "there is a test_win...\n";
224 }
225 $test_win->destroy if $test_win;
226 }
227
228 sub EXECUTE {
229 print "the perl plugin is being configured.....\n";
230 HomeBank->info("Hello Prefs", "YEEEEEARGGH!!!!!");
231 }
232
233 #__PACKAGE__->meta->make_immutable;
This page took 0.046565 seconds and 4 git commands to generate.