| 1 | package MyLibrary::Interface; | ||
| 2 | |||
| 3 | use Template qw( :template ); | ||
| 4 | |||
| 5 | sub output_interface { | ||
| 6 | my $self = $_[0]; | ||
| 7 | my $html = $self->{html}; | ||
| 8 | my $options = {}; | ||
| 9 | foreach my $attr (keys %{$self}) { | ||
| 10 | if ($attr ne 'html') { | ||
| 11 | $options->{$attr} = $self->{$attr}; | ||
| 12 | } | ||
| 13 | } | ||
| 14 | my $interface = Template->new({ | ||
| 15 | TRIM => 1, | ||
| 16 | PRE_CHOMP => 1, | ||
| 17 | POST_CHOMP => 0 | ||
| 18 | }); | ||
| 19 | |||
| 20 | $interface->process(\$html, $options) || die $interface->error(); | ||
| 21 | |||
| 22 | } # end sub output_interface | ||
| 23 | |||
| 24 | sub get_interface { | ||
| 25 | my $dbh = MyLibrary::DB->dbh(); | ||
| 26 | my $class = shift; | ||
| 27 | my %opts = @_; | ||
| 28 | my $q = qq(SELECT * FROM interface WHERE name='$opts{name}'); | ||
| 29 | my $interface = $dbh->selectrow_hashref($q); | ||
| 30 | my @arr = split(/,\W+/, $interface->{options}); | ||
| 31 | my @opts; | ||
| 32 | foreach my $pair (@arr) { | ||
| 33 | push @opts, split / => /, $pair; | ||
| 34 | } | ||
| 35 | my %interface_opts = (@opts); | ||
| 36 | my $self = { | ||
| 37 | html => $interface->{'html'}, | ||
| 38 | %interface_opts, | ||
| 39 | %opts | ||
| 40 | }; | ||
| 41 | return bless $self, $class; | ||
| 42 | } # end sub build_interface | ||
| 43 | |||
| 44 | 1; |