blib/lib/WWW/MyNewsletterBuilder.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 #
2 # Copyright (C) 2010 JBA Network (http://www.jbanetwork.com)
3 # WWW::MyNewsletterBuilder is free software; you can redistribute it
4 # and/or modify it under the same terms as Perl itself.
5 #
6 # WWW::MyNewsletterBuilder is an interface to the mynewsletterbuilder.com
7 # XML-RPC API.
8 #
9 # $Id: MyNewsletterBuilder.pm 59878 2010-05-04 22:15:50Z bo $
10 #
11  
12 package WWW::MyNewsletterBuilder;
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 0 ▶use Frontier::Client;
Subroutine BEGIN: called CC=1 SCAR=2.6
17  
18 our $VERSION = '0.021';
19  
20 sub new {
21 my $class = shift;
22 my $args = ($#_ == 0) ? { %{ (shift) } } : { @_ };
23  
24 if (!$args->{api_key}){
25 die('you must pass an api_key to WWW::MyNewsletterBuilder->new()');
26 }
27  
28 my $self = {
29 api_key => $args->{api_key},
30 username => $args->{username},
31 password => $args->{password},
32 timeout => $args->{timeout} || 300,
33 secure => $args->{secure} || 0,
34 no_validation => $args->{no_validation} || 0,
35 _api_host => $args->{_api_host} || 'api.mynewsletterbuilder.com',
36 _api_version => $args->{_api_version} || '1.0',
37 _debug => $args->{_debug} || 0,
38 };
39  
40 bless($self, $class);
41  
42 # we have to bless before setting up the url and client
43 my $url = $self->_buildUrl();
44 if ($self->{_debug}){
45 print "url: $url\n";
46 }
47  
48 $self->{client} = $self->_getClient($url);
49 return $self;
50 }
51  
52 # the only config var that might need to be changed between calls is timeout
53 sub Timeout{
54 my $self = shift;
55 $self->{timeout} = shift;
56 $self->{client}->{ua}->timeout($self->{timeout});
57 return 1;
58 }
59  
60 sub Campaigns{
61 my $self = shift;
62 my $filters = ($#_ == 0) ? { %{ (shift) } } : { @_ };
63  
64 $filters = $self->_validateHash(
65 $filters,
66 {
67 status => {
68 value => 'string',
69 emptyOk => 1,
70 },
71 archived => {
72 value => 'bool',
73 emptyOk => 1,
74 },
75 published => {
76 value => 'bool',
77 emptyOk => 1,
78 },
79 },
80 1
81 );
82  
83 return $self->_Execute('Campaigns', $filters);
84 }
85  
86 sub CampaignDetails{
87 my $self = shift;
88 my $id = $self->_intify(shift);
89  
90 return $self->_Execute('CampaignDetails', $id);
91 }
92  
93 sub CampaignCreate{
94 my $self = shift;
95 my $name = $self->_stringify(shift);
96 my $subject = $self->_stringify(shift);
97 my $from = shift;
98 my $reply = shift;
99 my $html = $self->_stringify(shift);
100 my $text = $self->_stringify(shift || '', 1);
101 my $link_tracking = $self->_boolify(shift || 1);
102 my $gat = $self->_boolify(shift || 0);
103  
104 $from = $self->_validateHash(
105 $from,
106 {
107 name => {
108 value => 'string',
109 },
110 email => {
111 value => 'string',
112 },
113 },
114 );
115
116 $reply = $self->_validateHash(
117 $reply,
118 {
119 name => {
120 value => 'string',
121 emptyOk => 1,
122 },
123 email => {
124 value => 'string',
125 emptyOk => 1,
126 },
127 },
128 1
129 );
130  
131 return $self->_Execute(
132 'CampaignCreate',
133 $name,
134 $subject,
135 $from,
136 $reply,
137 $html,
138 $text,
139 $link_tracking,
140 $gat,
141 );
142 }
143  
144 sub CampaignUpdate{
145 my $self = shift;
146 my $id = $self->_intify(shift);
147 my $details = shift;
148  
149 my $signature = {};
150 $signature->{name} = {value => 'string'};
151 $signature->{subject} = {value => 'string'};
152 $signature->{html} = {value => 'string'};
153 $signature->{text} = {value => 'string', emptyOk => 1};
154 $signature->{link_tracking} = {value => 'bool', emptyOk => 1};
155 $signature->{gat} = {value => 'bool', emptyOk => 1};
156  
157 $signature->{from} = {
158 value => {
159 name => {
160 value => 'string',
161 },
162 email => {
163 value => 'string',
164 },
165 },
166 };
167 $signature->{reply} = {
168 value => {
169 name => {
170 value => 'string',
171 emptyOk => 1,
172 },
173 email => {
174 value => 'string',
175 emptyOk => 1,
176 },
177 },
178 emptyOk => 1,
179 };
180  
181 $details = $self->_validateHash($details, $signature);
182  
183 return $self->_Execute(
184 'CampaignUpdate',
185 $id,
186 $details,
187 );
188 }
189  
190 sub CampaignCopy{
191 my $self = shift;
192 my $id = $self->_intify(shift);
193 my $name = $self->_stringify(shift || '', 1);
194  
195 return $self->_Execute('CampaignCopy', $id, $name);
196 }
197  
198 sub CampaignDelete{
199 my $self = shift;
200 my $id = $self->_intify(shift);
201  
202 return $self->_Execute('CampaignDelete', $id);
203 }
204  
205 sub CampaignSchedule{
206 my $self = shift;
207 my $id = $self->_intify(shift);
208 my $when = $self->_stringify(shift);
209 my $lists = shift;
210 my $smart = $self->_boolify(shift || 0);
211 my $confirmed = $self->_boolify(shift || 0);
212  
213 $lists = $self->_validateArray($lists, 'int', 1);
214  
215 return $self->_Execute(
216 'CampaignSchedule',
217 $id,
218 $when,
219 $lists,
220 $smart,
221 $confirmed
222 );
223 }
224  
225 sub CampaignStats{
226 my $self = shift;
227 my $id = $self->_intify(shift);
228  
229 return $self->_Execute('CampaignStats', $id);
230 }
231  
232 sub CampaignRecipients{
233 my $self = shift;
234 my $id = $self->_intify(shift);
235 my $page = $self->_intify(shift || 0);
236 my $limit = $self->_intify(shift || 1000);
237  
238 return $self->_Execute(
239 'CampaignRecipients',
240 $id,
241 $page,
242 $limit
243 );
244 }
245  
246 sub CampaignOpens{
247 my $self = shift;
248 my $id = $self->_intify(shift);
249 my $page = $self->_intify(shift || 0);
250 my $limit = $self->_intify(shift || 1000);
251  
252 return $self->_Execute(
253 'CampaignOpens',
254 $id,
255 $page,
256 $limit
257 );
258 }
259  
260 sub CampaignBounces{
261 my $self = shift;
262 my $id = $self->_intify(shift);
263 my $page = $self->_intify(shift || 0);
264 my $limit = $self->_intify(shift || 1000);
265  
266 return $self->_Execute(
267 'CampaignBounces',
268 $id,
269 $page,
270 $limit
271 );
272 }
273  
274 sub CampaignClicks{
275 my $self = shift;
276 my $id = $self->_intify(shift);
277 my $page = $self->_intify(shift || 0);
278 my $limit = $self->_intify(shift || 1000);
279  
280 return $self->_Execute(
281 'CampaignClicks',
282 $id,
283 $page,
284 $limit
285 );
286 }
287  
288 sub CampaignClickDetails{
289 my $self = shift;
290 my $id = $self->_intify(shift);
291 my $url_id = $self->_intify(shift);
292 my $page = $self->_intify(shift || 0);
293 my $limit = $self->_intify(shift || 1000);
294  
295 return $self->_Execute(
296 'CampaignClickDetails',
297 $id,
298 $url_id,
299 $page,
300 $limit
301 );
302 }
303  
304 sub CampaignSubscribes{
305 my $self = shift;
306 my $id = $self->_intify(shift);
307 my $page = $self->_intify(shift || 0);
308 my $limit = $self->_intify(shift || 1000);
309  
310 return $self->_Execute(
311 'CampaignSubscribes',
312 $id,
313 $page,
314 $limit
315 );
316 }
317  
318 sub CampaignUnsubscribes{
319 my $self = shift;
320 my $id = $self->_intify(shift);
321 my $page = $self->_intify(shift || 0);
322 my $limit = $self->_intify(shift || 1000);
323  
324 return $self->_Execute(
325 'CampaignUnsubscribes',
326 $id,
327 $page,
328 $limit
329 );
330 }
331  
332 sub CampaignUrls{
333 my $self = shift;
334 my $id = $self->_intify(shift);
335  
336 return $self->_Execute('CampaignUrls', $id);
337 }
338  
339 sub Lists{
340 my $self = shift;
341
342 return $self->_Execute('Lists');
343 }
344  
345 sub ListDetails{
346 my $self = shift;
347 my $id = $self->_intify(shift);
348
349 return $self->_Execute('ListDetails', $id);
350 }
351  
352 sub ListCreate{
353 my $self = shift;
354 my $name = $self->_stringify(shift);
355 my $description = $self->_stringify(shift || '', 1);
356 my $visible = $self->_boolify(shift || 0);
357 my $default = $self->_boolify(shift || 0);
358  
359 return $self->_Execute(
360 'ListCreate',
361 $name,
362 $description,
363 $visible,
364 $default
365 );
366 }
367  
368 sub ListUpdate{
369 my $self = shift;
370 my $id = $self->_intify(shift);
371 my $details = shift;
372  
373 my $signature = {};
374 $signature->{name} = {
375 value => 'string',
376 emptyOk => 1,
377 };
378 $signature->{description} = {
379 value => 'string',
380 emptyOk => 1,
381 };
382 $signature->{visible} = {
383 value => 'bool',
384 emptyOk => 1,
385 };
386 $signature->{default} = {
387 value => 'bool',
388 emptyOk => 1,
389 };
390  
391 $details = $self->_validateHash($details, $signature);
392  
393 return $self->_Execute('ListUpdate', $id, $details);
394 }
395  
396 sub ListDelete{
397 my $self = shift;
398 my $id = $self->_intify(shift);
399 my $delete_subs = $self->_boolify(shift || 0);
400  
401 return $self->_Execute('ListDelete', $id, $delete_subs);
402 }
403  
404 sub Subscribe{
405 my $self = shift;
406 my $details = shift;
407 my $lists = shift;
408 my $skip_opt_in = $self->_boolify(shift || 0);
409 my $update_existing = $self->_boolify(shift || 1);
410  
411 my $signature = {};
412 $signature->{email} = {value => 'string'};
413 $signature->{first_name} = {value => 'string', emptyOk => 1};
414 $signature->{middle_name} = {value => 'string', emptyOk => 1};
415 $signature->{last_name} = {value => 'string', emptyOk => 1};
416 $signature->{full_name} = {value => 'string', emptyOk => 1};
417 $signature->{company_name} = {value => 'string', emptyOk => 1};
418 $signature->{job_title} = {value => 'string', emptyOk => 1};
419 $signature->{phone_work} = {value => 'string', emptyOk => 1};
420 $signature->{phone_home} = {value => 'string', emptyOk => 1};
421 $signature->{address_1} = {value => 'string', emptyOk => 1};
422 $signature->{address_2} = {value => 'string', emptyOk => 1};
423 $signature->{address_3} = {value => 'string', emptyOk => 1};
424 $signature->{city} = {value => 'string', emptyOk => 1};
425 $signature->{state} = {value => 'string', emptyOk => 1};
426 $signature->{zip} = {value => 'string', emptyOk => 1};
427 $signature->{country} = {value => 'string', emptyOk => 1};
428  
429 $details = $self->_validateHash($details, $signature);
430  
431 $lists = $self->_validateArray($lists, 'int', 1);
432  
433 return $self->_Execute(
434 'Subscribe',
435 $details,
436 $lists,
437 $skip_opt_in,
438 $update_existing
439 );
440 }
441  
442 sub SubscribeBatch{
443 my $self = shift;
444 my $subscribers = shift;
445 my $lists = shift;
446 my $skip_opt_in = $self->_boolify(shift || 0);
447 my $update_existing = $self->_boolify(shift || 1);
448  
449 my $signature = {};
450 $signature->{email} = {value => 'string'};
451 $signature->{first_name} = {value => 'string', emptyOk => 1};
452 $signature->{middle_name} = {value => 'string', emptyOk => 1};
453 $signature->{last_name} = {value => 'string', emptyOk => 1};
454 $signature->{full_name} = {value => 'string', emptyOk => 1};
455 $signature->{company_name} = {value => 'string', emptyOk => 1};
456 $signature->{job_title} = {value => 'string', emptyOk => 1};
457 $signature->{phone_work} = {value => 'string', emptyOk => 1};
458 $signature->{phone_home} = {value => 'string', emptyOk => 1};
459 $signature->{address_1} = {value => 'string', emptyOk => 1};
460 $signature->{address_2} = {value => 'string', emptyOk => 1};
461 $signature->{address_3} = {value => 'string', emptyOk => 1};
462 $signature->{city} = {value => 'string', emptyOk => 1};
463 $signature->{state} = {value => 'string', emptyOk => 1};
464 $signature->{zip} = {value => 'string', emptyOk => 1};
465 $signature->{country} = {value => 'string', emptyOk => 1};
466  
467 $subscribers = $self->_validateArray($subscribers, $signature);
468  
469 $lists = $self->_validateArray($lists, 'int', 1);
470  
471 return $self->_Execute(
472 'SubscribeBatch',
473 $subscribers,
474 $lists,
475 $skip_opt_in,
476 $update_existing
477 );
478 }
479  
480 sub Subscribers{
481 my $self = shift;
482 my $statuses = shift;
483 my $lists = shift;
484 my $page = $self->_intify(shift || 0);
485 my $limit = $self->_intify(shift || 1000);
486  
487 return $self->_Execute('Subscribers', $statuses, $lists, $page, $limit);
488 }
489  
490 sub SubscriberDetails{
491 my $self = shift;
492 my $id_or_email = $self->_stringify(shift);
493  
494 return $self->_Execute('SubscriberDetails', $id_or_email);
495 }
496  
497 sub SubscriberUpdate{
498 my $self = shift;
499 my $id_or_email = $self->_stringify(shift);
500 my $details = shift;
501 my $lists = shift;
502
503 my $signature = {};
504 $signature->{email} = {value => 'string'};
505 $signature->{first_name} = {value => 'string', emptyOk => 1};
506 $signature->{middle_name} = {value => 'string', emptyOk => 1};
507 $signature->{last_name} = {value => 'string', emptyOk => 1};
508 $signature->{full_name} = {value => 'string', emptyOk => 1};
509 $signature->{company_name} = {value => 'string', emptyOk => 1};
510 $signature->{job_title} = {value => 'string', emptyOk => 1};
511 $signature->{phone_work} = {value => 'string', emptyOk => 1};
512 $signature->{phone_home} = {value => 'string', emptyOk => 1};
513 $signature->{address_1} = {value => 'string', emptyOk => 1};
514 $signature->{address_2} = {value => 'string', emptyOk => 1};
515 $signature->{address_3} = {value => 'string', emptyOk => 1};
516 $signature->{city} = {value => 'string', emptyOk => 1};
517 $signature->{state} = {value => 'string', emptyOk => 1};
518 $signature->{zip} = {value => 'string', emptyOk => 1};
519 $signature->{country} = {value => 'string', emptyOk => 1};
520  
521 $details = $self->_validateHash($details, $signature);
522  
523 $lists = $self->_validateArray($lists, 'int', 1);
524  
525 return $self->_Execute(
526 'SubscriberUpdate',
527 $id_or_email,
528 $details,
529 $lists,
530 );
531 }
532  
533 sub SubscriberUnsubscribe{
534 my $self = shift;
535 my $id_or_email = $self->_stringify(shift);
536  
537 return $self->_Execute('SubscriberUnsubscribe', $id_or_email);
538 }
539  
540 sub SubscriberUnsubscribeBatch{
541 my $self = shift;
542 my $ids_or_emails = shift;
543  
544 $ids_or_emails = $self->_validateArray($ids_or_emails, 'string');
545  
546 return $self->_Execute('SubscriberUnsubscribeBatch', $ids_or_emails);
547 }
548  
549 sub SubscriberDelete{
550 my $self = shift;
551 my $id_or_email = $self->_stringify(shift);
552  
553 return $self->_Execute('SubscriberDelete', $id_or_email);
554 }
555  
556 sub SubscriberDeleteBatch{
557 my $self = shift;
558 my $ids_or_emails = shift;
559  
560 $ids_or_emails = $self->_validateArray($ids_or_emails, 'string');
561  
562 return $self->_Execute('SubscriberDeleteBatch', $ids_or_emails);
563 }
564  
565 sub AccountKeys{
566 my $self = shift;
567 my $username = $self->_stringify(shift);
568 my $password = $self->_stringify(shift);
569 my $disabled = $self->_boolify(shift || 0);
570  
571 return $self->_Execute(
572 'AccountKeys',
573 $username,
574 $password,
575 $disabled,
576 );
577 }
578  
579 sub AccountKeyCreate{
580 my $self = shift;
581 my $username = $self->_stringify(shift);
582 my $password = $self->_stringify(shift);
583  
584 return $self->_Execute('AccountKeyCreate', $username, $password);
585 }
586  
587 sub AccountKeyEnable{
588 my $self = shift;
589 my $username = $self->_stringify(shift);
590 my $password = $self->_stringify(shift);
591 my $id_or_key = $self->_stringify(shift);
592  
593 return $self->_Execute(
594 'AccounKeyEnable',
595 $username,
596 $password,
597 $id_or_key
598 );
599 }
600  
601 sub AccountKeyDisable{
602 my $self = shift;
603 my $username = $self->_stringify(shift);
604 my $password = $self->_stringify(shift);
605 my $id_or_key = $self->_stringify(shift);
606  
607 return $self->_Execute(
608 'AccounKeyDisable',
609 $username,
610 $password,
611 $id_or_key
612 );
613 }
614  
615 sub HelloWorld{
616 my $self = shift;
617 my $val = $self->_stringify(shift || '', 1);
618  
619 return $self->_Execute('HelloWorld', $val);
620 }
621  
622 sub _Execute{
623 my $self = shift;
624 my $method = shift;
625  
626 $self->{errno} = '';
627 $self->{errstr} = '';
628  
629 my $data;
630 eval{
631 $data = $self->{client}->call($method, $self->{api_key}, @_);
632 };
633  
634 if ($self->{_debug}){
635 use Data::Dumper;
636 print "returned data\n";
637 print Dumper $data;
638 }
639  
640 if ($@){
641 $self->{errno} = 2;
642 $self->{errstr} = $@;
643  
644 if ($self->{_debug}){
645 print 'errors: '. $self->{errno} .'--'. $self->{errstr} ."\n";
646 }
647  
648 return 0;
649 }
650 elsif (!$data){
651 $self->{errno} = 2;
652 $self->{errstr} = 'Empty response from API server';
653  
654 if ($self->{_debug}){
655 print 'errors: '. $self->{errno} .'--'. $self->{errstr} ."\n";
656 }
657  
658 return 0;
659 }
660  
661 if (ref($data) eq 'HASH' && $data->{'errno'}){
662 $self->{errno} = $data->{'errno'};
663 $self->{errstr} = $data->{'errstr'};
664 return 0;
665 }
666  
667 return $self->_unBoolify($data);
668 }
669  
670 sub _buildUrl{
671 my $self = shift;
672 my $url;
673 if ($self->{secure}){
674 $url = 'https://';
675 }
676 else{
677 $url = 'http://';
678 }
679  
680 return $url . $self->{_api_host} . '/' . $self->{_api_version};
681 }
682  
683 sub _getClient{
684 my $self = shift;
685 my $url = shift;
686  
687 my $client = Frontier::Client->new(
688 url => $url,
689 debug => 0,
690 );
691  
692 # we have to modify Frontier's LWP instance a little bit.
693 $client->{ua}->agent('MNB_API Perl ' . $self->{_api_version} . '/' . $VERSION . '-' . '$Rev: 59878 $');
694 $client->{ua}->requests_redirectable(['GET', 'HEAD', 'POST' ]);
695 $client->{ua}->timeout($self->{timeout});
696  
697 return $client;
698 }
699  
700 sub _error{
701 my $self = shift;
702 my $msg = shift;
703 my $warn = shift || 0;
704  
705 if ($self->{no_validation} || $warn){
706 warn($msg);
707 }
708 else{
709 die($msg);
710 }
711 }
712  
713 sub _validateArray{
714 my $self = shift;
715 my $array = shift;
716 my $signature = shift;
717 my $emptyOk = shift || 0;
718  
719 my $isHash = 0;
720 if (ref($signature) eq 'HASH'){
721 $isHash = 1;
722 }
723  
724 if (!$array and !$emptyOk){
725 $self->_error('invalid param passed to '. (caller(1))[3] .':'. (caller(0))[2] .' from '. (caller(1))[1] .':'. (caller(1))[2] .' expected array got '. $array);
726 }
727  
728 foreach (@$array){
729 if ($isHash){
730 $_ = validateHash($_, $signature, $emptyOk);
731 }
732 else{
733 my $function = '_' . $signature . 'ify';
734 $_ = $self->$function($_, $emptyOk);
735 }
736 }
737 return $array;
738 }
739  
740 ##
741 #
742 # takes a hash and a signature for that hash and validates the hash's
743 # values then makes sure they are the proper xml-rpc types.
744 #
745 ##
746 sub _validateHash{
747 my $self = shift;
748 my $hash = shift;
749 my $signature = shift;
750 my $emptyOk = shift || 0;
751  
752 if (!$hash and !$emptyOk){
753 $self->_error('invalid param passed to '. (caller(1))[3] .':'. (caller(0))[2] .' from '. (caller(1))[1] .':'. (caller(1))[2] .' expected hash got '. $hash);
754 }
755  
756 ##
757 #
758 # we loop through the signature keys. if the value is a hash
759 # we need recursively call this function. if it is a string
760 # we validate it based on the type.
761 #
762 ##
763 foreach (keys(%$signature)){
764 if (ref($signature->{$_}->{value}) eq 'HASH'){
765 $hash->{$_} = $self->_validateHash($hash->{$_}, $signature->{$_}->{value}, $signature->{$_}->{emptyOk}) if (defined($hash->{$_}));
766 }
767 else{
768 my $function = '_' . $signature->{$_}->{value} . 'ify';
769 $hash->{$_} = $self->$function($hash->{$_}, $signature->{$_}->{emptyOk}) if (defined($hash->{$_}));
770 }
771 }
772  
773 return $hash;
774 }
775  
776 ##
777 #
778 # $self->_intify( int $var, bool $require)
779 # validates value of $var as an int... throws error if it isn't
780 # converts to Frontier int data type if test passed (or we aren't validating data))
781 #
782 ##
783 sub _intify{
784 my $self = shift;
785 my $var = shift;
786 my $emptyOk = shift || 0;
787  
788 my $check = '\d+';
789 $check = '\d*' if ($emptyOk);
790  
791 $self->_error('invalid param passed to '. (caller(1))[3] .':'. (caller(0))[2] .' from '. (caller(1))[1] .':'. (caller(1))[2] .' expected int got '. $var) unless ($var =~ /^($check)$/);
792  
793 return $self->{client}->int($var);
794 }
795  
796 ##
797 #
798 # $self->_stringify( string $var, bool $require)
799 # validates value of $var as an string... throws error if it isn't
800 # converts to Frontier string data type if test passed (or we aren't validating data))
801 #
802 ##
803 sub _stringify{
804 my $self = shift;
805 my $var = shift;
806 my $emptyOk = shift || 0;
807  
808 my $check = '.+';
809 $check = '.*' if ($emptyOk);
810  
811 $self->_error('invalid param passed to '. (caller(1))[3] .':'. (caller(0))[2] .' from '. (caller(1))[1] .':'. (caller(1))[2] .' expected string got '. $var) unless ($var =~ /^($check)$/);
812  
813 return $self->{client}->string($var);
814 }
815  
816 ##
817 #
818 # $self->boolfy( int $var, bool $require)
819 # validates value of $var as a bool... throws error if it isn't
820 # converts to Frontier bool data type if test passed (or we aren't validating data))
821 #
822 ##
823 sub _boolify{
824 my $self = shift;
825 my $var = shift;
826  
827 $self->_error('invalid param passed to '. (caller(1))[3] .':'. (caller(0))[2] .' from '. (caller(1))[1] .':'. (caller(1))[2] .' expected bool(0 or 1) got '. $var) unless ($var =~ /^(0|1)$/);
828  
829 return $self->{client}->boolean($var);
830 }
831  
832 sub _unBoolify{
833 my $self = shift;
834 my $var = shift;
835  
836 if (ref($var) eq 'ARRAY'){
837 foreach my $v (@$var){
838 $v = $self->_unBoolify($v);
839 }
840 }
841  
842 if (ref($var) eq 'HASH'){
843 foreach (keys(%$var)){
844 $var->{$_} = $self->_unBoolify($var->{$_});
845 }
846 }
847  
848 if (ref($var) ne 'Frontier::RPC2::Boolean'){
849 return $var;
850 }
851 return $var->value;
852 }
853  
854 1;
855 __END__
↑ Summary