Changeset 15184
- Timestamp:
- Oct 3, 2007, 12:15:02 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
r14794 r15184 1 1 # Copyright (c) 2006 Paul Price, Joshua Hoblitt 2 2 # 3 # $Id: Config.pm,v 1. 69 2007-09-07 21:39:58price Exp $3 # $Id: Config.pm,v 1.70 2007-10-03 22:15:02 price Exp $ 4 4 5 5 package PS::IPP::Config; … … 87 87 path => $path, # Path 88 88 camera => undef, # Camera configuration 89 filerules => undef, # File rules from the camera configuration 89 90 rejection => undef, # Rejection data 90 91 _ipprc => $mdc # The parsed configuration … … 654 655 } 655 656 656 my $camera = $self->{camera}; # Camera configuration 657 unless (defined $camera) { 658 carp "Camera has not yet been defined.\n"; 659 return undef; 660 } 661 662 my $filerules = metadataLookupMD($camera, 'FILERULES'); # File rules 663 unless (defined $filerules) { 664 carp "Can't find FILERULES list in camera configuration.\n"; 665 return undef; 657 my $filerules; # File rules 658 if (defined $self->{filerules}) { 659 $filerules = $self->{filerules}; 660 } else { 661 # Get the file rules from the camera configuration 662 663 my $camera = $self->{camera}; # Camera configuration 664 unless (defined $camera) { 665 carp "Camera has not yet been defined.\n"; 666 return undef; 667 } 668 669 $filerules = metadataLookup($camera, 'FILERULES'); # File rules 670 unless (defined $filerules) { 671 carp "Can't find FILERULES list in camera configuration.\n"; 672 return undef; 673 } 674 675 if ($filerules->{class} eq "scalar" and $filerules->{type} eq "STR") { 676 # Allow indirection to a file 677 my $filename = $self->_find_config($filerules->{value}); # Resolved filename 678 # Read the file 679 my $file; # File handle 680 unless (open $file, $filename) { 681 carp "Unable to open filerules file $filename: $!"; 682 exit($PS_EXIT_CONFIG_ERROR); 683 } 684 my @contents = <$file>; 685 close $file; 686 $filerules = $parser->parse( join '', @contents); 687 } elsif ($filerules->{class} eq "metadata") { 688 $filerules = $filerules->{value}; 689 } else { 690 carp "Can't interpret FILERULES in camera configuration.\n"; 691 return undef; 692 } 693 $self->{filerules} = $filerules; 666 694 } 667 695 … … 845 873 } 846 874 847 # Lookup the metadata, checking the type is STR 848 sub metadataLookupStr 875 sub metadataLookup 849 876 { 850 877 my $mdc = shift; # Metadata config to look up … … 859 886 foreach my $item (@$mdc) { 860 887 if ($item->{name} eq $name) { 861 carp "$name within metadata is not of type STR.\n" unless $item->{type} eq "STR"; 862 return $item->{value}; 888 return $item; 863 889 } 864 890 } … … 867 893 return undef; 868 894 } 895 896 897 # Lookup the metadata, checking the type is STR 898 sub metadataLookupStr 899 { 900 my $item = metadataLookup(@_); 901 return undef if not defined $item; 902 my $name = shift; # Name of item 903 carp "$name within metadata is not of type STR.\n" unless $item->{type} eq "STR"; 904 return $item->{value}; 905 } 869 906 870 907 # Lookup the metadata, checking the type is MD 871 908 sub metadataLookupMD 872 909 { 873 my $mdc = shift; # Metadata config to look up 874 my $name = shift; # Name of item to look ip 875 876 unless (defined $mdc and defined $name) { 877 carp "Programming error"; 878 exit($PS_EXIT_PROG_ERROR); 879 } 880 881 # Iterate through the array of hashes 882 foreach my $item (@$mdc) { 883 if ($item->{name} eq $name) { 884 carp "$name within metadata is not of type METADATA.\n" unless $item->{class} eq "metadata"; 885 return $item->{value}; 886 } 887 } 888 889 carp "Unable to find $name within metadata.\n"; 890 return undef; 910 my $item = metadataLookup(@_); 911 return undef if not defined $item; 912 my $name = shift; # Name of item 913 carp "$name within metadata is not of type METADATA.\n" unless $item->{class} eq "metadata"; 914 return $item->{value}; 891 915 } 892 916 … … 894 918 sub metadataLookupBool 895 919 { 896 my $mdc = shift; # Metadata config to look up 897 my $name = shift; # Name of item to look ip 898 899 unless (defined $mdc and defined $name) { 900 carp "Programming error"; 901 exit($PS_EXIT_PROG_ERROR); 902 } 903 904 # Iterate through the array of hashes 905 foreach my $item (@$mdc) { 906 if ($item->{name} eq $name) { 907 carp "$name within metadata is not of type BOOL.\n" unless $item->{type} eq "BOOL"; 908 return $item->{value}; 909 } 910 } 911 912 carp "Unable to find $name within metadata.\n"; 913 return undef; 920 my $item = metadataLookup(@_); 921 return undef if not defined $item; 922 my $name = shift; # Name of item 923 carp "$name within metadata is not of type BOOL.\n" unless $item->{type} eq "BOOL"; 924 return $item->{value}; 914 925 } 915 926
Note:
See TracChangeset
for help on using the changeset viewer.
