« lib/Gtk2/Ex/MindMapView/Layout/Column.pm
↑ Summary
blib/lib/Gtk2/Ex/MindMapView/HotSpot/Toggle.pm »
| 1 | package Gtk2::Ex::MindMapView::ArgUtils; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use Carp; | ||
| 6 | |||
| 7 | use Exporter; | ||
| 8 | |||
| 9 | our $VERSION = '0.000001'; | ||
| 10 | |||
| 11 | our @ISA = qw(Exporter); | ||
| 12 | |||
| 13 | our @EXPORT = qw(args_required args_store args_valid arg_default); | ||
| 14 | |||
| 15 | |||
| 16 | sub args_required | ||
| 17 | { | ||
| 18 | my ($attributes_ref, @valid_keys) = @_; | ||
| 19 | |||
| 20 | foreach my $valid_key (@valid_keys) | ||
| 21 | { | ||
| 22 | if (!defined $attributes_ref->{$valid_key}) | ||
| 23 | { | ||
| 24 | croak "Missing required argument: $valid_key\n"; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | |||
| 30 | sub args_store | ||
| 31 | { | ||
| 32 | my ($self, $attributes_ref) = @_; | ||
| 33 | |||
| 34 | my %attributes = %$attributes_ref; | ||
| 35 | |||
| 36 | foreach my $key (keys %attributes) | ||
| 37 | { | ||
| 38 | $self->{$key} = $attributes{$key}; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | sub args_valid | ||
| 44 | { | ||
| 45 | my ($attributes_ref, @valid_keys) = @_; | ||
| 46 | |||
| 47 | KEY: foreach my $key (keys %$attributes_ref) | ||
| 48 | { | ||
| 49 | foreach my $valid_key (@valid_keys) | ||
| 50 | { | ||
| 51 | next KEY if ($valid_key eq $key); | ||
| 52 | } | ||
| 53 | |||
| 54 | croak "Invalid argument: $key\n"; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | sub arg_default | ||
| 60 | { | ||
| 61 | my ($self, $key, $default) = @_; | ||
| 62 | |||
| 63 | if (!defined $self->{$key}) | ||
| 64 | { | ||
| 65 | $self->{$key} = $default; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | 1; # Magic true value required at end of module | ||
| 71 | __END__ |