ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.276 by root, Sun Jun 10 04:05:47 2007 UTC vs.
Revision 1.278 by root, Mon Jun 11 21:38:14 2007 UTC

943 943
944 cf::override; 944 cf::override;
945 }, 945 },
946); 946);
947 947
948sub load_extension {
949 my ($path) = @_;
950
951 $path =~ /([^\/\\]+)\.ext$/ or die "$path";
952 my $base = $1;
953 my $pkg = $1;
954 $pkg =~ s/[^[:word:]]/_/g;
955 $pkg = "ext::$pkg";
956
957 warn "... loading '$path' into '$pkg'\n";
958
959 open my $fh, "<:utf8", $path
960 or die "$path: $!";
961
962 my $source =
963 "package $pkg; use strict; use utf8;\n"
964 . "#line 1 \"$path\"\n{\n"
965 . (do { local $/; <$fh> })
966 . "\n};\n1";
967
968 unless (eval $source) {
969 my $msg = $@ ? "$path: $@\n"
970 : "extension disabled.\n";
971 if ($source =~ /^#!.*perl.*#.*MANDATORY/m) { # ugly match
972 warn $@;
973 warn "mandatory extension failed to load, exiting.\n";
974 exit 1;
975 }
976 die $@;
977 }
978
979 push @EXTS, $pkg;
980}
981
982sub load_extensions { 948sub load_extensions {
949 cf::sync_job {
950 my %todo;
951
983 for my $ext (<$LIBDIR/*.ext>) { 952 for my $path (<$LIBDIR/*.ext>) {
984 next unless -r $ext; 953 next unless -r $path;
985 eval { 954
986 load_extension $ext; 955 $path =~ /([^\/\\]+)\.ext$/ or die "$path";
956 my $base = $1;
957 my $pkg = $1;
958 $pkg =~ s/[^[:word:]]/_/g;
959 $pkg = "ext::$pkg";
960
961 open my $fh, "<:utf8", $path
962 or die "$path: $!";
963
964 my $source = do { local $/; <$fh> };
965
966 my %ext = (
967 path => $path,
968 base => $base,
969 pkg => $pkg,
970 );
971
972 $ext{meta} = { map { split /=/, $_, 2 } split /\s+/, $1 }
973 if $source =~ /^#!.*?perl.*?#\s*(.*)$/;
974
975 $ext{source} =
976 "package $pkg; use strict; use utf8;\n"
977 . "#line 1 \"$path\"\n{\n"
978 . $source
979 . "\n};\n1";
980
981 $todo{$base} = \%ext;
982 }
983
984 my %done;
985 while (%todo) {
986 my $progress;
987
988 while (my ($k, $v) = each %todo) {
989 for (split /,\s*/, $ext{meta}{depends}) {
990 goto skip
991 unless exists $done{$_};
992 }
993
994 warn "... loading '$k' into '$v->{pkg}'\n";
995
996 unless (eval $v->{source}) {
997 my $msg = $@ ? "$v->{path}: $@\n"
998 : "extension disabled.\n";
999
1000 if (exists $v->{meta}{mandatory}) {
1001 warn $msg;
1002 warn "mandatory extension failed to load, exiting.\n";
1003 exit 1;
1004 }
1005
1006 die $msg;
1007 }
1008
1009 $done{$k} = delete $todo{$k};
1010 push @EXTS, $v->{pkg};
987 1 1011 }
988 } or warn "$ext not loaded: $@"; 1012
1013 skip:
1014 die "cannot load " . (join ", ", keys %todo) . ": unable to resolve dependencies\n"
1015 unless $progress;
1016 }
989 } 1017 };
990} 1018}
991 1019
992############################################################################# 1020#############################################################################
993 1021
994=head2 CORE EXTENSIONS 1022=head2 CORE EXTENSIONS
1779} 1807}
1780 1808
1781=item $maps = cf::map::tmp_maps 1809=item $maps = cf::map::tmp_maps
1782 1810
1783Returns an arrayref with all map paths of currently instantiated and saved 1811Returns an arrayref with all map paths of currently instantiated and saved
1784maps. 1812maps. May block.
1785 1813
1786=cut 1814=cut
1787 1815
1788sub tmp_maps() { 1816sub tmp_maps() {
1789 [ 1817 [
1790 map { 1818 map {
1791 utf8::decode $_; 1819 utf8::decode $_;
1792 !/\.(?:pst|meta)$/ && /^$PATH_SEP/o 1820 /\.map$/
1793 ? normalise $_ 1821 ? normalise $_
1794 : () 1822 : ()
1795 } @{ aio_readdir $TMPDIR or [] } 1823 } @{ aio_readdir $TMPDIR or [] }
1796 ] 1824 ]
1797} 1825}
1798 1826
1827=item $maps = cf::map::random_maps
1828
1829Returns an arrayref with all map paths of currently instantiated and saved
1830random maps. May block.
1831
1832=cut
1833
1834sub random_maps() {
1835 [
1836 map {
1837 utf8::decode $_;
1838 /\.map$/
1839 ? normalise "?random/$_"
1840 : ()
1841 } @{ aio_readdir $RANDOMDIR or [] }
1842 ]
1843}
1844
1799=item cf::map::unique_maps 1845=item cf::map::unique_maps
1800 1846
1801Returns an arrayref of paths of all shared maps that have 1847Returns an arrayref of paths of all shared maps that have
1802instantiated unique items. May block. 1848instantiated unique items. May block.
1803 1849
1805 1851
1806sub unique_maps() { 1852sub unique_maps() {
1807 [ 1853 [
1808 map { 1854 map {
1809 utf8::decode $_; 1855 utf8::decode $_;
1810 !/\.(?:pst|meta)$/ && /^$PATH_SEP/o 1856 /\.map$/
1811 ? normalise $_ 1857 ? normalise $_
1812 : () 1858 : ()
1813 } @{ aio_readdir $UNIQUEDIR or [] } 1859 } @{ aio_readdir $UNIQUEDIR or [] }
1814 ] 1860 ]
1815} 1861}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines