| 1 | # Copyright 2008, 2009, 2010, 2011, 2012, 2016 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | package App::Chart::Glib::Ex::TempProperty; | ||
| 18 | use 5.008; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use Glib; | ||
| 22 | use Carp; | ||
| 23 | |||
| 24 | sub new { | ||
| 25 | my $class = shift; | ||
| 26 | my $obj = shift; | ||
| 27 | if (@_ & 1) { | ||
| 28 | croak 'TempProperty should have an even number of propname+value arguments'; | ||
| 29 | } | ||
| 30 | my @self = ($obj); | ||
| 31 | my $self = bless \@self, $class; | ||
| 32 | while (@_) { | ||
| 33 | my $pname = shift; | ||
| 34 | my $value = shift; | ||
| 35 | push @self, $pname, $obj->get_property($pname); | ||
| 36 | $obj->set_property($pname,$value); | ||
| 37 | } | ||
| 38 | return $self; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub DESTROY { | ||
| 42 | my ($self) = @_; | ||
| 43 | my $obj = shift @$self; | ||
| 44 | while (@$self) { | ||
| 45 | $obj->set_property(shift @$self, shift @$self); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | __END__ | ||
| 51 | |||
| 52 | =head1 NAME | ||
| 53 | |||
| 54 | =for stopwords TempProperty | ||
| 55 | |||
| 56 | App::Chart::Glib::Ex::TempProperty -- temporary object property setting | ||
| 57 | |||
| 58 | =for test_synopsis my ($obj, $newval) | ||
| 59 | |||
| 60 | =head1 SYNOPSIS | ||
| 61 | |||
| 62 | use App::Chart::Glib::Ex::TempProperty; | ||
| 63 | my $setting = App::Chart::Glib::Ex::TempProperty->new ($obj, 'propname', $newval); | ||
| 64 | |||
| 65 | =head1 FUNCTIONS | ||
| 66 | |||
| 67 | =over 4 | ||
| 68 | |||
| 69 | =item C<< App::Chart::Glib::Ex::TempProperty->new ($obj, $propname) >> | ||
| 70 | |||
| 71 | =item C<< App::Chart::Glib::Ex::TempProperty->new ($obj, $propname, $newvalue) >> | ||
| 72 | |||
| 73 | Create and return a TempProperty object ... | ||
| 74 | |||
| 75 | =back | ||
| 76 | |||
| 77 | =head1 SEE ALSO | ||
| 78 | |||
| 79 | L<Glib::Ex::TieProperties> | ||
| 80 | |||
| 81 | =head1 HOME PAGE | ||
| 82 | |||
| 83 | L<http://user42.tuxfamily.org/chart/index.html> | ||
| 84 | |||
| 85 | =head1 LICENCE | ||
| 86 | |||
| 87 | Copyright 2008, 2009, 2010, 2011, 2012, 2016 Kevin Ryde | ||
| 88 | |||
| 89 | Chart is free software; you can redistribute it and/or modify it under the | ||
| 90 | terms of the GNU General Public License as published by the Free Software | ||
| 91 | Foundation; either version 3, or (at your option) any later version. | ||
| 92 | |||
| 93 | Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 94 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 95 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 96 | details. | ||
| 97 | |||
| 98 | You should have received a copy of the GNU General Public License along with | ||
| 99 | Chart; see the file F<COPYING>. Failing that, see | ||
| 100 | L<http://www.gnu.org/licenses/>. | ||
| 101 | |||
| 102 | =cut |