From 17a8ec28ad6a97f4c0c326a4b46deaf4d652851b Mon Sep 17 00:00:00 2001 From: Jay Allen Date: Mon, 4 Jul 2011 19:50:30 -0700 Subject: [PATCH] Perltidied --- .../lib/ConfigAssistant/Init.pm | 20 +- .../lib/ConfigAssistant/Plugin.pm | 321 ++-- .../lib/ConfigAssistant/Static.pm | 25 +- .../lib/ConfigAssistant/Util.pm | 44 +- .../lib/MT/Theme/Exporter.pm | 415 ++--- .../lib/ThemeExport/Plugin.pm | 103 +- .../lib/ThemeManager/DashboardWidget.pm | 2 +- .../lib/ThemeManager/Plugin.pm | 32 +- .../lib/ThemeManager/TemplateInstall.pm | 161 +- .../lib/ThemeManager/Util.pm | 61 +- build/l10n/validate.pl | 1 + build/make-l10n | 2 +- build/sample.pm | 6 +- dev/lib/Melody/Devel.pm | 2 +- dev/lib/Melody/Devel/Command/Relnotes.pm | 174 +- lib/MT.pm | 16 +- lib/MT/App.pm | 88 +- lib/MT/App/Comments.pm | 13 +- lib/MT/AtomServer.pm | 90 +- lib/MT/Auth/OpenID.pm | 5 +- lib/MT/BackupRestore/BackupFileHandler.pm | 6 +- lib/MT/BackupRestore/ManifestFileHandler.pm | 6 +- lib/MT/Bootstrap.pm | 6 + lib/MT/CMS/Asset.pm | 46 +- lib/MT/CMS/Comment.pm | 15 +- lib/MT/CMS/Entry.pm | 2 +- lib/MT/CMS/User.pm | 3 +- lib/MT/Config.pm | 19 +- lib/MT/ConfigMgr.pm | 54 +- lib/MT/Core.pm | 37 +- lib/MT/Image.pm | 67 +- lib/MT/Util.pm | 39 +- lib/MT/XMLRPCServer.pm | 6 +- t/00-compile.t | 2 + t/02-meta-new.t | 4 +- t/03-meta-new-author.t | 4 +- t/04-config.t | 168 +- t/09-image.t | 24 +- t/110-cms-permission.t | 1419 +++++++++-------- t/30-support-files.t | 46 +- t/33-driver.t | 3 +- t/92-pubqueue.t | 2 +- t/93-init_plugin.t | 150 +- t/93-plugins.t | 92 +- t/99-utils-misc.t | 123 +- t/lib/MT/Test.pm | 78 +- t/lib/Test/Output.pm | 814 +++++----- t/lib/Test/Output/Tie.pm | 16 +- t/plugins/IgnorePerl/IgnorePerl.pl | 23 +- t/plugins/stray.pl | 21 +- t/plugins/subfoldered/subfoldered.pl | 20 +- tools/convert-db | 12 +- tools/export-theme | 145 +- tools/populate | 37 +- tools/run-periodic-tasks | 2 +- 55 files changed, 2604 insertions(+), 2488 deletions(-) diff --git a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm index c8d2534d6..67aefb222 100644 --- a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm +++ b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm @@ -22,7 +22,7 @@ sub init_app { # been merged with Config Assistant, so is not needed anymore.) my $switch = $cfg->PluginSwitch || {}; $switch->{'AutoPrefs/config.yaml'} = $switch->{'AutoPrefs'} = 0; - $cfg->PluginSwitch( $switch ); + $cfg->PluginSwitch($switch); # FIXME This needs some commentary... init_options($app); @@ -32,14 +32,16 @@ sub init_app { # Static files only get copied during an upgrade. if ( $app->id eq 'upgrade' ) { + # Because no schema version is set, the upgrade process does nothing # during the plugin's initial install. So, in order to copy static # files on first run, we set an initial schema version which triggers # the framework. - my $schemas = $cfg->PluginSchemaVersion || {}; + my $schemas = $cfg->PluginSchemaVersion || {}; $schemas->{ $plugin->id } ||= '0.1'; + # $schemas->{$plugin->id} = '0.1'; ## UNCOMMENT TO TEST UPGRADE ## - $cfg->PluginSchemaVersion( $schemas ); + $cfg->PluginSchemaVersion($schemas); } # TODO - This should not have to reinstall a subroutine. It should invoke @@ -79,9 +81,9 @@ sub init_options { my $option = $r->{'template_sets'}->{$set}->{'options'}->{$opt}; - # To avoid option names that may collide with other - # options in other template sets settings are derived - # by combining the name of the template set and the + # To avoid option names that may collide with other + # options in other template sets settings are derived + # by combining the name of the template set and the # option's key. my $optname = $set . '_' . $opt; if ( _option_exists( $sig, $optname ) ) { @@ -91,7 +93,7 @@ sub init_options { else { # if ( my $default = $option->{default} ) { - # if ( !ref($default) + # if ( !ref($default) # && ( $default =~ /^\s*sub/ # || $default =~ /^\$/)) { # $default @@ -110,7 +112,7 @@ sub init_options { $obj->{'registry'}->{'settings'}->{$optname} = { scope => 'blog', %$option, }; } - } + } ## end else [ if ( _option_exists( $sig...))] } ## end foreach my $opt ( keys %{ $r...}) } ## end if ( $r->{'template_sets'...}) } # end foreach (@sets) @@ -184,7 +186,7 @@ sub load_tags { class => 'system', category => 'plugin', level => MT::Log::ERROR(), - } + } ); } } diff --git a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm index b0ca0e3b9..292f9b1ce 100644 --- a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm +++ b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm @@ -5,12 +5,13 @@ use warnings; use Carp qw( croak ); use MT::Util qw( relative_date offset_time offset_time_list epoch2ts - ts2epoch format_ts encode_html decode_html dirify ); + ts2epoch format_ts encode_html decode_html dirify ); use ConfigAssistant::Util qw( find_theme_plugin find_template_def find_option_def - find_option_plugin process_file_upload - plugin_static_web_path plugin_static_file_path ); + find_option_plugin process_file_upload + plugin_static_web_path plugin_static_file_path ); use JSON; + # use MT::Log::Log4perl qw( l4mtdump ); use Log::Log4perl qw( :resurrect ); our $logger; @@ -21,12 +22,12 @@ sub tag_plugin_static_web_path { if ( !$obj ) { return $ctx->error( - MT->translate( - "The plugin you specified '[_2]' in '[_1]' " - . "could not be found.", - $ctx->stash('tag'), - $sig - ) + MT->translate( + "The plugin you specified '[_2]' in '[_1]' " + . "could not be found.", + $ctx->stash('tag'), + $sig + ) ); } elsif ( $obj->registry('static_version') ) { @@ -37,13 +38,13 @@ sub tag_plugin_static_web_path { # TODO - perhaps this should default to: mt-static/plugins/$sig? return $ctx->error( - MT->translate( - "The plugin you specified '[_2]' in '[_1]' has not" - . "registered a static directory. Please use " - . " instead.", - $ctx->stash('tag'), - $sig - ) + MT->translate( + "The plugin you specified '[_2]' in '[_1]' has not" + . "registered a static directory. Please use " + . " instead.", + $ctx->stash('tag'), + $sig + ) ); } } ## end sub tag_plugin_static_web_path @@ -55,12 +56,12 @@ sub tag_plugin_static_file_path { if ( !$obj ) { return $ctx->error( - MT->translate( - "The plugin you specified '[_2]' in '[_1]' " - . "could not be found.", - $ctx->stash('tag'), - $sig - ) + MT->translate( + "The plugin you specified '[_2]' in '[_1]' " + . "could not be found.", + $ctx->stash('tag'), + $sig + ) ); } elsif ( $obj->registry('static_version') ) { @@ -69,12 +70,12 @@ sub tag_plugin_static_file_path { else { return $ctx->error( - MT->translate( - "The plugin you specified in '[_1]' has not " - . "registered a static directory. Please use " - . " instead.", - $_[0]->stash('tag') - ) + MT->translate( + "The plugin you specified in '[_1]' has not " + . "registered a static directory. Please use " + . " instead.", + $_[0]->stash('tag') + ) ); } } ## end sub tag_plugin_static_file_path @@ -364,25 +365,29 @@ sub save_config { if ( $result->{status} == ConfigAssistant::Util::ERROR() ) { return $app->error( "Error uploading file: " . $result->{message} ); - } elsif ( $result->{status} == ConfigAssistant::Util::NO_UPLOAD ) { - if ($param->{$var.'-clear'} && $data->{$var}) { + } + elsif ( + $result->{status} == ConfigAssistant::Util::NO_UPLOAD ) + { + if ( $param->{ $var . '-clear' } && $data->{$var} ) { my $old = MT->model('asset')->load( $data->{$var} ); $old->remove if $old; $param->{$var} = undef; } else { - + # The user hasn't changed the file--keep it. $param->{$var} = $data->{$var}; } - } else { + } + else { if ( $data->{$var} ) { my $old = MT->model('asset')->load( $data->{$var} ); $old->remove if $old; } $param->{$var} = $result->{asset}->{id}; } - } + } ## end if ( $opt->{type} eq 'file') my $old = $data->{$var}; my $new = $param->{$var}; my $has_changed @@ -391,7 +396,7 @@ sub save_config { || ( defined $new and $old ne $new ); ###l4p $logger->debug('$has_changed: '.$has_changed); - # If the field data has changed, and if the field uses the + # If the field data has changed, and if the field uses the # "republish" key, we want to republish the specified templates. # Add the specified templates to $repub_queue so that they can # be republished later. @@ -403,6 +408,7 @@ sub save_config { $data->{$var} = $new ? $new : undef; if ($has_changed) { $opt->{'basename'} = $var; + #MT->log("Triggering: " . 'options_change.option.' . $var ); $app->run_callbacks( 'options_change.option.' . $var, $app, $opt, $old, $new ); @@ -417,49 +423,51 @@ sub save_config { $app->run_callbacks( 'options_change.plugin.' . $plugin->id, $app, $plugin ); } - + # Index templates that have been flagged should be republished. use MT::WeblogPublisher; foreach ( keys %$repub_queue ) { my $tmpl = MT->model('template') ->load( { blog_id => $blog_id, identifier => $_, } ); - if (!$tmpl) { + if ( !$tmpl ) { MT->log( { blog_id => $blog_id, - level => '2', # Warning + level => '2', # Warning message => "Config Assistant could not find a " - . "template with the identifier " . $_, - } + . "template with the identifier " + . $_, + } ); next; } - my $result = $app->rebuild_indexes( - Blog => $app->blog, - Template => $tmpl, - Force => 1, - ); + my $result = + $app->rebuild_indexes( + Blog => $app->blog, + Template => $tmpl, + Force => 1, + ); # Report on the success/failure of the template republishing. - my ($message, $level); + my ( $message, $level ); if ($result) { - $message = "Config Assistant: Republishing template " - . $tmpl->name; - $level = '1'; # Info + $message + = "Config Assistant: Republishing template " . $tmpl->name; + $level = '1'; # Info } else { - $message = "Config Assistant could not republish template " - . $tmpl->name; - $level = '4'; # Error + $message = "Config Assistant could not republish template " + . $tmpl->name; + $level = '4'; # Error } MT->log( { - blog_id => $blog_id, - level => $level, - message => $message, - } + blog_id => $blog_id, + level => $level, + message => $message, + } ); - } + } ## end foreach ( keys %$repub_queue) $pdata->data($data); MT->request( 'plugin_config.' . $plugin->id, undef ); $pdata->save() or die $pdata->errstr; @@ -500,14 +508,19 @@ sub type_file { . "\">view | remove

"; } else { - $html .= "

Selected asset could not be found. reset

"; + $html + .= "

Selected asset could not be found. reset

"; } } - $html .= " \n" . - " \n"; + $html + .= " \n" + . " \n"; $html .= "\n"; return $html; @@ -668,19 +681,19 @@ sub type_entry { my ( $ctx, $field_id, $field, $value ) = @_; my $out; my $obj_class = $ctx->stash('object_class') || 'entry'; - my ($obj, $obj_name, $obj_id); - - # The $value is the object ID. Only if $value exists should we try to + my ( $obj, $obj_name, $obj_id ); + + # The $value is the object ID. Only if $value exists should we try to # load the object. Otherwise, the most recent entry/page is loaded # and the $obj_name is incorrectly populated with the most recent object # title. This way, $obj_name is blank if there is no $value, which is # clearer to the user. if ($value) { - $obj = MT->model($obj_class)->load($value); - $obj_name = ( $obj ? $obj->title : '' ) || ''; - $obj_id = ( $obj ? $obj->id : 0 ) || ''; + $obj = MT->model($obj_class)->load($value); + $obj_name = ( $obj ? $obj->title : '' ) || ''; + $obj_id = ( $obj ? $obj->id : 0 ) || ''; } - my $blog_id = $field->{all_blogs} ? 0 : $app->blog->id; + my $blog_id = $field->{all_blogs} ? 0 : $app->blog->id; unless ( $ctx->var('entry_chooser_js') ) { $out .= < @@ -696,10 +709,10 @@ sub type_entry { EOH $ctx->var( 'entry_chooser_js', 1 ); } - my $class = MT->model($obj_class); - my $label = $class->class_label; + my $class = MT->model($obj_class); + my $label = $class->class_label; my $label_lc = lc($label); - $ctx->var( 'entry_class_label', $label ); + $ctx->var( 'entry_class_label', $label ); $ctx->var( 'entry_class_labelp', $class->class_label_plural ); $out .= < @@ -712,7 +725,7 @@ EOH EOH - $ctx->stash('object_class',''); + $ctx->stash( 'object_class', '' ); return $out; } ## end sub type_entry @@ -729,8 +742,8 @@ sub type_entry_or_page { # title. This way, $obj_name is blank if there is no $value, which is # clearer to the user. if ($value) { - $obj = MT->model($obj_class)->load($value); - $obj_name = ( $obj ? $obj->title : '' ) || ''; + $obj = MT->model($obj_class)->load($value); + $obj_name = ( $obj ? $obj->title : '' ) || ''; $obj_class = $obj->class; } my $blog_id = $field->{all_blogs} ? 0 : $app->blog->id; @@ -750,9 +763,9 @@ EOH $ctx->var( 'entry_chooser_js', 1 ); } my $class_label = $obj->class_label; - my $preview = $value ? "$obj_name ( $class_label )" : ""; - my $class = MT->model($obj_class); - my $label = 'Entry or Page'; + my $preview = $value ? "$obj_name ( $class_label )" : ""; + my $class = MT->model($obj_class); + my $label = 'Entry or Page'; $ctx->var( 'entry_class_label', $label ); $out .= < @@ -768,7 +781,7 @@ EOH # $ctx->stash('object_class',''); return $out; -} +} ## end sub type_entry_or_page sub type_tagged_entry { @@ -1177,7 +1190,7 @@ sub _hdlr_field_category_list { my ( $ctx, $args, $cond ) = @_; my $field = $ctx->stash('field') or return _no_field($ctx); my $value = _get_field_value($ctx); - my @ids = ref($value) eq 'ARRAY' ? @$value : ($value); + my @ids = ref($value) eq 'ARRAY' ? @$value : ($value); my $class = $ctx->stash('obj_class'); my @categories = MT->model($class)->load( { id => \@ids } ); @@ -1267,9 +1280,9 @@ sub _hdlr_field_text_group { my $vars = $ctx->{__stash}{vars}; my $count = 0; foreach (@$list) { - local $vars->{'label'} = $_->{'label'}; - local $vars->{'__first__'} = ( $count++ == 0 ); - local $vars->{'__last__'} = ( $count == @$list ); + local $vars->{'label'} = $_->{'label'}; + local $vars->{'__first__'} = ( $count++ == 0 ); + local $vars->{'__last__'} = ( $count == @$list ); defined( $out .= $ctx->slurp( $args, $cond ) ) or return; } return $out; @@ -1497,26 +1510,28 @@ sub plugin_options { } ## end sub plugin_options sub entry_search_api_prep { - return _search_api_prep('entry',@_); + return _search_api_prep( 'entry', @_ ); } + sub page_search_api_prep { - return _search_api_prep('page',@_); + return _search_api_prep( 'page', @_ ); } + sub _search_api_prep { my ( $type, $terms, $args, $blog_id ) = @_; my $app = MT->instance; my $q = $app->can('query') ? $app->query : $app->param; - $terms->{blog_id} = $blog_id if $blog_id; + $terms->{blog_id} = $blog_id if $blog_id; if ( $type ne 'template' ) { - my $search_api = $app->registry("search_apis"); - my $api = $search_api->{$type}; - my $date_col = $api->{date_column} || 'created_on'; + my $search_api = $app->registry("search_apis"); + my $api = $search_api->{$type}; + my $date_col = $api->{date_column} || 'created_on'; $args->{sort} = $date_col; $args->{direction} = 'descend'; } return unless $app->mode eq 'ca_config_entry'; - $terms->{status} = $q->param('status') if ( $q->param('status') ); - $terms->{class} = $app->param('class'); + $terms->{status} = $q->param('status') if ( $q->param('status') ); + $terms->{class} = $app->param('class'); } #sub entry_search_api_prep { @@ -1535,9 +1550,9 @@ sub list_entry_mini { or return "Invalid request: unknown class $obj_type"; my $terms; - $terms->{class} = $obj_type; + $terms->{class} = $obj_type; $terms->{blog_id} = $blog_id if $blog_id; - $terms->{status} = 2 if $obj_type eq 'entry' || $obj_type eq 'page'; + $terms->{status} = 2 if $obj_type eq 'entry' || $obj_type eq 'page'; my %args = ( sort => 'authored_on', direction => 'descend', ); @@ -1545,19 +1560,19 @@ sub list_entry_mini { or die "OMG NO COMPONENT!?!"; my $tmpl = $plugin->load_tmpl('entry_list.mtml'); - $tmpl->param('entry_class_labelp', $pkg->class_label_plural); - $tmpl->param('entry_class_label', $pkg->class_label); - $tmpl->param('obj_type', $obj_type); + $tmpl->param( 'entry_class_labelp', $pkg->class_label_plural ); + $tmpl->param( 'entry_class_label', $pkg->class_label ); + $tmpl->param( 'obj_type', $obj_type ); return $app->listing( { type => $obj_type, template => $tmpl, params => { - panel_searchable => 1, - edit_blog_id => $blog_id, - edit_field => $q->param('edit_field'), - search => $q->param('search'), - blog_id => $blog_id, - class => $obj_type, + panel_searchable => 1, + edit_blog_id => $blog_id, + edit_field => $q->param('edit_field'), + search => $q->param('search'), + blog_id => $blog_id, + class => $obj_type, }, code => sub { my ( $obj, $row ) = @_; @@ -1619,10 +1634,7 @@ sub list_entry_or_page { my $type = 'entry'; my $pkg = $app->model($type) or return "Invalid request."; - my %terms = ( - status => '2', - class => '*', - ); + my %terms = ( status => '2', class => '*', ); my @blog_ids; if ( $blog_ids == 'all' ) { @@ -1636,78 +1648,75 @@ sub list_entry_or_page { $terms{blog_id} = [@blog_ids]; } - my %args = ( - sort => 'authored_on', - direction => 'descend', - ); + my %args = ( sort => 'authored_on', direction => 'descend', ); my $plugin = MT->component('ConfigAssistant') or die "OMG NO COMPONENT!?!"; - my $tmpl = $plugin->load_tmpl('entry_or_page_list.mtml'); + my $tmpl = $plugin->load_tmpl('entry_or_page_list.mtml'); $tmpl->param( 'type', $type ); - return $app->listing( - { type => 'entry', - template => $tmpl, - params => { - panel_searchable => 1, - edit_blog_id => $blog_ids, - edit_field => $app->param('edit_field'), - search => $app->param('search'), - blog_id => $blog_ids, - }, - code => sub { - my ( $obj, $row ) = @_; - $row->{ 'status_' - . lc MT::Entry::status_text( $obj->status ) } = 1; - $row->{entry_permalink} = $obj->permalink - if $obj->status == MT::Entry->RELEASE(); - if ( my $ts = $obj->authored_on ) { - my $date_format = MT::App::CMS->LISTING_DATE_FORMAT(); - my $datetime_format - = MT::App::CMS->LISTING_DATETIME_FORMAT(); - $row->{created_on_formatted} - = format_ts( $date_format, $ts, $obj->blog, + return $app->listing( { + type => 'entry', + template => $tmpl, + params => { + panel_searchable => 1, + edit_blog_id => $blog_ids, + edit_field => $app->param('edit_field'), + search => $app->param('search'), + blog_id => $blog_ids, + }, + code => sub { + my ( $obj, $row ) = @_; + $row->{ 'status_' . lc MT::Entry::status_text( $obj->status ) } + = 1; + $row->{entry_permalink} = $obj->permalink + if $obj->status == MT::Entry->RELEASE(); + if ( my $ts = $obj->authored_on ) { + my $date_format = MT::App::CMS->LISTING_DATE_FORMAT(); + my $datetime_format + = MT::App::CMS->LISTING_DATETIME_FORMAT(); + $row->{created_on_formatted} + = format_ts( $date_format, $ts, $obj->blog, $app->user ? $app->user->preferred_language : undef ); - $row->{created_on_time_formatted} - = format_ts( $datetime_format, $ts, $obj->blog, + $row->{created_on_time_formatted} + = format_ts( $datetime_format, $ts, $obj->blog, $app->user ? $app->user->preferred_language : undef ); - $row->{created_on_relative} - = relative_date( $ts, time, $obj->blog ); - $row->{kind} = ucfirst( $obj->class ); - } - return $row; - }, - terms => \%terms, - args => \%args, - limit => 10, + $row->{created_on_relative} + = relative_date( $ts, time, $obj->blog ); + $row->{kind} = ucfirst( $obj->class ); + } + return $row; + }, + terms => \%terms, + args => \%args, + limit => 10, } ); -} +} ## end sub list_entry_or_page sub select_entry_or_page { my $app = shift; - my $entry_id = $app->param('id') - or return $app->errtrans('No id'); + my $entry_id = $app->param('id') or return $app->errtrans('No id'); MT->log('boo'); my $entry = MT->model('entry')->load($entry_id) - or return $app->errtrans( 'No entry or page #[_1]', $entry_id ); + or return $app->errtrans( 'No entry or page #[_1]', $entry_id ); my $edit_field = $app->param('edit_field') - or return $app->errtrans('No edit_field'); + or return $app->errtrans('No edit_field'); my $plugin = MT->component('ConfigAssistant') - or die "OMG NO COMPONENT!?!"; - my $tmpl = $plugin->load_tmpl( - 'select_entry.mtml', - { entry_id => $entry->id, - entry_title => $entry->title, - entry_class => $entry->class_label, - edit_field => $edit_field, - } + or die "OMG NO COMPONENT!?!"; + my $tmpl = $plugin->load_tmpl( + 'select_entry.mtml', + { + entry_id => $entry->id, + entry_title => $entry->title, + entry_class => $entry->class_label, + edit_field => $edit_field, + } ); return $tmpl; -} +} ## end sub select_entry_or_page sub xfrm_cfg_plugin_param { diff --git a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Static.pm b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Static.pm index 2b4f03018..e2fdb66c1 100644 --- a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Static.pm +++ b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Static.pm @@ -28,18 +28,18 @@ sub upgrade { # The saved version my $ver = MT->config('PluginStaticVersion'); + # $ver = undef; ### UNCOMMENT TO TEST STATIC UPGRADE ### # Check to see if $plugin->id is valid. If it's not, we need to # undef $ver so that we don't try to grab the static_version # variable. $plugin->id seems to throw an error for some Six # Apart-originated plugins. I don't know why. - my $saved_version = 0.1; # Default - my $plugin_id = eval { $plugin->id } - or undef $ver; + my $saved_version = 0.1; # Default + my $plugin_id = eval { $plugin->id } or undef $ver; if ( $ver && $plugin_id ) { $saved_version = $ver->{$plugin_id} - if defined $ver->{$plugin_id}; + if defined $ver->{$plugin_id}; } if ( $static_version > $saved_version ) { @@ -72,13 +72,13 @@ sub upgrade { $cfg->set( 'PluginStaticVersion', $plugin_id . '=' . $static_version, 1 ); $self->progress( - $self->translate_escape( - "Plugin '[_1]' upgraded successfully to " - . "version [_2] (static version [_3]).", - $plugin->label, - $plugin->version || '-', - $static_version - ) + $self->translate_escape( + "Plugin '[_1]' upgraded successfully to " + . "version [_2] (static version [_3]).", + $plugin->label, + $plugin->version || '-', + $static_version + ) ); } ## end if ( $static_version >...) } ## end for my $sig ( keys %MT::Plugins) @@ -172,7 +172,8 @@ sub _make_dir { my $fmgr = MT::FileMgr->new('Local') or return MT::FileMgr->errstr; my $app = MT->instance; - $dir = File::Spec->catfile( $app->static_file_path, 'support', 'plugins', $dir ); + $dir = File::Spec->catfile( $app->static_file_path, 'support', 'plugins', + $dir ); if ( $fmgr->mkpath($dir) ) { # Success! diff --git a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Util.pm b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Util.pm index 10de13529..6e520031d 100644 --- a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Util.pm +++ b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Util.pm @@ -3,11 +3,10 @@ package ConfigAssistant::Util; use strict; use warnings; use base 'Exporter'; -our @EXPORT_OK - = qw( find_theme_plugin find_template_def find_option_def - find_option_plugin process_file_upload - plugin_static_web_path plugin_static_file_path - ERROR SUCCESS OVERWRITE NO_UPLOAD ); +our @EXPORT_OK = qw( find_theme_plugin find_template_def find_option_def + find_option_plugin process_file_upload + plugin_static_web_path plugin_static_file_path + ERROR SUCCESS OVERWRITE NO_UPLOAD ); use MT::Util qw( encode_url ); @@ -26,8 +25,9 @@ sub plugin_static_web_path { sub plugin_static_file_path { my ($plugin) = @_; - return File::Spec->catdir( MT->instance->static_file_path, - 'support', 'plugins', $plugin->id ); + return + File::Spec->catdir( MT->instance->static_file_path, + 'support', 'plugins', $plugin->id ); } sub process_file_upload { @@ -61,8 +61,8 @@ sub process_file_upload { || $q->param('overwrite_no'); my %param = ( middle_path => $q->param('middle_path') || '', - site_path => $q->param('site_path') || '', - extra_path => $q->param('extra_path') || '', + site_path => $q->param('site_path') || '', + extra_path => $q->param('extra_path') || '', upload_mode => $app->mode, ); return { @@ -123,8 +123,9 @@ sub process_file_upload { $root_path = $app->blog->site_path; $base_url = $app->blog->site_url; $fmgr = $app->blog->file_mgr; - $blog_id = $app->blog->id; # the resulting asset will be added to this context - $format = '%r'; + $blog_id = $app->blog + ->id; # the resulting asset will be added to this context + $format = '%r'; } elsif ( lc($scope) eq 'archive' ) { @@ -138,7 +139,8 @@ sub process_file_upload { $root_path = $app->blog->archive_path; $base_url = $app->blog->archive_url; $fmgr = $app->blog->file_mgr; - $blog_id = $app->blog->id; # the resulting asset will be added to this context + $blog_id = $app->blog + ->id; # the resulting asset will be added to this context $format = '%a'; } @@ -147,8 +149,11 @@ sub process_file_upload { $root_path = File::Spec->catdir( $app->static_file_path, 'support' ); $base_url = $app->static_path . '/support'; $fmgr = MT::FileMgr->new('Local'); - $blog_id = $app->blog ? $app->blog->id : 0; # the resulting asset will be added to this context - $format = File::Spec->catfile( '%s', 'support' ); + $blog_id + = $app->blog + ? $app->blog->id + : 0; # the resulting asset will be added to this context + $format = File::Spec->catfile( '%s', 'support' ); } else { @@ -306,13 +311,10 @@ sub process_file_upload { $asset->image_height($h); } $asset->save - or return { - status => ERROR(), - message => - $app->translate( - "Error saving asset: [_1]", - $asset->errstr - ) + or return { + status => ERROR(), + message => + $app->translate( "Error saving asset: [_1]", $asset->errstr ) }; $app->run_callbacks( 'cms_post_save.asset', $app, $asset, $original ); diff --git a/addons/ThemeExport.plugin/lib/MT/Theme/Exporter.pm b/addons/ThemeExport.plugin/lib/MT/Theme/Exporter.pm index 8a45f108d..141d20604 100644 --- a/addons/ThemeExport.plugin/lib/MT/Theme/Exporter.pm +++ b/addons/ThemeExport.plugin/lib/MT/Theme/Exporter.pm @@ -34,7 +34,7 @@ sub new { my $params = shift; my $self = {}; foreach my $prop ( - qw( id key pack_name pack_description pack_version system_cf system_fd + qw( id key pack_name pack_description pack_version system_cf system_fd dryrun verbose logger app author_name author_link basedir outdir zip ) ) { @@ -61,11 +61,10 @@ sub new { # TODO - error check #my @formats = MT::Util::Archive->available_formats(); require MT::Util::Archive; - $self->{'zipfilepath'} = - File::Spec->catfile( $self->{'outdir'}, - $self->{'basedir'} . ".zip" ); - $self->{'ziparchive'} = - MT::Util::Archive->new( 'zip', $self->{'zipfilepath'} ); + $self->{'zipfilepath'} = File::Spec->catfile( $self->{'outdir'}, + $self->{'basedir'} . ".zip" ); + $self->{'ziparchive'} + = MT::Util::Archive->new( 'zip', $self->{'zipfilepath'} ); } @@ -74,19 +73,20 @@ sub new { $opts{'author_name'} = $self->{'author_name'} if $self->{'author_name'}; $self->{'yaml'} = YAML::Tiny->new; - $self->{'yaml'}->[0] = { - id => $self->{'id'}, - key => $self->{'key'}, - name => $self->{'pack_name'}, - description => $self->{'pack_description'}, - %opts - }; + $self->{'yaml'}->[0] + = { + id => $self->{'id'}, + key => $self->{'key'}, + name => $self->{'pack_name'}, + description => $self->{'pack_description'}, + %opts + }; # End init code bless $self, $class; return $self; -} +} ## end sub new sub _archive_file { my $self = shift; @@ -105,9 +105,9 @@ sub write_config { sub write { my $self = shift; - my $filepath = - File::Spec->catfile( $self->{'outdir'}, $self->{'basedir'}, 'plugins', - $self->{'key'}, 'config.yaml' ); + my $filepath + = File::Spec->catfile( $self->{'outdir'}, $self->{'basedir'}, 'plugins', + $self->{'key'}, 'config.yaml' ); $self->_debug(" - Writing config.yaml file $filepath"); unless ( $self->_is_dryrun() ) { my $header = ''; @@ -127,16 +127,16 @@ sub write { if ( $self->{'zip'} ) { $self->_archive_file( - $self->{'outdir'}, - File::Spec->catfile( - $self->{'basedir'}, 'plugins', - $self->{'key'}, 'config.yaml' - ) + $self->{'outdir'}, + File::Spec->catfile( + $self->{'basedir'}, 'plugins', + $self->{'key'}, 'config.yaml' + ) ); $self->{'ziparchive'}->close(); } - } -} + } ## end unless ( $self->_is_dryrun...) +} ## end sub write sub export { my $self = shift; @@ -151,8 +151,8 @@ sub export { # Initialize the data structure for the current template set # we are exporting. $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id} = { - label => $name, - base_path => File::Spec->catdir( 'templates', $ts_id ) + label => $name, + base_path => File::Spec->catdir( 'templates', $ts_id ) }; # Create a shortcut to our template set node, this is in essense a cursor @@ -163,22 +163,21 @@ sub export { # under the theme pack's 'templates' directory. my $templates_path = File::Spec->catdir( $self->{'outdir'}, $self->{'basedir'}, 'plugins', - $self->{'key'}, 'templates', $ts_id ); + $self->{'key'}, 'templates', $ts_id ); unless ( $self->_is_dryrun() ) { $self->{'fmgr'}->exists($templates_path) or $self->{'fmgr'}->mkpath($templates_path) or die sprintf( "Could not make path %s: %s\n", - $templates_path, $self->{'fmgr'}->errstr ); + $templates_path, $self->{'fmgr'}->errstr ); } # TODO - static files need utilize config assistant's new static file structure - my $from = - File::Spec->catdir( _static_file_path( $self->{'app'} ), $static ); + my $from + = File::Spec->catdir( _static_file_path( $self->{'app'} ), $static ); if ( -e $from && $static ) { - my $to = - File::Spec->catdir( $self->{'outdir'}, $self->{'basedir'}, - 'mt-static', $static ); + my $to = File::Spec->catdir( $self->{'outdir'}, $self->{'basedir'}, + 'mt-static', $static ); $self->_debug( 'Copying static files from ' . $from . ' to ' . $to ); unless ( $self->_is_dryrun() ) { $self->{'fmgr'}->mkpath($to); @@ -200,17 +199,17 @@ sub export { foreach map { @{ _template_group( $blog_id, $_ ) } } ( $set_type, 'all' ); - # Store the provided configuration data in the node - # corresponding to the template's type and basename. - # REMOVED because it is in _process_templates - # $self->{'current_ts'}->{templates}->{ $cfg->{type} }->{ $cfg->{basename} } - # = $cfg->{data}; + # Store the provided configuration data in the node + # corresponding to the template's type and basename. + # REMOVED because it is in _process_templates + # $self->{'current_ts'}->{templates}->{ $cfg->{type} }->{ $cfg->{basename} } + # = $cfg->{data}; $self->_process_export_queue(); $self->_process_custom_fields( $blog_id, $ts_id ); $self->_process_field_day_fields( $blog_id, $ts_id ); -} +} ## end sub export =head2 @@ -235,18 +234,20 @@ sub _process_export_queue { # FIXME: this is hard coded to global templates based upon the assumption that # only global templates will be automatically included # my $cfg = $self->_process_templates( $inc->{'blog_id'}, 'global', { - my $cfg = $self->_process_templates( - 0, 'global', - { type => 'module', - basename => dirify( $inc->{'name'} ), - load_args => [ { blog_id => 0, id => $inc->{'id'} } ] - } - ); + my $cfg = + $self->_process_templates( + 0, 'global', + { + type => 'module', + basename => dirify( $inc->{'name'} ), + load_args => [ { blog_id => 0, id => $inc->{'id'} } ] + } + ); $seen{ $inc->{id} } = 1; } - } -} + } ## end foreach my $inc ( sort { $a...}) +} ## end sub _process_export_queue =head2 @@ -266,31 +267,34 @@ sub _template_group { # Blog-level templates # blog => [ { - type => 'index', - load_args => { %blog_id, type => 'index' }, - config => sub { - { outfile => $_[0]->outfile, - rebuild_me => $_[0]->rebuild_me - }; - }, + type => 'index', + load_args => { %blog_id, type => 'index' }, + config => sub { + { + outfile => $_[0]->outfile, + rebuild_me => $_[0]->rebuild_me + }; + }, }, - { type => 'archive', - config => \&_templatemap_config, - load_args => [ - { %blog_id, type => 'archive' } => -or => - { %blog_id, type => 'individual' } => -or => - { %blog_id, type => 'page' }, - ], + { + type => 'archive', + config => \&_templatemap_config, + load_args => [ + { %blog_id, type => 'archive' } => -or => + { %blog_id, type => 'individual' } => -or => + { %blog_id, type => 'page' }, + ], }, - { type => 'system', - basename => sub { $_[0]->type }, - load_args => [ - { %blog_id, type => 'popup_image' } => -or => - { %blog_id, type => 'dynamic_error' } => -or => - { %blog_id, type => 'search_results' } => -or => - { %blog_id, type => 'comment_preview' } => -or => - { %blog_id, type => 'comment_response' } - ], + { + type => 'system', + basename => sub { $_[0]->type }, + load_args => [ + { %blog_id, type => 'popup_image' } => -or => + { %blog_id, type => 'dynamic_error' } => -or => + { %blog_id, type => 'search_results' } => -or => + { %blog_id, type => 'comment_preview' } => -or => + { %blog_id, type => 'comment_response' } + ], } ], @@ -298,37 +302,42 @@ sub _template_group { # Global shared templates # global => [ { - type => 'system', - basename => sub { $_[0]->type }, - load_args => [ - { %blog_id, type => 'login_form' } => -or => - { %blog_id, type => 'profile_view' } => -or => - { %blog_id, type => 'profile_feed' } => -or => - { %blog_id, type => 'register_form' } => -or => - { %blog_id, type => 'profile_error' } => -or => - { %blog_id, type => 'profile_edit_form' } => -or => - { %blog_id, type => 'password_reset_form' } => -or => - { %blog_id, type => 'register_confirmation' } - ], - }, - { type => 'email', - load_args => { %blog_id, type => 'email' }, - }, + type => 'system', + basename => sub { $_[0]->type }, + load_args => [ + { %blog_id, type => 'login_form' } => -or => + { %blog_id, type => 'profile_view' } => -or => + { %blog_id, type => 'profile_feed' } => -or => + { %blog_id, type => 'register_form' } => -or => + { %blog_id, type => 'profile_error' } => -or => + { %blog_id, type => 'profile_edit_form' } => + -or => + { %blog_id, type => 'password_reset_form' } => + -or => + { %blog_id, type => 'register_confirmation' } + ], + }, + { + type => 'email', + load_args => { %blog_id, type => 'email' }, + }, ], # # Templates found in both the global shared and blog sets # all => [ { - type => 'module', - load_args => { %blog_id, type => 'custom' }, - }, - { type => 'widget', - load_args => { %blog_id, type => 'widget' }, - }, - { type => 'widgetset', - load_args => { %blog_id, type => 'widgetset' }, - }, + type => 'module', + load_args => { %blog_id, type => 'custom' }, + }, + { + type => 'widget', + load_args => { %blog_id, type => 'widget' }, + }, + { + type => 'widgetset', + load_args => { %blog_id, type => 'widgetset' }, + }, ], ); @@ -339,7 +348,7 @@ sub _template_group { unless exists $template_groups{$key}; return $template_groups{$key}; -} +} ## end sub _template_group sub _process_templates { my $self = shift; @@ -357,7 +366,7 @@ sub _process_templates { # use Data::Dumper; # $self->_debug(Dumper($t)); $self->_debug( sprintf ' - Creating %s: %s', - $args->{type}, $t->name ); + $args->{type}, $t->name ); my $basename ||= $t->identifier || _create_basename( $t->name ); @@ -377,8 +386,7 @@ sub _process_templates { my $includes = $self->_find_includes($t); foreach my $i (@$includes) { - push @{ $self->{'export_queue'} }, $i - if ( $i->{blog_id} eq 0 ); + push @{ $self->{'export_queue'} }, $i if ( $i->{blog_id} eq 0 ); # TODO - for now it might be best if this only processed # global templates? @@ -387,20 +395,30 @@ sub _process_templates { # Write the template text out to a file within the plugin envelope if ( $self->_write_tmpl( $t, $ts_id, $args->{type}, $basename ) ) { - print "Wrote template " . $t->name . " (".$t->type.",build=".$t->build_type.")\n"; + print "Wrote template " + . $t->name . " (" + . $t->type + . ",build=" + . $t->build_type . ")\n"; + # Using the template in context, compile the YAML config my $cfg = { - label => $t->name, - filename => File::Spec->catfile( $args->{type}, $basename . '.mtml' ), - ($t->type eq 'index' && $t->build_type != MT::PublishOption::ONDEMAND()) ? ( build_type => $t->build_type ) : (), + label => $t->name, + filename => + File::Spec->catfile( $args->{type}, $basename . '.mtml' ), + ( + $t->type eq 'index' + && $t->build_type != MT::PublishOption::ONDEMAND() + ) ? ( build_type => $t->build_type ) : (), }; - if ($t->type =~ /^(module|widget|custom)$/) { - $cfg->{'include_with_ssi'} = 1 if ($t->include_with_ssi); + if ( $t->type =~ /^(module|widget|custom)$/ ) { + $cfg->{'include_with_ssi'} = 1 if ( $t->include_with_ssi ); foreach (qw( expire_type expire_event expire_interval )) { - my $var = 'cache_'.$_; - if (my $val = $t->$var()) { + my $var = 'cache_' . $_; + if ( my $val = $t->$var() ) { $cfg->{cache}->{$_} = $val; - $cfg->{cache}->{$_} *= 60 if ($_ eq 'expire_interval'); + $cfg->{cache}->{$_} *= 60 + if ( $_ eq 'expire_interval' ); } } } @@ -417,10 +435,10 @@ sub _process_templates { # corresponding to the template's type and basename. if ( $blog_id == 0 ) { unless ( $self->{'yaml'}->[0]->{'default_templates'} - ->{'base_path'} ) + ->{'base_path'} ) { - $self->{'yaml'}->[0]->{'default_templates'} - ->{'base_path'} = 'templates/global'; + $self->{'yaml'}->[0]->{'default_templates'}->{'base_path'} + = 'templates/global'; } $self->{'yaml'}->[0]->{'default_templates'} ->{ 'global:' . $args->{'type'} }->{$basename} = $cfg; @@ -429,9 +447,9 @@ sub _process_templates { $self->{'current_ts'}->{'templates'}->{ $args->{'type'} } ->{$basename} = $cfg; } - } - } -} + } ## end if ( $self->_write_tmpl...) + } ## end while ( my $t = $iter->) +} ## end sub _process_templates sub _templatemap_config { my $t = shift; @@ -442,18 +460,20 @@ sub _templatemap_config { my $type = lc( $map->archive_type ); $type =~ s/ /-/g; $mappings->{$type} = { - archive_type => $map->archive_type, - preferred => $map->is_preferred, - $map->build_type != MT::PublishOption::ONDEMAND() ? (build_type => $map->build_type) : (), - $map->file_template - && $map->file_template ne '~' && $map->file_template ne '' - ? ( file_template => $map->file_template ) - : (), + archive_type => $map->archive_type, + preferred => $map->is_preferred, + $map->build_type != MT::PublishOption::ONDEMAND() + ? ( build_type => $map->build_type ) + : (), + $map->file_template + && $map->file_template ne '~' && $map->file_template ne '' + ? ( file_template => $map->file_template ) + : (), }; } return { mappings => $mappings }; -} +} ## end sub _templatemap_config sub _create_basename { my $name = shift; @@ -501,24 +521,27 @@ sub _write_tmpl { unless ($basename) { $self->_debug( - sprintf 'No template basename for template "%s". Skipping...', - $tmpl->name ); + sprintf 'No template basename for template "%s". Skipping...', + $tmpl->name ); return; } if ( $self->{'created'}{"$ts_id/$type/$basename"} ) { $self->_error( - sprintf - 'Template basename "%s" previously used for template "%s".' - . ' Skipping...', - "$ts_id/$type/$basename", $tmpl->name + sprintf + 'Template basename "%s" previously used for template "%s".' + . ' Skipping...', + "$ts_id/$type/$basename", $tmpl->name ); return; } - my $fn = - File::Spec->catfile( $self->{'basedir'}, 'plugins', $self->{'key'}, - 'templates', $ts_id, $type, $basename . '.mtml' ); + my $fn = File::Spec->catfile( + $self->{'basedir'}, 'plugins', + $self->{'key'}, 'templates', + $ts_id, $type, + $basename . '.mtml' + ); my $fn_abs = File::Spec->catfile( $self->{'outdir'}, $fn ); $self->_debug("\t-- Writing template text file out to $fn"); @@ -526,7 +549,7 @@ sub _write_tmpl { $self->{'fmgr'}->exists( dirname($fn_abs) ) or $self->{'fmgr'}->mkpath( dirname($fn_abs) ) or die sprintf( "Could not make path %s: %s\n", - dirname($fn_abs), $self->{'fmgr'}->errstr ); + dirname($fn_abs), $self->{'fmgr'}->errstr ); open FILE, ">$fn_abs" or die "Could not open $fn_abs for writing: $!\n"; @@ -535,7 +558,7 @@ sub _write_tmpl { } $self->_archive_file( $self->{'outdir'}, $fn ); $self->{'created'}{"$ts_id/$type/$basename"} = $tmpl->name; -} +} ## end sub _write_tmpl sub _find_includes { my $self = shift; @@ -554,83 +577,83 @@ sub _find_includes { next if exists $seen{$type}{$mod}; $seen{$type}{$mod} = 1; my $other = MT->model('template')->load( { - blog_id => ( - $tag->[1]->{global} - ? 0 - : [ $obj->blog_id, 0 ] - ), - name => $mod, - type => $type, - }, - { sort => 'blog_id', - direction => 'descend', - } + blog_id => ( + $tag->[1]->{global} + ? 0 + : [ $obj->blog_id, 0 ] + ), + name => $mod, + type => $type, + }, + { + sort => 'blog_id', + direction => 'descend', + } ); if ($other) { push @includes, - { type => $type, + { + type => $type, name => $mod, id => $other->id, blog_id => $other->blog_id }; } - } - } + } ## end foreach my $tag (@$includes) + } ## end if ( my $includes = $obj...) return \@includes; -} +} ## end sub _find_includes sub _process_custom_fields { my $self = shift; my ( $blog_id, $ts_id ) = @_; - + return unless MT->component('Commercial'); - + my @blogs; push @blogs, $blog_id; - if ($self->{'system_cf'}) { + if ( $self->{'system_cf'} ) { push @blogs, '0'; } - # Grab all custom fields in this blog, as well as all system-level - # custom fields. System-level fields may be required/used for this + # Grab all custom fields in this blog, as well as all system-level + # custom fields. System-level fields may be required/used for this # blog, and author fields may be needed, too. - my $iter = MT->model('field')->load_iter( - { blog_id => \@blogs, }, - { sort => 'name', } - ); + my $iter = MT->model('field') + ->load_iter( { blog_id => \@blogs, }, { sort => 'name', } ); if ($iter) { print "Exporting Custom Fields from blog #$blog_id\n"; } while ( my $cf = $iter->() ) { - $self->_debug( "\t- Writing Custom Field definition: " - . $cf->name . "\n" - ); - # YAML::Tiny will convert a hash into the necessary structure to - # write YAML, however we can't do that because of some naming + $self->_debug( + "\t- Writing Custom Field definition: " . $cf->name . "\n" ); + + # YAML::Tiny will convert a hash into the necessary structure to + # write YAML, however we can't do that because of some naming # differences. For example, the field's public name is "label" but # it's stored as "name". $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fields'} - ->{$cf->basename}->{'label'} = $cf->name; + ->{ $cf->basename }->{'label'} = $cf->name; $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fields'} - ->{$cf->basename}->{'description'} = $cf->description - if $cf->description; + ->{ $cf->basename }->{'description'} = $cf->description + if $cf->description; $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fields'} - ->{$cf->basename}->{'tag'} = $cf->tag; + ->{ $cf->basename }->{'tag'} = $cf->tag; $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fields'} - ->{$cf->basename}->{'obj_type'} = $cf->obj_type; + ->{ $cf->basename }->{'obj_type'} = $cf->obj_type; $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fields'} - ->{$cf->basename}->{'type'} = $cf->type; + ->{ $cf->basename }->{'type'} = $cf->type; $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fields'} - ->{$cf->basename}->{'options'} = $cf->options - if $cf->options; + ->{ $cf->basename }->{'options'} = $cf->options + if $cf->options; $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fields'} - ->{$cf->basename}->{'required'} = $cf->required - if $cf->required; + ->{ $cf->basename }->{'required'} = $cf->required + if $cf->required; $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fields'} - ->{$cf->basename}->{'default'} = $cf->default - if $cf->default; - } -} + ->{ $cf->basename }->{'default'} = $cf->default + if $cf->default; + } ## end while ( my $cf = $iter->(...)) +} ## end sub _process_custom_fields sub _process_field_day_fields { my $self = shift; @@ -639,10 +662,8 @@ sub _process_field_day_fields { return unless MT->component('FieldDay'); # Grab all Field Day fields in this blog. - my $iter = MT->model('fdsetting')->load_iter( - { blog_id => $blog_id, }, - { sort => 'name', } - ); + my $iter = MT->model('fdsetting') + ->load_iter( { blog_id => $blog_id, }, { sort => 'name', } ); if ($iter) { print "Exporting Field Day fields from blog #$blog_id\n"; } @@ -653,38 +674,40 @@ sub _process_field_day_fields { # System-level field day objects leave the blog_id set as NULL, so they # can't be looked up with the above load. if ( $self->{'system_fd'} ) { - $iter = MT->model('fdsetting')->load_iter( - { object_type => ['blog','system','user'], }, - { sort => 'name', } + $iter = MT->model('fdsetting')->load_iter( { + object_type => + [ 'blog', 'system', 'user' ], + }, + { sort => 'name', } ); while ( my $fd = $iter->() ) { $self->_write_field_day_yaml( $ts_id, $fd ); } } -} +} ## end sub _process_field_day_fields sub _write_field_day_yaml { my $self = shift; my ( $ts_id, $fd ) = @_; - $self->_debug("\t- Writing Custom Field definition: " - . $fd->name . "\n" - ); + $self->_debug( + "\t- Writing Custom Field definition: " . $fd->name . "\n" ); - # YAML::Tiny will convert a hash into the necessary structure to - # write YAML, however we don't want to do that because Field Day - # uses non-standard names ("object_type" instead of "obj_type"), + # YAML::Tiny will convert a hash into the necessary structure to + # write YAML, however we don't want to do that because Field Day + # uses non-standard names ("object_type" instead of "obj_type"), # so we should try to standardize that. $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fd_fields'} - ->{$fd->name}->{'obj_type'} = $fd->object_type; + ->{ $fd->name }->{'obj_type'} = $fd->object_type; $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fd_fields'} - ->{$fd->name}->{'type'} = $fd->type; + ->{ $fd->name }->{'type'} = $fd->type; $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fd_fields'} - ->{$fd->name}->{'order'} = $fd->order; + ->{ $fd->name }->{'order'} = $fd->order; + # The data field is a serialized blob. $self->{'yaml'}->[0]->{'template_sets'}->{$ts_id}->{'fd_fields'} - ->{$fd->name}->{'data'} = $fd->data; -} + ->{ $fd->name }->{'data'} = $fd->data; +} ## end sub _write_field_day_yaml 1; __END__ diff --git a/addons/ThemeExport.plugin/lib/ThemeExport/Plugin.pm b/addons/ThemeExport.plugin/lib/ThemeExport/Plugin.pm index 6c68f14d1..bd8f01bdf 100644 --- a/addons/ThemeExport.plugin/lib/ThemeExport/Plugin.pm +++ b/addons/ThemeExport.plugin/lib/ThemeExport/Plugin.pm @@ -16,38 +16,41 @@ sub export { my $temp_dir = $app->config('TempDir'); require File::Temp; - my $basedir = - File::Temp::tempdir( 'mt-theme-export-XXXX', DIR => $temp_dir ); - my $fmgr = MT::FileMgr->new('Local'); + my $basedir + = File::Temp::tempdir( 'mt-theme-export-XXXX', DIR => $temp_dir ); + my $fmgr = MT::FileMgr->new('Local'); my $options = { - verbose => 1, - zip => 1, - logger => sub { $app->print( $_[0] ); }, - fmgr => $fmgr, - pack_name => $q->param('theme_name') || '', - pack_description => $q->param('theme_description') || '', - pack_version => $q->param('theme_version') || '', - system_cf => $q->param('system_cf') || '', - system_fd => $q->param('system_fd') || '', - author_name => $q->param('designer_name') || '', - author_link => $q->param('designer_link') || '', - outdir => $basedir + verbose => 1, + zip => 1, + logger => sub { $app->print( $_[0] ); }, + fmgr => $fmgr, + pack_name => $q->param('theme_name') || '', + pack_description => $q->param('theme_description') || '', + pack_version => $q->param('theme_version') || '', + system_cf => $q->param('system_cf') || '', + system_fd => $q->param('system_fd') || '', + author_name => $q->param('designer_name') || '', + author_link => $q->param('designer_link') || '', + outdir => $basedir }; my $exporter = MT::Theme::Exporter->new($options); - $exporter->export( { - blog_id => $blog->id, - name => $q->param('theme_name') - } - ); + $exporter->export( + { blog_id => $blog->id, name => $q->param('theme_name') } ); $exporter->write_config(); my ( $support_dir, $target_path, $target_url ); - $support_dir = - File::Spec->catdir( 'support', 'theme-export', 'blog_id_'.$blog->id, - format_ts( "%Y-%m-%d", epoch2ts( undef, time ) ) ); + $support_dir = File::Spec->catdir( + 'support', + 'theme-export', + 'blog_id_' . $blog->id, + format_ts( + "%Y-%m-%d", epoch2ts( undef, time ) + ) + ); $target_path = File::Spec->catdir( $app->static_file_path, $support_dir ); + unless ( $fmgr->exists($target_path) ) { $fmgr->mkpath($target_path); } @@ -56,33 +59,32 @@ sub export { $target_path = File::Spec->catfile( $target_path, $zipfilename ); $target_url = caturl( $app->static_path, $support_dir, $zipfilename ); - # $fmgr can't always be used to move the zip file because it may not have - # permission to move a file created by a different user. That is, in + # $fmgr can't always be used to move the zip file because it may not have + # permission to move a file created by a different user. That is, in # MT::Theme::Exporter::write, the zip is created by the system. #$fmgr->rename( $exporter->{'zipfilepath'}, $target_path ) move( $exporter->{'zipfilepath'}, $target_path ) - or die $app->print( - 'JSON:' - . MT::Util::to_json( { - 'error' => "The destination $target_path could not be " + or die $app->print( + 'JSON:' + . MT::Util::to_json( { + 'error' => "The destination $target_path could not be " . "written. Check permissions before retrying.", - } - ) - ); + } + ) + ); # The zip file has been moved to $target_path now, so go ahead and delete # the temporary files. File::Path::rmtree($basedir); - return $app->print( - 'JSON:' - . MT::Util::to_json( { - 'download_url' => $target_url, - 'zipfilename' => $zipfilename, - } - ) - ); -} + return + $app->print( + 'JSON:' + . MT::Util::to_json( + { 'download_url' => $target_url, 'zipfilename' => $zipfilename, } + ) + ); +} ## end sub export sub export_start { my $app = shift; @@ -92,29 +94,30 @@ sub export_start { $tmpl->param( blog_id => $blog->id ); $tmpl->param( theme_name => $blog->name . ' Theme' ); $tmpl->param( theme_description => - "Theme created by the Theme Export Plugin by Endevver." ); + "Theme created by the Theme Export Plugin by Endevver." ); $tmpl->param( theme_version => '1.0' ); $tmpl->param( designer_name => $app->user->nickname ); $tmpl->param( designer_url => $app->user->url ); # If there are any system-level custom fields, give the user the option to # export them. - if ( MT->component('Commercial') - && MT->model('field')->load({ blog_id => '0' }) - ) { + if ( MT->component('Commercial') + && MT->model('field')->load( { blog_id => '0' } ) ) + { $tmpl->param( system_cf => '1' ); } # If there are any system-level Field Day fields, giv ethe user the option # to export them. - if ( MT->component('FieldDay') - && MT->model('fdsetting')->load({ object_type => ['blog','system','user'] }) - ) { + if ( MT->component('FieldDay') + && MT->model('fdsetting') + ->load( { object_type => [ 'blog', 'system', 'user' ] } ) ) + { $tmpl->param( system_fd => 1 ); } - + return $app->build_page($tmpl); -} +} ## end sub export_start 1; __END__ diff --git a/addons/ThemeManager.plugin/lib/ThemeManager/DashboardWidget.pm b/addons/ThemeManager.plugin/lib/ThemeManager/DashboardWidget.pm index 4d340c64f..dceed109e 100644 --- a/addons/ThemeManager.plugin/lib/ThemeManager/DashboardWidget.pm +++ b/addons/ThemeManager.plugin/lib/ThemeManager/DashboardWidget.pm @@ -10,7 +10,7 @@ use MT; sub widget { return { theme_manager => { - label => 'Theme Dashboard Widget', + label => 'Theme Dashboard Widget', handler => sub { my ( $app, $tmpl, $param ) = @_; diff --git a/addons/ThemeManager.plugin/lib/ThemeManager/Plugin.pm b/addons/ThemeManager.plugin/lib/ThemeManager/Plugin.pm index 0613b2d71..0b670dc20 100644 --- a/addons/ThemeManager.plugin/lib/ThemeManager/Plugin.pm +++ b/addons/ThemeManager.plugin/lib/ThemeManager/Plugin.pm @@ -213,7 +213,7 @@ sub theme_dashboard { # Turn that YAML into a plain old string and save it. $blog->theme_meta( $yaml->write_string() ); - + # Upgraders likely also don't have the theme_mode switch set $blog->theme_mode('production'); $blog->save; @@ -482,6 +482,7 @@ sub setup_theme { # Production Mode or Designer Mode. $param->{theme_mode} = $q->param('theme_mode'); if ( $q->param('theme_mode') ) { + # Save the theme mode selection foreach my $blog_id (@blog_ids) { my $blog = MT->model('blog')->load($blog_id); @@ -490,6 +491,7 @@ sub setup_theme { } } else { + # The desired theme mode hasn't been selected yet. return $app->load_tmpl( 'theme_mode.mtml', $param ); } @@ -620,6 +622,7 @@ sub setup_theme { return $app->load_tmpl( 'select_language.mtml', $param ); } ## end if ( !$q->param('language'...)) else { + # Either a language has been set, or there is only one language: english. my $selected_lang = $q->param('language') ? $q->param('language') : $languages[0]; @@ -1366,27 +1369,30 @@ sub _populate_list_templates_context { ); # If any email templates are part of this theme, display them under - # an "Email Templates" template area. Only show this area if a + # an "Email Templates" template area. Only show this area if a # theme requires it, because email templates can't be manually # created anyway. - if ( MT->registry('template_sets', $set, 'templates', 'email') ) { + if ( MT->registry( 'template_sets', $set, 'templates', 'email' ) ) + { $types{'email'} = { - label => $tm->translate("Email Templates"), - type => 'email', - order => 400, - }; + label => $tm->translate("Email Templates"), + type => 'email', + order => 400, + }; } - # If any system templates are part of this theme, display them + # If any system templates are part of this theme, display them # under a "System Templates" template area. Only show this area if # a theme requires it, because system templates can't be manually # created anyway. - if ( MT->registry('template_sets', $set, 'templates', 'system') ) { + if ( + MT->registry( 'template_sets', $set, 'templates', 'system' ) ) + { $types{'system'} = { - label => $tm->translate("System Templates"), - type => [ keys %$sys_tmpl ], - order => 401, - }; + label => $tm->translate("System Templates"), + type => [ keys %$sys_tmpl ], + order => 401, + }; } } ## end if ($blog) diff --git a/addons/ThemeManager.plugin/lib/ThemeManager/TemplateInstall.pm b/addons/ThemeManager.plugin/lib/ThemeManager/TemplateInstall.pm index d8b0d6b6a..b37f20c58 100644 --- a/addons/ThemeManager.plugin/lib/ThemeManager/TemplateInstall.pm +++ b/addons/ThemeManager.plugin/lib/ThemeManager/TemplateInstall.pm @@ -30,7 +30,7 @@ sub _refresh_all_templates { $blog = MT->model('blog')->load($blog_id); next BLOG unless $blog; } - + if ( !$can_refresh_system ) { # system refreshers can refresh all blogs my $perms = MT->model('permission') @@ -170,25 +170,26 @@ sub _create_default_templates { my $obj = MT->model('template')->new; local $val->{name} = $val->{name}; # name field is translated in "templates" call - # This code was added by Byrne because the localization of the $val->{text} - # variable within the context of the eval block was resulting in the - # translated text not to be saved to the variable. + # This code was added by Byrne because the localization of the $val->{text} + # variable within the context of the eval block was resulting in the + # translated text not to be saved to the variable. my $trans = $val->{text}; eval { - $trans = $p->translate_templatized( $trans ); - 1 - } or do { + $trans = $p->translate_templatized($trans); + 1; + } + or do { MT->log( level => MT->model('log')->ERROR(), blog_id => $blog ? $blog->id : 0, message => - $tm->translate( + $tm->translate( "There was an error translating the template '[_1].' Error: [_2]", $val->{name}, $@ - ) - ); - }; + ) + ); + }; local $val->{text} = $trans; $obj->build_dynamic(0); @@ -454,12 +455,12 @@ sub _link_templates { # supplies so that the template identifier can be properly # looked-up, and therefore the correct path can be crafted. my ($config_yaml_tmpl_type) - = grep { ($tmpl->type||'') eq $_ } - qw( index archive individual custom widget widgetset); + = grep { ( $tmpl->type || '' ) eq $_ } + qw( index archive individual custom widget widgetset); # Template modules are called "custom" in the DB $config_yaml_tmpl_type = 'module' - if $config_yaml_tmpl_type eq 'custom'; + if $config_yaml_tmpl_type eq 'custom'; # If none of the above, it must be a system template b/c they # each have a unique $tmpl->type. @@ -484,14 +485,16 @@ sub _link_templates { } else { require Carp; - my $warn = "Failed Theme Manager registry lookup for: ". - join(' > ', - $cur_ts_plugin, 'template_sets', $ts_id, - 'templates', $config_yaml_tmpl_type, - $tmpl->identifier, 'filename' - ).' '.Carp::longmess(); + my $warn = "Failed Theme Manager registry lookup for: " + . join( ' > ', + $cur_ts_plugin, 'template_sets', + $ts_id, 'templates', + $config_yaml_tmpl_type, $tmpl->identifier, + 'filename' ) + . ' ' + . Carp::longmess(); warn $warn; - MT->log( $warn ); + MT->log($warn); $tmpl_filename = $tmpl->identifier . '.mtml'; } @@ -563,6 +566,7 @@ sub _set_module_caching_prefs { $tmpl->$var($val); } } + # foreach (qw( include_with_ssi )) { # $tmpl->$_( $tmpls->{$t}->{$m}->{cache}->{$_} ); # } @@ -578,24 +582,35 @@ sub _parse_build_type { require MT::PublishOption; if ( $type =~ /^disable/i ) { return MT::PublishOption::DISABLED(); - } elsif ($type =~ /^static/i) { + } + elsif ( $type =~ /^static/i ) { return MT::PublishOption::ONDEMAND(); - } elsif ($type =~ /^manual/i) { + } + elsif ( $type =~ /^manual/i ) { return MT::PublishOption::MANUALLY(); - } elsif ($type =~ /^dynamic/i) { + } + elsif ( $type =~ /^dynamic/i ) { return MT::PublishOption::DYNAMIC(); - } elsif ($type =~ /^async/i) { + } + elsif ( $type =~ /^async/i ) { return MT::PublishOption::ASYNC(); - } else { + } + else { my $tm = MT->component('ThemeManager'); - MT->log({ - level => MT->model('log')->WARNING(), - message => $tm->translate( "Unrecognized build_type parameter found in theme's config.yaml: [_1].", $type ), - }); + MT->log( { + level => MT->model('log')->WARNING(), + message => + $tm->translate( + "Unrecognized build_type parameter found in theme's config.yaml: [_1].", + $type + ), + } + ); } + # Default return MT::PublishOption::ONDEMAND(); -} +} ## end sub _parse_build_type sub _set_archive_map_publish_types { my ( $cb, $param ) = @_; @@ -623,7 +638,8 @@ sub _set_archive_map_publish_types { } ); return unless $tm; - $tm->build_type( _parse_build_type($map->{build_type}) ); + $tm->build_type( + _parse_build_type( $map->{build_type} ) ); $tm->is_preferred( $map->{preferred} ); $tm->save() or MT->log( { @@ -659,7 +675,8 @@ sub _set_index_publish_type { my $tmpl = MT->model('template') ->load( { blog_id => $blog->id, identifier => $t, } ); return unless $tmpl; - $tmpl->build_type( _parse_build_type($tmpls->{index}->{$t}->{build_type}) ); + $tmpl->build_type( + _parse_build_type( $tmpls->{index}->{$t}->{build_type} ) ); $tmpl->save() or MT->log( { level => MT->model('log')->ERROR(), @@ -712,9 +729,9 @@ sub _refresh_system_custom_fields { next if UNIVERSAL::isa( $field_data, 'MT::Component' ); # plugin my %field = %$field_data; delete @field{qw( blog_id basename )}; - my $field_name = delete $field{label}; - my $field_scope - = ( $field{scope} && delete $field{scope} eq 'system' ? 0 : $blog->id ); + my $field_name = delete $field{label}; + my $field_scope = ( $field{scope} + && delete $field{scope} eq 'system' ? 0 : $blog->id ); $field_name = $field_name->() if 'CODE' eq ref $field_name; REQUIRED: for my $required (qw( obj_type tag )) { @@ -745,24 +762,24 @@ sub _refresh_system_custom_fields { if ($field_obj) { # Warn if the type is different. - if ($field_obj->type ne $field_data->{type}) { + if ( $field_obj->type ne $field_data->{type} ) { MT->log( { - level => MT->model('log')->WARNING(), - blog_id => $field_scope, - message => - $tm->translate( - 'Could not install custom field [_1] on blog [_2]: ' - . 'the blog already has a field [_1] with a ' - . 'conflicting type', - $field_id, - ), - } + level => MT->model('log')->WARNING(), + blog_id => $field_scope, + message => + $tm->translate( + 'Could not install custom field [_1] on blog [_2]: ' + . 'the blog already has a field [_1] with a ' + . 'conflicting type', + $field_id, + ), + } ); next FIELD; } } else { - + # This field doesn't exist yet. $field_obj = MT->model('field')->new; } @@ -787,15 +804,15 @@ sub _refresh_fd_fields { my $tm = MT->component('ThemeManager'); my $set_name = $blog->template_set or return; my $set = MT->app->registry( 'template_sets', $set_name ) or return; - + # Field Day fields are all defined under the fd_fields key. FIELD: while ( my ( $field_id, $field_data ) = each %{ $set->{fd_fields} } ) { next if UNIVERSAL::isa( $field_data, 'MT::Component' ); # plugin my %field = %$field_data; delete @field{qw( blog_id basename )}; - my $field_scope - = ( $field{scope} && delete $field{scope} eq 'system' ? 0 : $blog->id ); + my $field_scope = ( $field{scope} + && delete $field{scope} eq 'system' ? 0 : $blog->id ); REQUIRED: for my $required (qw( obj_type type )) { next REQUIRED if $field{$required}; @@ -804,10 +821,10 @@ sub _refresh_fd_fields { blog_id => $field_scope, message => $tm->translate( - 'Could not install Field Day field [_1]: field ' - . 'attribute [_2] is required', - $field_id, - $required, + 'Could not install Field Day field [_1]: field ' + . 'attribute [_2] is required', + $field_id, + $required, ), } ); @@ -816,39 +833,39 @@ sub _refresh_fd_fields { # Does the blog have a field with this basename? my $field_obj = MT->model('fdsetting')->load( { - blog_id => $field_scope, - name => $field_id, - object_type => $field_data->{obj_type} || q{}, - } + blog_id => $field_scope, + name => $field_id, + object_type => $field_data->{obj_type} || q{}, + } ); if ($field_obj) { # Warn if the type is different. - if ($field_obj->type ne $field_data->{type}) { + if ( $field_obj->type ne $field_data->{type} ) { MT->log( { - level => MT->model('log')->WARNING(), - blog_id => $field_scope, - message => - $tm->translate( - 'Could not install Field Day field [_1] on blog [_2]: ' - . 'the blog already has a field [_1] with a ' - . 'conflicting type', - $field_id, - ), - } + level => MT->model('log')->WARNING(), + blog_id => $field_scope, + message => + $tm->translate( + 'Could not install Field Day field [_1] on blog [_2]: ' + . 'the blog already has a field [_1] with a ' + . 'conflicting type', + $field_id, + ), + } ); next FIELD; } } else { - + # This field doesn't exist yet. $field_obj = MT->model('fdsetting')->new; } # The label field needs to be dereferenced. - $field_data->{data}->{label} = &{$field_data->{data}->{label}}; + $field_data->{data}->{label} = &{ $field_data->{data}->{label} }; $field_obj->set_values( { blog_id => $field_scope, diff --git a/addons/ThemeManager.plugin/lib/ThemeManager/Util.pm b/addons/ThemeManager.plugin/lib/ThemeManager/Util.pm index 83ec0be31..029761d65 100644 --- a/addons/ThemeManager.plugin/lib/ThemeManager/Util.pm +++ b/addons/ThemeManager.plugin/lib/ThemeManager/Util.pm @@ -174,24 +174,26 @@ sub _return_data { } return $data->( $obj, @_ ) if ref $data eq 'CODE'; if ( $data =~ /\.html$/ ) { + # Ends with .html so this must be a filename/template. eval { - my $tmpl = $obj->load_tmpl($data) - or die $obj->errstr; - $data = $tmpl->output(); + my $tmpl = $obj->load_tmpl($data) or die $obj->errstr; + $data = $tmpl->output(); }; if ($@) { - $@ and warn $@; # TODO - error message + $@ and warn $@; # TODO - error message MT->log( { - level => MT->model('log')->ERROR(), - blog_id => MT->instance->blog->id, - message => - $tm->translate( - 'Theme Manager could not load the documentation for this theme: '.$@ - ), - }); + level => MT->model('log')->ERROR(), + blog_id => MT->instance->blog->id, + message => + $tm->translate( + 'Theme Manager could not load the documentation for this theme: ' + . $@ + ), + } + ); } - } + } ## end if ( $data =~ /\.html$/) return $data; } ## end sub _return_data @@ -215,26 +217,26 @@ sub theme_thumb_path { } sub theme_thumb_url { - # The theme thumbnail/preview image was previously generated by the - # site_preview_image Task. Of course, this requires that - # run-periodic-tasks have run already. If it hasn't run, a thumbnail - # preview may not be created yet. If that's the case, we should fall - # back to the theme preview image. If that's not available, fallback to + + # The theme thumbnail/preview image was previously generated by the + # site_preview_image Task. Of course, this requires that + # run-periodic-tasks have run already. If it hasn't run, a thumbnail + # preview may not be created yet. If that's the case, we should fall + # back to the theme preview image. If that's not available, fallback to # the Theme Manager default preview image. my $blog = $app->blog; # Create the file path to the already-created theme_thumbs file. - my $file_path = File::Spec->catfile( - theme_thumb_path(), - $blog->id . '.jpg' - ); + my $file_path + = File::Spec->catfile( theme_thumb_path(), $blog->id . '.jpg' ); # Check the theme_thumbs folder for the preview image we need. If it's # there then return it. If not, then we need to use the theme default, # or fall back to Theme Manager's default. if ( $blog->file_mgr->exists($file_path) ) { - return caturl( $app->static_path, 'support', 'plugins', $tm->id, - 'theme_thumbs', $blog->id . '.jpg' ); + return + caturl( $app->static_path, 'support', 'plugins', $tm->id, + 'theme_thumbs', $blog->id . '.jpg' ); } else { my $ts_id = $blog->template_set or return; @@ -243,12 +245,15 @@ sub theme_thumb_url { # Just use theme_preview_url to craft the URL. Sure, this is really # intended for when the user is applying a theme, but it works just # fine for our purposes here. - return theme_preview_url( - $plugin->registry('template_sets', $ts_id, 'preview'), - $plugin->id - ); + return + theme_preview_url( + $plugin->registry( + 'template_sets', $ts_id, 'preview' + ), + $plugin->id + ); } -} +} ## end sub theme_thumb_url sub prepare_theme_meta { diff --git a/build/l10n/validate.pl b/build/l10n/validate.pl index 7ed14c1b4..b6e2867ca 100644 --- a/build/l10n/validate.pl +++ b/build/l10n/validate.pl @@ -89,6 +89,7 @@ $res = $c->translate( $key, qw( 111 222 333 444 555 666 777 888 999 ) ); }; + if ( $@ || !defined $res ) { $e++; $total_errors++; diff --git a/build/make-l10n b/build/make-l10n index c14abea40..40b8cfc64 100755 --- a/build/make-l10n +++ b/build/make-l10n @@ -166,7 +166,7 @@ sub wanted_app { . '::Lexicon{$phrase}' ) ); - } ## end while (...) + } ## end while ( ...) } ## end else [ if ( $file =~ m/\.js/ )] } ## end sub wanted_app diff --git a/build/sample.pm b/build/sample.pm index fe4749097..d6bc84b36 100644 --- a/build/sample.pm +++ b/build/sample.pm @@ -190,9 +190,9 @@ sub encoding {"iso-8859-1"} # Latin-1 ## Blog Config: Navigation 'Configuration' => '', - 'Core Setup' => '', - 'Preferences' => '', - 'Archiving' => '', + 'Core Setup' => '', + 'Preferences' => '', + 'Archiving' => '', ## Add a Category screen (category_add.tmpl) 'Add a Category' => '', diff --git a/dev/lib/Melody/Devel.pm b/dev/lib/Melody/Devel.pm index 36c61090c..95238ac70 100644 --- a/dev/lib/Melody/Devel.pm +++ b/dev/lib/Melody/Devel.pm @@ -1,4 +1,4 @@ package Melody::Devel; use App::Cmd::Setup -app; -1; \ No newline at end of file +1; diff --git a/dev/lib/Melody/Devel/Command/Relnotes.pm b/dev/lib/Melody/Devel/Command/Relnotes.pm index 20c09b1da..a3eade5c5 100644 --- a/dev/lib/Melody/Devel/Command/Relnotes.pm +++ b/dev/lib/Melody/Devel/Command/Relnotes.pm @@ -14,20 +14,19 @@ use Gravatar::URL qw( gravatar_url ); my $DEBUG = 0; sub opt_spec { - return ( - [ - "start|s=s", - "refspec for starting commit (usually the last release tag)" - ], - [ "end|e=s", "refspec for the ending tag, defaults to HEAD" ], - [ "melody_dir|m=s", "The path to the Melody directory" ], - [ "output|o=s", "Output filename" ], + return ( [ + "start|s=s", + "refspec for starting commit (usually the last release tag)" + ], + [ "end|e=s", "refspec for the ending tag, defaults to HEAD" ], + [ "melody_dir|m=s", "The path to the Melody directory" ], + [ "output|o=s", "Output filename" ], ); } sub options { my $self = shift; - if ( @_ ) { + if (@_) { $self->{options} = shift; } return wantarray ? %{ $self->{options} } : $self->{options}; @@ -38,19 +37,18 @@ sub option { my $opt = $self->{options} || {}; my $key = shift; my $val = shift; - return defined $val ? ( $opt->{key} = $val ) - : defined $key and exists $opt->{$key} ? $opt->{$key} - : undef; + return defined $val ? ( $opt->{key} = $val ) : defined $key + and exists $opt->{$key} ? $opt->{$key} : undef; } sub fh { my $self = shift; - if ( @_ ) { + if (@_) { my $out = shift; require FileHandle; - my $fh = FileHandle->new( $out, 'w' ); - die "Error opening ".$out.": $!" unless defined $fh; - select( $fh ); + my $fh = FileHandle->new( $out, 'w' ); + die "Error opening " . $out . ": $!" unless defined $fh; + select($fh); return $self->{fh} = $fh; } $self->{fh}; @@ -69,19 +67,19 @@ sub debug { sub out { my $self = shift; - print join("\n", @_); + print join( "\n", @_ ); } sub verify_git_directory { - my ($self, $dir ) = @_; - my @loc = grep { defined } - ( $dir, '.', dirname("$0/.."), $ENV{MT_HOME} ); + my ( $self, $dir ) = @_; + my @loc = grep {defined} ( $dir, '.', dirname("$0/.."), $ENV{MT_HOME} ); my $repo; - foreach my $loc ( @loc ) { + foreach my $loc (@loc) { + # $self->debug( "Testing $loc\n" ); - my $path = realpath( $loc ); + my $path = realpath($loc); next unless $path and -d $path; - if ( $repo = Git->repository( Directory => $path )) { + if ( $repo = Git->repository( Directory => $path ) ) { $dir = $path; last; } @@ -89,10 +87,10 @@ sub verify_git_directory { $repo; } -sub validate_args { - my $self = shift; - my $opt = shift; - my $args = shift; +sub validate_args { + my $self = shift; + my $opt = shift; + my $args = shift; $opt->{end} ||= 'master'; # no args allowed but options! @@ -100,7 +98,7 @@ sub validate_args { # Check that we're in the Melody directory $self->{repo} = $self->verify_git_directory( $opt->{melody_dir} ) - or return $self->usage_error("Couldn't find repo"); + or return $self->usage_error("Couldn't find repo"); $self->fh( $opt->{output} ) if $opt->{output}; @@ -110,34 +108,29 @@ sub validate_args { # Ask for display name for end refspec my $term = Term::ReadLine->new(__PACKAGE__); foreach my $ref (qw( start end )) { -print STDERR 'show-ref', $opt->{$ref}."\n"; + print STDERR 'show-ref', $opt->{$ref} . "\n"; - return $self->usage_error("Invalid refspec: ".$opt->{$ref}) - unless $self->{repo}->command( 'show-ref', $opt->{$ref} ); + return $self->usage_error( "Invalid refspec: " . $opt->{$ref} ) + unless $self->{repo}->command( 'show-ref', $opt->{$ref} ); my $prompt = sprintf( "Choose a display name to use for release %s: ", - $opt->{$ref}); + $opt->{$ref} ); my $OUT = $term->OUT || \*STDOUT; defined( my $resp = $term->readline($prompt) ) - or return $self->usage_error("Aborting"); - $term->addhistory( $opt->{$ref.'_label'} = $resp ); + or return $self->usage_error("Aborting"); + $term->addhistory( $opt->{ $ref . '_label' } = $resp ); } $self->{arguments} = $args; - $self->options( $opt ); -} + $self->options($opt); +} ## end sub validate_args sub run { my $self = shift; my $repo = $self->{repo}; my $opt = $self->options(); $self->out( $self->boilerplate ); - my ($fh, $c) = $repo->command_output_pipe( - 'log', - '--abbrev-commit', - '--no-merges', - '--topo-order', - '--reverse', - '--date=iso', - q(--format=START commit %H + my ( $fh, $c ) = $repo->command_output_pipe( + 'log', '--abbrev-commit', '--no-merges', '--topo-order', '--reverse', + '--date=iso', q(--format=START commit %H SHA = %h Tree = %t Parents = %p @@ -150,59 +143,60 @@ Committer Date = %cd Subject = %s Message = %-b Note = %N -END commit), - join('..', $opt->{start}, $opt->{end}) +END commit), join( '..', $opt->{start}, $opt->{end} ) ); + # %n: newline my ( @log, %buffer ); while ( my $lastrev = <$fh> ) { chomp $lastrev; if ( $lastrev =~ m{^START commit (\w+)} ) { - $self->debug( "FOUND $lastrev\n" ); + $self->debug("FOUND $lastrev\n"); %buffer = ( commit => $1 ); } elsif ( $lastrev =~ m{^END commit} ) { - $self->debug( "FOUND $lastrev\n" ); + $self->debug("FOUND $lastrev\n"); delete $buffer{multiline_key}; - $self->out( $self->format_commit( \%buffer )); - push( @log, { %buffer } ); + $self->out( $self->format_commit( \%buffer ) ); + push( @log, {%buffer} ); %buffer = (); next; } - elsif ( $lastrev =~ m{^(Note|Message)\s+= (.*)}) { - my ( $key, $val ) = ( lc($1), $2 ); + elsif ( $lastrev =~ m{^(Note|Message)\s+= (.*)} ) { + my ( $key, $val ) = ( lc($1), $2 ); $buffer{multiline_key} = $key; - $buffer{$key} = $val; - $self->debug( "Set $key to $val\n" ); + $buffer{$key} = $val; + $self->debug("Set $key to $val\n"); } else { my ( $key, $val ); if ( $key = $buffer{multiline_key} ) { - $buffer{$key} .= "\n".$lastrev; - $self->debug( "Added to $key: $lastrev\n" ); + $buffer{$key} .= "\n" . $lastrev; + $self->debug("Added to $key: $lastrev\n"); } else { - ( $key, $val ) = split(/\s+=\s+/, $lastrev, 2 ); - my @keys = split(/\s+/, lc($key) ); + ( $key, $val ) = split( /\s+=\s+/, $lastrev, 2 ); + my @keys = split( /\s+/, lc($key) ); if ( @keys == 1 ) { - $buffer{$keys[0]} = $val; + $buffer{ $keys[0] } = $val; } else { - ($key, (my $subkey)) = @keys; + ( $key, ( my $subkey ) ) = @keys; $buffer{$key}{$subkey} = $val; } - $self->debug( "Set @keys to $val\n" ); + $self->debug("Set @keys to $val\n"); } } - } - $repo->command_close_pipe($fh, $c); + } ## end while ( my $lastrev = <$fh>) + $repo->command_close_pipe( $fh, $c ); + # $self->out( Dumper(\@log) ); # | perl -lape ' # if ( ! m{^\[[a-z0-9]{6}} ) { # s{^\s+$}{}g; # s{^([^\[\s])}{ $1}; # s{\[#(\d+)}{\[[#$1](https://openmelody.lighthouseapp.com/projects/26604/tickets/$1)}g; -} +} ## end sub run sub boilerplate { my $self = shift; @@ -231,30 +225,29 @@ _The following are notable changes introduced since [the release of $prev_name][ The following are the raw commits introduced in $release_name, listed in the order in which they were introduced into the [openmelody/melody master repo](http://github.com/openmelody/melody). EOF - -} + +} ## end sub boilerplate sub format_commit { my $self = shift; my $buffer = shift; my $gh_base = 'http://github.com/openmelody/melody/commit'; my $lh_base - = 'http://openmelody.lighthouseapp.com/projects/26604-melody/tickets'; - - my $sha = delete $buffer->{sha} || ''; - my $date = delete $buffer->{committer}{date} || ''; - my $author = delete $buffer->{author}{name} || ''; - my $author_img = gravatar_url( - email => delete $buffer->{author}{email}, - size => 30 - ); - my $author_url = $self->author_url_lookup( $author ) || ''; + = 'http://openmelody.lighthouseapp.com/projects/26604-melody/tickets'; + + my $sha = delete $buffer->{sha} || ''; + my $date = delete $buffer->{committer}{date} || ''; + my $author = delete $buffer->{author}{name} || ''; + my $author_img + = gravatar_url( email => delete $buffer->{author}{email}, size => 30 ); + my $author_url = $self->author_url_lookup($author) || ''; my $subject = delete $buffer->{subject} || ''; my $note = delete $buffer->{note} || ''; my $msg = delete $buffer->{message} || ''; my $tree = delete $buffer->{tree} || ''; - $subject =~ s{\[\#(\d+)(\s*state:.*?)?\]}{[Case \#$1]($lh_base/$1) - }g; - $subject = "\n\n> $subject"; + $subject =~ s{\[\#(\d+)(\s*state:.*?)?\]}{[Case \#$1]($lh_base/$1) - }g; + $subject = "\n\n> $subject"; + foreach my $k ( $msg, $note ) { next unless defined $k and $k ne ''; $k =~ s{^([^>])}{> $1}gsm; @@ -265,24 +258,23 @@ sub format_commit { **[ $author]($author_url) — [$date — $sha]($gh_base/$sha)** ([tree]($gh_base/$tree)) $subject EOF $output_fmt =~ s{[\s\n]+\Z}{}gsm; - return $output_fmt."\n\n"; -} + return $output_fmt . "\n\n"; +} ## end sub format_commit sub author_url_lookup { - my $self = shift; + my $self = shift; my $name = shift; - my $url = 'http://github.com/'; + my $url = 'http://github.com/'; my %authors = ( - 'Jay Allen' => 'jayallen', - 'Byrne Reese' => 'byrnereese', - 'Dan Wolfgang' => 'danwolfgang', - 'Mike Thomsen' => 'mikert', - 'Timothy Appnel' => 'tima', - 'David Phillips' => 'dphillips', - 'Sabine' => 'sabine', + 'Jay Allen' => 'jayallen', + 'Byrne Reese' => 'byrnereese', + 'Dan Wolfgang' => 'danwolfgang', + 'Mike Thomsen' => 'mikert', + 'Timothy Appnel' => 'tima', + 'David Phillips' => 'dphillips', + 'Sabine' => 'sabine', ); - $url .= $authors{$name} ? $authors{$name} - : 'UNKNOWN'; + $url .= $authors{$name} ? $authors{$name} : 'UNKNOWN'; } 1; diff --git a/lib/MT.pm b/lib/MT.pm index 5a28c2d0a..38fbf49a5 100644 --- a/lib/MT.pm +++ b/lib/MT.pm @@ -54,7 +54,7 @@ BEGIN { $PRODUCT_NAME = 'Melody'; $PRODUCT_CODE = 'OM'; $VERSION_ID = '1.0.1'; - $PORTAL_URL = 'http://openmelody.org'; + $PORTAL_URL = 'http://openmelody.org'; } ## end if ( '__MAKE_ME__' eq ...) else { @@ -1007,12 +1007,14 @@ sub init_config { if ( my @local_lib = $cfg->PERL5LIB ) { - eval sprintf "use local::lib qw( %s )", join(' ', @local_lib); - $@ and return $mt->errtrans( - 'PERL5LIB: Error loading Perl local libraries: [_1]. ' - . 'Please re-check your PERL5LIB configuration value: [_2]', - $@, join( ', ', @local_lib ) - ); + eval sprintf "use local::lib qw( %s )", join( ' ', @local_lib ); + $@ and return + $mt->errtrans( + 'PERL5LIB: Error loading Perl local libraries: [_1]. ' + . 'Please re-check your PERL5LIB configuration value: [_2]', + $@, + join( ', ', @local_lib ) + ); } return $mt->trans_error("Bad ObjectDriver config") diff --git a/lib/MT/App.pm b/lib/MT/App.pm index 37e9e0419..2cc5f0640 100644 --- a/lib/MT/App.pm +++ b/lib/MT/App.pm @@ -2442,19 +2442,20 @@ sub upload_info { } ## end sub upload_info sub validate_upload { - my $app = shift; - my $args = shift; + my $app = shift; + my $args = shift; my $INVALID = sub { my $desc = $app->translate( @_ ? @_ : 'Reason unspecified' ); require MT::Log; - $app->log({ - level => MT::Log::SECURITY(), - class => 'asset', - category => 'invalid', - message - => $app->translate('Blocked invalid upload: [_1]', $desc), - }); + $app->log( { + level => MT::Log::SECURITY(), + class => 'asset', + category => 'invalid', + message => + $app->translate( 'Blocked invalid upload: [_1]', $desc ), + } + ); return $app->errtrans('Invalid upload file'); }; @@ -2465,15 +2466,18 @@ sub validate_upload { if ( defined $args->{filename} ) { require File::Basename; my ($file) = File::Basename::fileparse( $args->{filename} ); - my $cfg = $app->config(); + my $cfg = $app->config(); defined $file - or return $INVALID->( 'Could not parse filepath [_1]', - $args->{filename} ); + or return $INVALID->( 'Could not parse filepath [_1]', + $args->{filename} ); - return $INVALID->( - 'Invalid characters in filename: [_1]', $args->{filename}) - if $file =~ m{ + return + $INVALID->( + 'Invalid characters in filename: [_1]', + $args->{filename} + ) + if $file =~ m{ / | # Filename shouldn't have slash; indicates directory \.\. | # No upward traversal allowed \0 | # No NULL bytes allowed @@ -2482,26 +2486,29 @@ sub validate_upload { }x; my $deny_exts = $cfg->DeniedAssetFileExtensions || []; - if ( @$deny_exts ) { + if (@$deny_exts) { my $match = MT::Util::match_file_extension( $file, $deny_exts ); if ( defined $match and $match ne '' ) { - return $INVALID->( - 'Blacklisted file extension ([_1]) found for file [_2]', - $match, $file - ); + return + $INVALID->( + 'Blacklisted file extension ([_1]) found for file [_2]', + $match, $file + ); } } my $allow_exts = $cfg->AssetFileExtensions || []; - if ( @$allow_exts ) { + if (@$allow_exts) { my $match = MT::Util::match_file_extension( $file, $allow_exts ); unless ( defined $match and $match ne '' ) { - return $INVALID->( - 'File does not have whitelisted extension: [_1]', $file - ); + return + $INVALID->( + 'File does not have whitelisted extension: [_1]', + $file + ); } } - } + } ## end if ( defined $args->{filename...}) ### # Evaluation of a binary data to see if it contains HTML or @@ -2509,21 +2516,24 @@ sub validate_upload { # files (in particular) that contain embedded HTML or JavaScript are # a known vector for an IE 6 and 7 content-sniffing vulnerability. ### - if ( defined( my $data = $args->{data} )) { + if ( defined( my $data = $args->{data} ) ) { require MT::Image; my $has_html = MT::Image->has_html_signature( data => $data ); defined $has_html - or return $INVALID->( - 'Error reading image [_1]: [_2]', 'data', MT::Image->errstr ); + or return + $INVALID->( + 'Error reading image [_1]: [_2]', + 'data', MT::Image->errstr + ); $has_html - or return $INVALID->( - 'Image file contains suspicious filetype signature'); + or return $INVALID->( + 'Image file contains suspicious filetype signature'); } 1; -} +} ## end sub validate_upload sub cookie_val { my $app = shift; @@ -3689,15 +3699,13 @@ sub query { } sub blog { - my $app = shift; - my $blog = shift || $app->{_blog}; - $blog ||= eval { - no warnings; - my $blog_id - = int( $app->query->param('blog_id') || 0 ); - return $blog_id ? $app->model('blog')->load( $blog_id ) - : undef; - }; + my $app = shift; + my $blog = shift || $app->{_blog}; + $blog ||= eval { + no warnings; + my $blog_id = int( $app->query->param('blog_id') || 0 ); + return $blog_id ? $app->model('blog')->load($blog_id) : undef; + }; return $app->{_blog} = $blog; } diff --git a/lib/MT/App/Comments.pm b/lib/MT/App/Comments.pm index e6149a5c5..94ff0f427 100644 --- a/lib/MT/App/Comments.pm +++ b/lib/MT/App/Comments.pm @@ -350,25 +350,24 @@ sub do_signup { my $q = $app->query; return $app->errtrans("Invalid request") - if $app->request_method() ne 'POST'; + if $app->request_method() ne 'POST'; my $param = {}; $param->{$_} = $q->param($_) foreach qw(blog_id entry_id static email url username nickname email return_url ); - return $app->errtrans("Invalid request") - unless int( $param->{blog_id} ); + return $app->errtrans("Invalid request") unless int( $param->{blog_id} ); my $blog = $app->model('blog')->load( $param->{blog_id} || 0 ) - or return $app->error( - $app->translate( 'Can\'t load blog #[_1].', $param->{blog_id} ) ); + or return $app->error( + $app->translate( 'Can\'t load blog #[_1].', $param->{blog_id} ) ); my $cfg = $app->config; if ( my $registration = $cfg->CommenterRegistration ) { return $app->handle_error( - $app->translate('Registration is not allowed.') ) - unless $registration->{Allow} && $blog->allow_commenter_regist; + $app->translate('Registration is not allowed.') ) + unless $registration->{Allow} && $blog->allow_commenter_regist; } my $filter_result = $app->run_callbacks( 'api_save_filter.author', $app ); diff --git a/lib/MT/AtomServer.pm b/lib/MT/AtomServer.pm index 0526250e4..833033f94 100644 --- a/lib/MT/AtomServer.pm +++ b/lib/MT/AtomServer.pm @@ -249,9 +249,9 @@ sub xml_body { die "Error Parsing XML Input $@ "; } } - } + } ## end unless ( exists $app->{xml_body...}) $app->{xml_body}; -} +} ## end sub xml_body sub atom_body { my $app = shift; @@ -278,7 +278,7 @@ sub atom_body { ) or return $app->error( 500, MT::Atom::Entry->errstr ); } $atom; -} +} ## end sub atom_body # $target_zone is expected to be a number of hours from GMT sub iso2ts { @@ -958,37 +958,38 @@ sub delete_post { sub validate_upload { my $app = shift; - if ( @_ ) { - $app->SUPER::validate_upload( @_ ) - or return $app->error( 500, $app->errstr ); + if (@_) { + $app->SUPER::validate_upload(@_) + or return $app->error( 500, $app->errstr ); } - else { # Check Atom payload + else { # Check Atom payload return $app->error( 403, "Access denied" ) - unless $app->{perms}->can_upload; + unless $app->{perms}->can_upload; - my $atom = $app->atom_body - or return $app->error( 400, "atom body is required" ); + my $atom = $app->atom_body + or return $app->error( 400, "atom body is required" ); my $content = $atom->content; my $data = $content->body; - my $type = $content->type - or return $app->error( 400, "content \@type is required" ); + my $type = $content->type + or return $app->error( 400, "content \@type is required" ); - my $fname = $atom->title - or return $app->error( 400, "title is required" ); + my $fname = $atom->title + or return $app->error( 400, "title is required" ); # Call self to have $app->SUPER check the filename and data - $app->validate_upload({ filename => basename($fname), data => $data }) - or return $app->error( 500, $app->errstr ); - } + $app->validate_upload( + { filename => basename($fname), data => $data } ) + or return $app->error( 500, $app->errstr ); + } ## end else [ if (@_) ] - 1; # Looks good -} + 1; # Looks good +} ## end sub validate_upload sub _upload_to_asset { - my $app = shift; + my $app = shift; return unless $app->validate_upload(); @@ -1001,16 +1002,15 @@ sub _upload_to_asset { my $type = $content->type; my $data = $content->body; - my $local - = File::Spec->catfile( $blog->site_path, $fname ); + my $local = File::Spec->catfile( $blog->site_path, $fname ); my ( $base, $path, $ext ) - = File::Basename::fileparse( $local, '\.[^\.]*' ); + = File::Basename::fileparse( $local, '\.[^\.]*' ); # FIXME Unnecessarily hard-coded hash of a handful of MIME types # If there's no extension, look it up against a hash of arbitrarily # chosen, sadly non-comprehensive list of popular MIME types. - if ( ! defined $ext or $ext eq '' ) { + if ( !defined $ext or $ext eq '' ) { my %MIME2EXT = ( 'text/plain' => '.txt', 'image/jpeg' => '.jpg', @@ -1023,21 +1023,20 @@ sub _upload_to_asset { 'audio/ogg' => '.ogg', 'audio/ogg-vorbis' => '.ogg', ); - ($ext) = $MIME2EXT{$type} - || MT::Util::mime_type_extension( $type ); + ($ext) = $MIME2EXT{$type} || MT::Util::mime_type_extension($type); } my $i = 1; my $base_copy = $base; - while ( $fmgr->exists( join('', $path, $base, $ext) ) ) { + while ( $fmgr->exists( join( '', $path, $base, $ext ) ) ) { $base = join( '_', $base_copy, $i++ ); } - my $local_basename = join('', $base, $ext); - $local = join('', $path, $local_basename); + my $local_basename = join( '', $base, $ext ); + $local = join( '', $path, $local_basename ); # Re-check in case extension was added - $app->validate_upload({ filename => $local_basename }) - or return $app->error( 500, $app->errstr ); + $app->validate_upload( { filename => $local_basename } ) + or return $app->error( 500, $app->errstr ); defined( my $bytes = $fmgr->put_data( $data, $local, 'upload' ) ) or return $app->error( 500, "Error writing uploaded file" ); @@ -1048,15 +1047,17 @@ sub _upload_to_asset { my $is_image = 0; if ( $asset_pkg eq 'MT::Asset::Image' ) { eval { require Image::Size; }; - if ( $@ ) { - $fmgr->delete( $local ); - return $app->error( - 500, - MT->translate( - 'Perl module Image::Size is required to determine ' - .'width and height of uploaded images.' - ).' Upload aborted.' - ); + if ($@) { + $fmgr->delete($local); + return + $app->error( + 500, + MT->translate( + 'Perl module Image::Size is required to determine ' + . 'width and height of uploaded images.' + ) + . ' Upload aborted.' + ); } $is_image = 1; } @@ -1064,6 +1065,7 @@ sub _upload_to_asset { my ( $w, $h, $id ) = Image::Size::imgsize($local); unless ( defined($w) && defined($h) ) { + # rebless to file type $asset_pkg = 'MT::Asset'; } @@ -1078,18 +1080,18 @@ sub _upload_to_asset { ) { $asset = $asset_pkg->new(); - $asset->file_path( join('/', '%r', $local_basename ) ); - $asset->file_name( $local_basename ); + $asset->file_path( join( '/', '%r', $local_basename ) ); + $asset->file_name($local_basename); $asset->blog_id( $blog->id ); $asset->created_by( $user->id ); - (my $ext_copy = $ext) =~ s/\.//; + ( my $ext_copy = $ext ) =~ s/\.//; $asset->file_ext($ext_copy); } else { $asset->modified_by( $user->id ); } my $original = $asset->clone; - my $url = join('/', '%r', $local_basename ); + my $url = join( '/', '%r', $local_basename ); $asset->url($url); if ($is_image) { $asset->image_width($w); diff --git a/lib/MT/Auth/OpenID.pm b/lib/MT/Auth/OpenID.pm index 88c874718..faaf845c9 100644 --- a/lib/MT/Auth/OpenID.pm +++ b/lib/MT/Auth/OpenID.pm @@ -373,8 +373,7 @@ sub _asset_from_url { return undef unless $resp->is_success; my $image = $resp->content; return undef unless $image; - my $mimetype = $resp->header('Content-Type') - or return undef; + my $mimetype = $resp->header('Content-Type') or return undef; my $def_ext = { 'image/jpeg' => '.jpg', 'image/png' => '.png', @@ -418,7 +417,7 @@ sub _asset_from_url { require MT::Asset; my $asset_pkg = MT::Asset->handler_for_file($local); - if ( $asset_pkg ne 'MT::Asset::Image' ) { + if ( $asset_pkg ne 'MT::Asset::Image' ) { unlink $local; return undef; } diff --git a/lib/MT/BackupRestore/BackupFileHandler.pm b/lib/MT/BackupRestore/BackupFileHandler.pm index a8f6d5bc4..624b149f4 100644 --- a/lib/MT/BackupRestore/BackupFileHandler.pm +++ b/lib/MT/BackupRestore/BackupFileHandler.pm @@ -42,8 +42,10 @@ sub start_element { die MT->translate( 'Uploaded file was not a valid Movable Type backup manifest file.' ) - if !( ( 'movabletype' eq $name ) - && ( MT::BackupRestore::NS_MOVABLETYPE() eq $ns ) ); + if !( + ( 'movabletype' eq $name ) + && ( MT::BackupRestore::NS_MOVABLETYPE() eq $ns ) + ); #unless ($self->{ignore_schema_conflicts}) { my $schema = $attrs->{'{}schema_version'}->{Value}; diff --git a/lib/MT/BackupRestore/ManifestFileHandler.pm b/lib/MT/BackupRestore/ManifestFileHandler.pm index 6df67b806..2a217f52b 100644 --- a/lib/MT/BackupRestore/ManifestFileHandler.pm +++ b/lib/MT/BackupRestore/ManifestFileHandler.pm @@ -51,8 +51,10 @@ sub start_element { die MT->translate( "Uploaded file was not a valid Movable Type backup manifest file." ) - if !( ( 'manifest' eq $name ) - && ( MT::BackupRestore::NS_MOVABLETYPE() eq $ns ) ); + if !( + ( 'manifest' eq $name ) + && ( MT::BackupRestore::NS_MOVABLETYPE() eq $ns ) + ); $self->{start} = 0; } if ( MT::BackupRestore::NS_MOVABLETYPE() eq $ns ) { diff --git a/lib/MT/Bootstrap.pm b/lib/MT/Bootstrap.pm index 33578d3bc..4d3e968dc 100644 --- a/lib/MT/Bootstrap.pm +++ b/lib/MT/Bootstrap.pm @@ -168,6 +168,8 @@ sub import { $app->run; } }; + + if ( my $err = $@ ) { if ( !$app && $err =~ m/Missing configuration file/ ) { my $host = $ENV{SERVER_NAME} || $ENV{HTTP_HOST}; @@ -198,6 +200,7 @@ sub import { } ## end if ( $uri =~ m/(\/index\.(f?cgi|f?pl)(\?.*)?)$/) } ## end if ( !$app && $err =~ ...) + my $charset = 'utf-8'; eval { @@ -209,6 +212,7 @@ sub import { $app->{cfg}->read_config($c); $charset = $app->{cfg}->PublishCharset; }; + if ( $app && UNIVERSAL::isa( $app, 'MT::App' ) && !UNIVERSAL::isa( $app, 'MT::App::Wizard' ) ) @@ -239,6 +243,7 @@ sub import { }; $err = $@; } ## end if ( $app && UNIVERSAL::isa...) + if ( !$MT::DebugMode && ( $err =~ m/^(.+?)( at .+? line \d+)(.*)$/s ) ) { @@ -246,6 +251,7 @@ sub import { my $dbmode = 'Enable DebugMode for more details.'; $err .= '. ' . ( $app ? $app->translate($dbmode) : $dbmode ); } + print "Content-Type: text/plain; charset=$charset\n\n"; print $app ? $app->translate( "Got an error: [_1]", $err ) diff --git a/lib/MT/CMS/Asset.pm b/lib/MT/CMS/Asset.pm index 34577aa2c..8a260b8a7 100644 --- a/lib/MT/CMS/Asset.pm +++ b/lib/MT/CMS/Asset.pm @@ -379,20 +379,19 @@ sub start_upload { } sub upload_file { - my $app = shift; - my $q = $app->query; - my $perms = $app->permissions; + my $app = shift; + my $q = $app->query; + my $require_type = $q->param('require_type') || ''; + my $perms = $app->permissions; return $app->errtrans("Permission denied.") - unless $perms and $perms->can_upload; + unless $perms and $perms->can_upload; $app->validate_magic() or return; - my ( $asset, $bytes ) = _upload_file( - $app, - require_type => ( $app->param('require_type') || '' ), - @_, - ); + my ( $asset, $bytes ) + = _upload_file( $app, require_type => $require_type, @_, ); + return if !defined $asset; return $asset if !defined $bytes; # whatever it is @@ -993,8 +992,8 @@ sub _set_start_upload_params { } ## end sub _set_start_upload_params # FIXME This 580-line method MUST be refactored!!!! -# It needs to be broken up and ALL code NOT specifically unique to -# MT::App::CMS must be moved to MT::App or elsewhere so that other apps or +# It needs to be broken up and ALL code NOT specifically unique to +# MT::App::CMS must be moved to MT::App or elsewhere so that other apps or # command-line tools can use all of its functions individually AND so # that we run all uploads through a common set of security checks. sub _upload_file { @@ -1152,10 +1151,10 @@ sub _upload_file { ; ## Save the filename so we can use it in the error message later $ext = $local_base; $ext =~ m!.*\.(.*)$! - ; ## Extract the characters to the right of the last dot delimiter / period + ; ## Extract the characters to the right of the last dot delimiter / period $ext = $1; ## Those characters are the file extension - return unless $app->validate_upload({ filename => $filename }); + return unless $app->validate_upload( { filename => $filename } ); my $real_fh; unless ($has_overwrite) { @@ -1384,19 +1383,20 @@ sub _upload_file { ; ## Save the filename so we can use it in the error message later $ext = $local_base; $ext =~ m!.*\.(.*)$! - ; ## Extract the characters to the right of the last dot delimiter / period + ; ## Extract the characters to the right of the last dot delimiter / period $ext = $1; ## Those characters are the file extension - return unless $app->validate_upload({ filename => $filename }); + return unless $app->validate_upload( { filename => $filename } ); - my ( $w, $h, $id, $write_file ) = MT::Image->check_upload( - Fh => $fh, - Fmgr => $fmgr, - Local => $local_file, - Max => $upload_param{max_size}, - MaxDim => $upload_param{max_image_dimension}, - ext => $ext, - LocalBase => $local_base + my ( $w, $h, $id, $write_file ) + = MT::Image->check_upload( + Fh => $fh, + Fmgr => $fmgr, + Local => $local_file, + Max => $upload_param{max_size}, + MaxDim => $upload_param{max_image_dimension}, + ext => $ext, + LocalBase => $local_base ); return $app->error( MT::Image->errstr ) unless $write_file; diff --git a/lib/MT/CMS/Comment.pm b/lib/MT/CMS/Comment.pm index bc8f3316b..7e7205031 100644 --- a/lib/MT/CMS/Comment.pm +++ b/lib/MT/CMS/Comment.pm @@ -738,18 +738,17 @@ sub save_commenter_perm { my %permissions; foreach my $id (@ids) { ( $id, $blog_id ) = @$id if ref $id eq 'ARRAY'; - my $perm_blog_id = $app->config->SingleCommunity ? 0 : $blog_id; - if ( $perm_blog_id ) { - my $perm - = $permissions{ $perm_blog_id } - ||= $author->permissions($perm_blog_id); + my $perm_blog_id = $app->config->SingleCommunity ? 0 : $blog_id; + if ($perm_blog_id) { + my $perm = $permissions{$perm_blog_id} + ||= $author->permissions($perm_blog_id); if ( !$perm->can_manage_feedback && !$perm->can_administer ) { - return $app->errtrans( "Permission denied." ); + return $app->errtrans("Permission denied."); } } else { - return $app->errtrans( "Permission denied." ) - unless $author->is_superuser; + return $app->errtrans("Permission denied.") + unless $author->is_superuser; } my $cmntr = MT::Author->load($id) diff --git a/lib/MT/CMS/Entry.pm b/lib/MT/CMS/Entry.pm index 1a2237bb3..585049671 100644 --- a/lib/MT/CMS/Entry.pm +++ b/lib/MT/CMS/Entry.pm @@ -1015,7 +1015,7 @@ sub preview { } return $app->error( $app->translate("Permission denied.") ) - unless $app->permissions->can_edit_entry( $entry, $app->user ); + unless $app->permissions->can_edit_entry( $entry, $app->user ); my $cat; my $names = $entry->column_names; diff --git a/lib/MT/CMS/User.pm b/lib/MT/CMS/User.pm index cf2590367..9e0cd3126 100644 --- a/lib/MT/CMS/User.pm +++ b/lib/MT/CMS/User.pm @@ -918,8 +918,7 @@ sub upload_userpic { my $app = shift; $app->validate_magic() or return; - return $app->errtrans("Invalid request.") - if $app->param('blog_id'); + return $app->errtrans("Invalid request.") if $app->param('blog_id'); require MT::CMS::Asset; my ( $asset, $bytes ) diff --git a/lib/MT/Config.pm b/lib/MT/Config.pm index 86a3573d6..f5a394d7d 100644 --- a/lib/MT/Config.pm +++ b/lib/MT/Config.pm @@ -9,15 +9,16 @@ use strict; use base qw( MT::Object ); __PACKAGE__->install_properties( { - column_defs => - { 'id' => 'integer not null auto_increment', 'data' => 'text', }, - primary_key => 'id', - datasource => 'config', - # Added to eliminate overly aggressive caching of the config object - # under persistent webserver environments. - # Details at https://movabletype.fogbugz.com/?100356 - cacheable => 0, - } + column_defs => + { 'id' => 'integer not null auto_increment', 'data' => 'text', }, + primary_key => 'id', + datasource => 'config', + + # Added to eliminate overly aggressive caching of the config object + # under persistent webserver environments. + # Details at https://movabletype.fogbugz.com/?100356 + cacheable => 0, + } ); sub class_label { diff --git a/lib/MT/ConfigMgr.pm b/lib/MT/ConfigMgr.pm index a76db5690..009eb74aa 100644 --- a/lib/MT/ConfigMgr.pm +++ b/lib/MT/ConfigMgr.pm @@ -34,8 +34,7 @@ sub define { my $mgr = shift; my ($vars); - if ( ref $_[0] - and grep { ref $_[0] eq $_ } qw( ARRAY HASH )) { + if ( ref $_[0] and grep { ref $_[0] eq $_ } qw( ARRAY HASH ) ) { $vars = shift; } else { @@ -112,15 +111,16 @@ sub default { # } # if ( 'ARRAY' eq $type ) { - $def = ! defined $def ? [] # Now @$default works! - : ! ref $def ? [ $def ] # 1 element defined as scalar - : $def # No-op, fallback to self + $def = !defined $def + ? [] # Now @$default works! + : !ref $def ? [$def] # 1 element defined as scalar + : $def # No-op, fallback to self } elsif ( 'HASH' eq $type ) { - $def = ! defined $def ? {} # Now %$default works - # Data folding: String to hashref - : ! ref $def ? $mgr->_parse_stringy_hash($def) - : $def; + $def = !defined $def + ? {} # Now %$default works + # Data folding: String to hashref + : !ref $def ? $mgr->_parse_stringy_hash($def) : $def; } # $ENV{CONFIGMGRDEBUG} @@ -132,7 +132,7 @@ sub default { # Can be a scalar (either defined or not), # an array ref or a hash ref return $def; -} +} ## end sub default sub is_path { my $mgr = shift; @@ -157,7 +157,8 @@ sub get_internal { if ( defined $alias ) { if ( $max_depth < $depth ) { die MT->translate( - 'Alias for [_1] is looping in the configuration.', $alias ); + 'Alias for [_1] is looping in the configuration.', + $alias ); } local $depth = $depth + 1; return $mgr->get($alias); @@ -179,7 +180,7 @@ sub get_internal { $val = $val->() if ref $val eq 'CODE'; return first { defined $_ } - ( $val, $dbval, ( my $default = $mgr->default($var) )); + ( $val, $dbval, ( my $default = $mgr->default($var) ) ); } ## end sub get_internal @@ -229,18 +230,19 @@ sub set { } sub set_internal { - my $mgr = shift; + my $mgr = shift; my ( $var, $val, $db_flag ) = @_; - my $set = $db_flag ? '__dbvar' : '__var'; - $var = lc $var; - my $alias = $mgr->{__settings}{$var}{alias}; + my $set = $db_flag ? '__dbvar' : '__var'; + $var = lc $var; + my $alias = $mgr->{__settings}{$var}{alias}; $mgr->set_dirty() if defined($db_flag) && $db_flag; if ( defined $alias ) { if ( $max_depth < $depth ) { die MT->translate( - 'Alias for [_1] is looping in the configuration.', $alias ); + 'Alias for [_1] is looping in the configuration.', + $alias ); } local $depth = $depth + 1; return $mgr->set( $alias, $val, $db_flag ); @@ -268,7 +270,7 @@ sub set_internal { push @{ $mgr->{$set}{$var} }, $val if defined $val; } return $mgr->{$set}{$var}; - } + } ## end if ( $type eq 'ARRAY' ) elsif ( $type eq 'HASH' ) { my $hash = $mgr->{$set}{$var}; $hash = $mgr->default($var) unless defined $hash; @@ -343,7 +345,7 @@ sub save_config { my $h = $settings->{$_}; foreach my $k ( keys %$h ) { $data - .= $mgr->{__settings}{$_}{key} . ' ' + .= $mgr->{__settings}{$_}{key} . ' ' . $k . '=' . $h->{$k} . "\n"; } @@ -369,10 +371,9 @@ sub save_config { && ( ( $config->data || '' ) =~ m/^schemaversion/im ) ) { require Carp; - MT->log( - "Caught attempt to clear SchemaVersion setting. " - ."New config settings were:\n$data ".longmess() - ); + MT->log( "Caught attempt to clear SchemaVersion setting. " + . "New config settings were:\n$data " + . longmess() ); return; } } @@ -421,12 +422,13 @@ sub read_config_file { $val =~ s/\s*$// if defined($val); next unless $var && defined($val); $mgr->set( $var, $val ); - my $full = $mgr->{__var}{lc $var}; + my $full = $mgr->{__var}{ lc $var }; + # $ENV{CONFIGMGRDEBUG} # and diag ''.((caller(0))[3]) # .": Called set() with $var and $val. Current: " # .( ref $full ? Dumper($full) : $full); - } + } ## end while () close FH; 1; } ## end sub read_config_file @@ -458,7 +460,7 @@ sub read_config_db { } ## end sub read_config_db sub _parse_stringy_hash { - my $mgr = shift; + my $mgr = shift; my ($def) = @_; ( my ($key), my ($val) ) = split( /=/, $def ); return { $key => $val }; diff --git a/lib/MT/Core.pm b/lib/MT/Core.pm index 3982c7b2b..b29ec5b5b 100644 --- a/lib/MT/Core.pm +++ b/lib/MT/Core.pm @@ -314,12 +314,13 @@ BEGIN { 'EnableArchivePaths' => { default => 0, }, 'SearchTemplatePath' => { default => 'search_templates', path => 1, }, + # The following three are aliased, with the latter two being # deprecated in favor of the first. # LocalLib is included for people upgrading to Melody from MT 5.1+ - 'PERL5LIB' => { path => 1, type => 'ARRAY' }, - 'PerlLocalLibPath' => { alias => 'PERL5LIB' }, # Deprecated. - 'LocalLib' => { alias => 'PERL5LIB' }, # Deprecated. + 'PERL5LIB' => { path => 1, type => 'ARRAY' }, + 'PerlLocalLibPath' => { alias => 'PERL5LIB' }, # Deprecated. + 'LocalLib' => { alias => 'PERL5LIB' }, # Deprecated. 'SupportDirectoryPath' => { default => '' }, 'SupportDirectoryURL' => { default => '' }, 'ObjectDriver' => undef, @@ -328,20 +329,20 @@ BEGIN { 'DisableObjectCache' => { default => 0, }, 'AllowedTextFilters' => undef, 'Serializer' => { default => 'MT', }, - 'SendMailPath' => { default => '/usr/lib/sendmail', }, - 'RsyncPath' => undef, - 'TimeOffset' => { default => 0, }, - 'WSSETimeout' => { default => 120, }, - 'StaticWebPath' => { default => '', }, - 'StaticFilePath' => undef, - 'CGIPath' => { default => '/cgi-bin/', }, - 'AdminCGIPath' => undef, - 'CookieDomain' => undef, - 'CookiePath' => undef, - 'MailEncoding' => { default => 'ISO-8859-1', }, - 'MailTransfer' => { default => 'sendmail' }, - 'SMTPServer' => { default => 'localhost', }, - 'DebugEmailAddress' => undef, + 'SendMailPath' => { default => '/usr/lib/sendmail', }, + 'RsyncPath' => undef, + 'TimeOffset' => { default => 0, }, + 'WSSETimeout' => { default => 120, }, + 'StaticWebPath' => { default => '', }, + 'StaticFilePath' => undef, + 'CGIPath' => { default => '/cgi-bin/', }, + 'AdminCGIPath' => undef, + 'CookieDomain' => undef, + 'CookiePath' => undef, + 'MailEncoding' => { default => 'ISO-8859-1', }, + 'MailTransfer' => { default => 'sendmail' }, + 'SMTPServer' => { default => 'localhost', }, + 'DebugEmailAddress' => undef, 'WeblogsPingURL' => { default => 'http://rpc.weblogs.com/RPC2', }, 'BlogsPingURL' => { default => 'http://ping.blo.gs/', }, 'MTPingURL' => @@ -554,7 +555,7 @@ BEGIN { 'SingleCommunity' => { default => 1 }, 'DefaultTemplateSet' => { default => 'DePoClean_theme' }, - 'AssetFileTypes' => { type => 'HASH' }, + 'AssetFileTypes' => { type => 'HASH' }, 'AssetFileExtensions' => { type => 'ARRAY', default => undef, diff --git a/lib/MT/Image.pm b/lib/MT/Image.pm index 30a035f49..348a55a99 100644 --- a/lib/MT/Image.pm +++ b/lib/MT/Image.pm @@ -94,30 +94,28 @@ sub check_upload { if ( $ext =~ m/(jpe?g|png|gif|bmp|tiff?|ico)/i ) { - my %sig_args = $fh ? ( fh => $fh ) - : $local ? ( path => $local ) - : (); - die 'No filehandle or path provided' - unless keys %sig_args; + my %sig_args = $fh ? ( fh => $fh ) : $local ? ( path => $local ) : (); + die 'No filehandle or path provided' unless keys %sig_args; - my $has_html = $class->has_html_signature( %sig_args ); - $has_html and return $class->errtrans( "Invalid upload file" ); + my $has_html = $class->has_html_signature(%sig_args); + $has_html and return $class->errtrans("Invalid upload file"); unless ( defined($has_html) ) { - return $class->errtrans( 'Error reading image [_1]: [_2]', - $local_base, $class->errstr); + return + $class->errtrans( 'Error reading image [_1]: [_2]', + $local_base, $class->errstr ); } - } ## end if ( $ext =~ m/(jpe?g|png|gif|bmp|tiff?|ico)/i) + } ## Use Image::Size to check if the uploaded file is an image, and if so, ## record additional image info (width, height). We first rewind the ## filehandle $fh, then pass it in to imgsize. seek $fh, 0, 0; eval { require Image::Size; }; - $@ and return $class->errtrans( - "Perl module Image::Size is required to determine " - . "width and height of uploaded images." - ); + $@ + and return $class->errtrans( + "Perl module Image::Size is required to determine " + . "width and height of uploaded images." ); my ( $w, $h, $id ) = Image::Size::imgsize($fh); @@ -177,13 +175,13 @@ sub check_upload { } ## end sub check_upload sub has_html_signature { - my $class = shift; - my %args = @_; - my ($fh, $data, $path) = @args{'fh','data','path'}; + my $class = shift; + my %args = @_; + my ( $fh, $data, $path ) = @args{ 'fh', 'data', 'path' }; unless ( $data || $fh || $path ) { return $class->errtrans( - "No valid arguments passed to MT::Image::has_html_signature"); + "No valid arguments passed to MT::Image::has_html_signature"); } # Convert path to filehandle if provided @@ -191,15 +189,16 @@ sub has_html_signature { use Symbol; $fh = gensym(); open $fh, $path - or return $class->errtrans( - "Could not open $path for reading: $!"); + or return $class->errtrans("Could not open $path for reading: $!"); binmode($fh); } die "No valid arguments passed to MT::Image::has_html_signature" - unless $data or $fh; + unless $data + or $fh; my @patterns = ( + # NOTE: The following patterns will be matched against a string # with all whitespace stripped to simplify HTML matching. qr{ @@ -209,8 +208,7 @@ sub has_html_signature { [!?]|frameset|iframe|link|base|style|div|p|font| applet|meta|center|form|isindex|h[123456]|b|br ) - }ix, - qr{<(html|script|title|body|head|plaintext|table|img|pre|a)}i, + }ix, qr{<(html|script|title|body|head|plaintext|table|img|pre|a)}i, qr{text/html}i, ); @@ -222,8 +220,9 @@ sub has_html_signature { defined $data and return substr( $data, 0, $buffer ); my $str; seek( $fh, 0, 0 ); - defined( $buffer_read = read( $fh, $str, $buffer) ) - || die "Could not read filehandle: $!"; + defined( $buffer_read = read( $fh, $str, $buffer ) ) + || die "Could not read filehandle: $!"; + # print STDERR "read_buffer: $buffer, buffer_read: $buffer_read\n"; seek( $fh, 0, 0 ); return $str; @@ -232,24 +231,26 @@ sub has_html_signature { # Get 1024 bytes of whitespace-free content my $buffer = 1024; my $test_string; - while ( ! defined $test_string ) { - my $str = $read_buffer->( $buffer ); - $str =~ s{\s}{}g; # Strip whitespace, + while ( !defined $test_string ) { + my $str = $read_buffer->($buffer); + $str =~ s{\s}{}g; # Strip whitespace, - # If result string is long enough, trim down to 1024 and assign + # If result string is long enough, trim down to 1024 and assign # to $test_string which will terminate the while loop - if ( length $str >= 1024 ) { - $test_string = substr( $str, 0, 1024 ); + if ( length $str >= 1024 ) { + $test_string = substr( $str, 0, 1024 ); } + # File is shorter than our buffer elsif ( $buffer_read < 1024 ) { - $test_string = $str + $test_string = $str; } + # Otherwise, increase the buffer size by 1024 and repeat else { $buffer += 1024; } - } + } ## end while ( !defined $test_string) return scalar grep { $test_string =~ $_ } @patterns; diff --git a/lib/MT/Util.pm b/lib/MT/Util.pm index 753051a0b..24afa83e9 100644 --- a/lib/MT/Util.pm +++ b/lib/MT/Util.pm @@ -2741,28 +2741,30 @@ sub to_json { # Tested in t/99-utils.misc # TODO Move this to MT::FileMgr (perhaps?) sub file_extension { - my $fname = shift; + my $fname = shift; require File::Basename; - my @parts = split(/\./, File::Basename::basename($fname)); + my @parts = split( /\./, File::Basename::basename($fname) ); shift @parts - while @parts > 1 and $parts[0] eq ''; # Skips empty dotfile element + while @parts > 1 and $parts[0] eq ''; # Skips empty dotfile element - return @parts > 1 ? pop @parts : '' -} ## end sub file_extension + return @parts > 1 ? pop @parts : ''; +} # Tested in t/99-utils.misc sub file_mime_type { - my $file = shift; + my $file = shift; + # Probably best not to return a default value because it obscures failure # my $default = 'application/octet-stream'; my $default = ''; my $external_lib_error = sub { - return MT->instance->translate( - "An non-fatal error occurred when trying " - . "to determine the files MIME type using the [_1] module: ", - +shift - ) + return + MT->instance->translate( + "An non-fatal error occurred when trying " + . "to determine the files MIME type using the [_1] module: ", + +shift + ); }; my $lwp_mediatypes = sub { @@ -2785,28 +2787,27 @@ sub file_mime_type { }; return ( $lwp_mediatypes->() || $file_mmagic->() || $default ); -} ## end sub get_mime_type +} ## end sub file_mime_type # Tested in t/99-utils.misc sub mime_type_extension { require LWP::MediaTypes; - my @exts = LWP::MediaTypes::media_suffix( shift ) - or return; + my @exts = LWP::MediaTypes::media_suffix(shift) or return; return wantarray ? @exts : shift @exts; -} ## end sub mime_type_extension +} # Tested in t/99-utils.misc # TODO Move this to MT::FileMgr (perhaps?) sub match_file_extension { my $filename = shift; - my $exts = ref $_[0] eq 'ARRAY' ? shift : [ @_ ]; + my $exts = ref $_[0] eq 'ARRAY' ? shift : [@_]; require File::Basename; - my @exts = map { m/^\./ ? qr/$_/i : qr/\.$_/i } @$exts; - my @ret = File::Basename::fileparse( $filename, @exts ); + my @exts = map { m/^\./ ? qr/$_/i : qr/\.$_/i } @$exts; + my @ret = File::Basename::fileparse( $filename, @exts ); return $ret[2] if @ret; -} ## end sub match_file_extension +} package MT::Util::XML::SAX::LexicalHandler; diff --git a/lib/MT/XMLRPCServer.pm b/lib/MT/XMLRPCServer.pm index 6ff6d48f3..97e7659dd 100644 --- a/lib/MT/XMLRPCServer.pm +++ b/lib/MT/XMLRPCServer.pm @@ -1411,9 +1411,9 @@ sub newMediaObject { die _fault( MT->translate( "Invalid filename '[_1]'", $fname ) ); } - $mt->validate_upload({ filename => $fname }) - or die _fault( $mt->errstr ); - + $mt->validate_upload( { filename => $fname } ) + or die _fault( $mt->errstr ); + # Copy the filename and extract the extension. my $ext = $fname; $ext =~ m!.*\.(.*)$! diff --git a/t/00-compile.t b/t/00-compile.t index d2c26878d..15fd38991 100644 --- a/t/00-compile.t +++ b/t/00-compile.t @@ -121,6 +121,7 @@ use_ok('MT::DateTime'); use_ok('MT::DefaultTemplates'); use_ok('MT::FileMgr'); use_ok('MT::FileMgr::Local'); + # use_ok('MT::FileMgr::DAV'); # use_ok('MT::FileMgr::FTP'); # use_ok('MT::FileMgr::SFTP'); @@ -144,6 +145,7 @@ use_ok('MT::Util::Archive'); use_ok('MT::Util::Archive::Tgz'); use_ok('MT::Util::Archive::Zip'); use_ok('MT::Util::Captcha'); + # Temporarily removed from prod builds # use_ok('MT::Util::LogProcessor'); use_ok('MT::Util::PerformanceData'); diff --git a/t/02-meta-new.t b/t/02-meta-new.t index 59e0cd0ff..d5c12ecfa 100644 --- a/t/02-meta-new.t +++ b/t/02-meta-new.t @@ -46,8 +46,8 @@ is( $ref_blog->my_meta_hash->{something}, 'else', "New meta column has the right HASH value ({'something' => 'else'}) after update" ); -$ref_blog->clear_cache - ; # reset ramcache to make sure data is coming from memcached +$ref_blog + ->clear_cache; # reset ramcache to make sure data is coming from memcached $ref_blog->my_meta_hash( { a_new => 'hash' } ); $ref_blog->meta_obj->save; diff --git a/t/03-meta-new-author.t b/t/03-meta-new-author.t index dc0889b12..eae8cc812 100644 --- a/t/03-meta-new-author.t +++ b/t/03-meta-new-author.t @@ -47,8 +47,8 @@ is( $ref_o->my_meta_hash->{something}, 'else', "New meta column has the right HASH value ({'something' => 'else'}) after update" ); -$ref_o->clear_cache - ; # reset ramcache to make sure data is coming from memcached +$ref_o + ->clear_cache; # reset ramcache to make sure data is coming from memcached $ref_o->my_meta_hash( { a_new => 'hash' } ); $ref_o->meta_obj->save; diff --git a/t/04-config.t b/t/04-config.t index 7f0287e19..1c43f9c4c 100644 --- a/t/04-config.t +++ b/t/04-config.t @@ -25,10 +25,10 @@ $ENV{CONFIGMGRDEBUG} = 0; # The massive default value list of DeniedAssetFileExtensions my @denied_exts = qw( - ascx asis asp aspx bat cfc cfm cgi cmd com cpl dll - exe htaccess html? inc jhtml js jsb jsp mht(ml)? - msi php[s\d]? phtml? pif pl pwml py reg scr - sh shtml? vbs vxd + ascx asis asp aspx bat cfc cfm cgi cmd com cpl dll + exe htaccess html? inc jhtml js jsb jsp mht(ml)? + msi php[s\d]? phtml? pif pl pwml py reg scr + sh shtml? vbs vxd ); my ( $mt, $cfg, $cfg_file ); @@ -39,9 +39,9 @@ subtest "Read config test for MT constructor" => sub { $cfg = init_config(); - isa_ok( $mt, 'MT' ); - isa_ok( $cfg, 'MT::ConfigMgr' ); - ok( -f db_dir().'/mt.db', 'Database file' ); + isa_ok( $mt, 'MT' ); + isa_ok( $cfg, 'MT::ConfigMgr' ); + ok( -f db_dir() . '/mt.db', 'Database file' ); }; @@ -50,17 +50,17 @@ subtest 'MT::ConfigMgr API - accessors/mutators/defaults' => sub { plan tests => 6; ## Test standard get/set - $cfg->set( 'DataSource', './db2' ); + $cfg->set( 'DataSource', './db2' ); is( $cfg->get('DataSource'), './db2', 'get(DataSource)=./db2' ); ## Test autoloaded methods is( $cfg->DataSource, './db2', 'autoloaded DataSource=./db2' ); - $cfg->DataSource( './db'); + $cfg->DataSource('./db'); is( $cfg->DataSource, './db', 'autoloaded DataSource=./db2' ); ## Test defaults - is( $cfg->Serializer, 'MT', 'Serializer=MT' ); - is( $cfg->TimeOffset, 0, 'TimeOffset=0' ); + is( $cfg->Serializer, 'MT', 'Serializer=MT' ); + is( $cfg->TimeOffset, 0, 'TimeOffset=0' ); ## Test bug in early version of ConfigMgr where space was not ## stripped from the ends of values. @@ -69,58 +69,63 @@ subtest 'MT::ConfigMgr API - accessors/mutators/defaults' => sub { }; -subtest 'MT::ConfigMgr API - accessors/mutators/defaults for ARRAY directives' - => sub { +subtest + 'MT::ConfigMgr API - accessors/mutators/defaults for ARRAY directives' => + sub { plan tests => 12; my @array_vars - = qw( AssetFileExtensions PluginPath DeniedAssetFileExtensions ); + = qw( AssetFileExtensions PluginPath DeniedAssetFileExtensions ); ## Test data type for ARRAY directives; is( $cfg->type($_), 'ARRAY', "MT::ConfigMgr::type: $_ is ARRAY" ) - foreach @array_vars; + foreach @array_vars; ## Test contextual return values (list vs scalar) - my @exts = $cfg->DeniedAssetFileExtensions; # List context returns array - my $exts = $cfg->DeniedAssetFileExtensions; # Scalar context returns ref + my @exts = $cfg->DeniedAssetFileExtensions; # List context returns array + my $exts = $cfg->DeniedAssetFileExtensions; # Scalar context returns ref is_deeply( $exts, \@exts, - 'MT::ConfigMgr::get: Contextual return values' ); + 'MT::ConfigMgr::get: Contextual return values' ); ## Test array directive default values - is_deeply( [ $cfg->AssetFileExtensions ], - [], - 'MT::ConfigMgr::get ARRAY directive defaults: ' - .'AssetFileExtensions undefined' ); + is_deeply( + [ $cfg->AssetFileExtensions ], + [], + 'MT::ConfigMgr::get ARRAY directive defaults: ' + . 'AssetFileExtensions undefined' + ); my $got = $cfg->PluginPath; - is_deeply( $got, - # Converted by MT::init_config into an absolute path - [ File::Spec->catdir( $mt->{config_dir}, 'plugins' ) ], - 'MT::ConfigMgr::get ARRAY directive defaults: PluginPath is populated' ) - || diag explain $got; - - is_deeply( $exts, - \@denied_exts, - 'MT::ConfigMgr::get ARRAY directive defaults: ' - .'DeniedAssetFileExtensions is heavily populated' + is_deeply( + $got, + + # Converted by MT::init_config into an absolute path + [ File::Spec->catdir( $mt->{config_dir}, 'plugins' ) ], + 'MT::ConfigMgr::get ARRAY directive defaults: PluginPath is populated' + ) || diag explain $got; + + is_deeply( + $exts, + \@denied_exts, + 'MT::ConfigMgr::get ARRAY directive defaults: ' + . 'DeniedAssetFileExtensions is heavily populated' ); ## Test MT::ConfigMgr::default() method - foreach ( @array_vars ) { + foreach (@array_vars) { my $vals = $cfg->$_; my $defs = $cfg->default($_); if ( $cfg->is_path($_) ) { + # Cloned so we don't affect the referent - my @temp = map { File::Spec->catdir( $mt->{config_dir}, $_ ) } - @$defs; + my @temp + = map { File::Spec->catdir( $mt->{config_dir}, $_ ) } @$defs; $defs = \@temp; } - is_deeply( - $defs, - $vals, - "MT::ConfigMgr::default: Method matches value for $_" ) - || diag explain $defs; + is_deeply( $defs, $vals, + "MT::ConfigMgr::default: Method matches value for $_" ) + || diag explain $defs; } ## Test appending to an existing ARRAY directive @@ -129,26 +134,25 @@ subtest 'MT::ConfigMgr API - accessors/mutators/defaults for ARRAY directives' $cfg->set( 'PluginPath', 'seekret' ); @ppaths = $cfg->PluginPath; - is( - scalar @ppaths, + is( scalar @ppaths, $orig_cnt + 1, - 'MT::ConfigMgr::set: Scalar value arg appends to ARRAY directive' - ); + 'MT::ConfigMgr::set: Scalar value arg appends to ARRAY directive' ); ## Test overriding an existing ARRAY directive my @replacements = qw( ernie bert elmo zoe ); - $cfg->set( 'PluginPath', [ @replacements ] ); + $cfg->set( 'PluginPath', [@replacements] ); @ppaths = $cfg->PluginPath; - is_deeply( \@ppaths, [ @replacements ], + is_deeply( \@ppaths, [@replacements], 'MT::ConfigMgr::set: Arrayref value arg overwrites ARRAY directive' ); -}; + }; subtest "Config file assignment of ARRAY directives" => sub { plan tests => 4; - $cfg = init_config(<<" CFG" + $cfg = init_config( + <<" CFG" AltTemplate foo bar AltTemplate baz quux DeniedAssetFileExtensions xls @@ -160,30 +164,31 @@ subtest "Config file assignment of ARRAY directives" => sub { # Test AltTemplate config data type is( $cfg->type('AltTemplate'), 'ARRAY', 'AltTemplate=ARRAY' ); - TODO: { + TODO: { local $TODO = 'Search app hack overrides default behavior and ' - . 'prepends the default value to the array'; - # See MT::App::Search::Legacy::init_request - # and MT::App::Search::load_search_tmpl + . 'prepends the default value to the array'; + + # See MT::App::Search::Legacy::init_request + # and MT::App::Search::load_search_tmpl # Test for overriden ARRAY value my $paths = $cfg->AltTemplate; - is_deeply( $paths, [ 'foo bar', 'baz quux' ], - 'AltTemplate: Config file overrides defaults' ) - or diag explain $paths; + is_deeply( $paths, + [ 'foo bar', 'baz quux' ], + 'AltTemplate: Config file overrides defaults' ) + or diag explain $paths; } # Test for overridden ARRAY value my $override = [qw( xls doc ppt )]; - my $exts = $cfg->DeniedAssetFileExtensions; - is_deeply( - $exts, - [qw( xls doc ppt )], - 'DeniedAssetFileExtensions: Config file overrides default' - ) || diag explain $exts; + my $exts = $cfg->DeniedAssetFileExtensions; + is_deeply( $exts, [qw( xls doc ppt )], + 'DeniedAssetFileExtensions: Config file overrides default' ) + || diag explain $exts; # Write new config using special __DEFAULT__ value - $cfg = init_config(<<" CFG" + $cfg = init_config( + <<" CFG" DeniedAssetFileExtensions __DEFAULT__ DeniedAssetFileExtensions huey DeniedAssetFileExtensions dewey @@ -194,17 +199,17 @@ subtest "Config file assignment of ARRAY directives" => sub { # Test for values appended onto ARRAY default value $exts = $cfg->DeniedAssetFileExtensions; is_deeply( - $exts, - [ @denied_exts, qw( huey dewey louie ) ], - 'DeniedAssetFileExtensions: Config file with __DEFAULT__ appends') - || diag explain $exts; + $exts, + [ @denied_exts, qw( huey dewey louie ) ], + 'DeniedAssetFileExtensions: Config file with __DEFAULT__ appends' + ) || diag explain $exts; }; # subtest 'MT::ConfigMgr API - accessors/mutators/defaults for HASH directives' => sub { # plan tests => 0; # }; -# +# # subtest "Config file assignment of HASH directives" => sub { # plan tests => 0; # # AtomApp @@ -216,7 +221,8 @@ subtest "Config file assignment of ARRAY directives" => sub { # # AssetFileTypes # }; -{ local $ENV{CONFIGMGRDEBUG} = 1; +{ + local $ENV{CONFIGMGRDEBUG} = 1; } { @@ -225,11 +231,11 @@ subtest "Config file assignment of ARRAY directives" => sub { sub base_config { return $base_config if $base_config; my $app = MT->instance - or die "Could not get MT instance: " . MT->errstr; + or die "Could not get MT instance: " . MT->errstr; my $mgr = $app->config() - or die "Could not instantiate base config: ". $app->errstr; + or die "Could not instantiate base config: " . $app->errstr; $base_config = $mgr->{__config_contents} - or die "Base config is empty: " . $mgr->errstr; + or die "Base config is empty: " . $mgr->errstr; } sub db_dir { @@ -241,28 +247,27 @@ subtest "Config file assignment of ARRAY directives" => sub { sub create_db_dir { my $db_dir = db_dir(); - -d $db_dir || mkdir($db_dir) - or die "Could not create DB directory: $!"; + -d $db_dir || mkdir($db_dir) or die "Could not create DB directory: $!"; $db_dir; } sub write_config_file { - my $data = shift || ''; + my $data = shift || ''; my ( $fh, $cfg_file ) = tempfile(); $ENV{CONFIGMGRDEBUG} - and diag __PACKAGE__."::write_config_file: cfg_file = $cfg_file"; + and diag __PACKAGE__ . "::write_config_file: cfg_file = $cfg_file"; - print $fh join("\n", base_config(), $data )."\n"; + print $fh join( "\n", base_config(), $data ) . "\n"; close $fh; return $cfg_file; } sub init_config { my $config = shift || ''; - $config =~ s{^[\s\t]+}{}gsm; # Strip leading space from heredoc + $config =~ s{^[\s\t]+}{}gsm; # Strip leading space from heredoc - $cfg_file = write_config_file( $config ) - or die "Could not write config file: $!"; + $cfg_file = write_config_file($config) + or die "Could not write config file: $!"; my $db_dir = create_db_dir(); @@ -274,8 +279,9 @@ sub init_config { undef $MT::ConfigMgr::cfg; $ENV{MT_CONFIG} = $mt->{cfg_file} = $cfg_file; - $mt->init_config({ Directory => $mt->{mt_dir} }); + $mt->init_config( { Directory => $mt->{mt_dir} } ); + # $mt->{config_dir} = dirname( db_dir() ); return $mt->config(); -} +} ## end sub init_config diff --git a/t/09-image.t b/t/09-image.t index c192ca82c..7b336add1 100644 --- a/t/09-image.t +++ b/t/09-image.t @@ -27,7 +27,7 @@ BEGIN { * scalar @drivers * 19 ) # 19 tests each for every image and driver + 1 # has_html_signature - ; + ; } MT->set_language('en-us'); @@ -51,11 +51,9 @@ for my $rec (@Img) { $cfg->ImageDriver($driver); my $img = MT::Image->new( Filename => $img_file ) - or diag explain - sprintf( - "%s: Could not instantiate MT::Image object from %s: %s", - $driver, $img_file, MT::Image->errstr() - ); + or diag explain + sprintf( "%s: Could not instantiate MT::Image object from %s: %s", + $driver, $img_file, MT::Image->errstr() ); SKIP: { skip( "no $driver image", 19 ) unless $img; @@ -142,18 +140,16 @@ for my $rec (@Img) { } ## end for my $rec (@Img) subtest "MT::Image::has_html_signature" => sub { - my $images = File::Spec->catdir( $ENV{MT_HOME}, qw( t images )); + my $images = File::Spec->catdir( $ENV{MT_HOME}, qw( t images ) ); my $real = MT::Image->has_html_signature( - path => File::Spec->catfile( $images, 'test.jpg' ) - ); + path => File::Spec->catfile( $images, 'test.jpg' ) ); is( $real, 0, 'has_html_signature with real image' ); - defined $real or diag "Err: ".MT::Image->errstr; + defined $real or diag "Err: " . MT::Image->errstr; my $fake = MT::Image->has_html_signature( - path => File::Spec->catfile( $images, 'fake.jpg' ) - ); + path => File::Spec->catfile( $images, 'fake.jpg' ) ); is( $fake, 1, 'has_html_signature with fake image' ) - or diag MT::Image->errstr; - defined $fake or diag "Err: ".MT::Image->errstr; + or diag MT::Image->errstr; + defined $fake or diag "Err: " . MT::Image->errstr; }; diff --git a/t/110-cms-permission.t b/t/110-cms-permission.t index 1dbc67f82..1e00dca83 100644 --- a/t/110-cms-permission.t +++ b/t/110-cms-permission.t @@ -8,7 +8,7 @@ BEGIN { } use lib 't/lib', 'lib', 'extlib', 'addons/Commercial.pack/lib', - 'addons/Enterprise.pack/lib'; + 'addons/Enterprise.pack/lib'; use MT; use MT::Author; @@ -35,13 +35,14 @@ my $other = MT::Author->load(998); # ichikawa # Create a new Asset # __mode=save&_type=asset&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'asset', - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'asset', + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new asset" ); @@ -50,14 +51,15 @@ ok( $out =~ m!Permission denied!i, "Create a new Asset: result" ); # Delete Asset # __mode=delete&_type=asset&blog_id=1&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'asset', - blog_id => 1, - id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'asset', + blog_id => 1, + id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete asset" ); @@ -66,14 +68,15 @@ ok( $out =~ m/Permission denied/i, "Delete asset: result" ); # Update an asset # __mode=save&_type=asset&blog_id=1&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $other, - __request_method => 'POST', - __mode => 'save', - _type => 'asset', - blog_id => 1, - id => 1 - } + 'MT::App::CMS', + { + __test_user => $other, + __request_method => 'POST', + __mode => 'save', + _type => 'asset', + blog_id => 1, + id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Update an asset" ); @@ -82,30 +85,31 @@ ok( $out =~ m!Permission denied!i, "Update an asset: result" ); # Create a new Author # __mode=save&_type=author&name=new_author&type=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'author', - name => 'new_author', - type => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'author', + name => 'new_author', + type => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new author" ); -ok( $out =~ m/Permission denied/i, - "Create a new Author: result" ); +ok( $out =~ m/Permission denied/i, "Create a new Author: result" ); # Delete Author # __mode=delete&_type=author&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'author', - id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'author', + id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete author" ); @@ -114,30 +118,30 @@ ok( $out =~ m/Permission denied/i, "Delete author: result" ); # Create a new Association # __mode=save&_type=association&type=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'association', - type => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'association', + type => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new association" ); -ok( $out =~ m/Permission denied/i, - "Create a new Association: result" -); +ok( $out =~ m/Permission denied/i, "Create a new Association: result" ); # Delete Association # __mode=delete&_type=association&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'association', - id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'association', + id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete association" ); @@ -146,13 +150,14 @@ ok( $out =~ m/Permission denied/i, "Delete association: result" ); # Create a new Blog # __mode=save&_type=blog&name=BlogName $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'blog', - name => 'BlogName' - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'blog', + name => 'BlogName' + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new blog" ); @@ -161,13 +166,14 @@ ok( $out =~ m/Permission denied/i, "Create a new Blog: result" ); # Delete Blog # __mode=delete&_type=blog&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'blog', - id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'blog', + id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete blog" ); @@ -176,31 +182,32 @@ ok( $out =~ m/Permission denied/i, "Delete blog: result" ); # Create a new Category # __mode=save&_type=category&label=CategoryName&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'category', - label => 'CategoryName', - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'category', + label => 'CategoryName', + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new category" ); -ok( $out =~ m/Permission denied/i, - "Create a new Category: result" ); +ok( $out =~ m/Permission denied/i, "Create a new Category: result" ); # Delete Category # __mode=delete&_type=category&id=1&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'category', - id => 1, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'category', + id => 1, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete category" ); @@ -209,31 +216,32 @@ ok( $out =~ m/Permission denied/i, "Delete category: result" ); # Create a new Folder # __mode=save&_type=folder&label=FolderName&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'folder', - label => 'FolderName', - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'folder', + label => 'FolderName', + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new folder" ); -ok( $out =~ m/Permission denied/i, - "Create a new Folder: result" ); +ok( $out =~ m/Permission denied/i, "Create a new Folder: result" ); # Delete Folder # __mode=delete&_type=folder&id=20&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'folder', - id => 20, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'folder', + id => 20, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete folder" ); @@ -242,15 +250,16 @@ ok( $out =~ m/Permission denied/i, "Delete folder: result" ); # Update Folder # __mode=save&_type=folder&label=FolderName&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $other, - __request_method => 'POST', - __mode => 'save', - _type => 'folder', - label => 'FolderName', - blog_id => 1, - id => 1 - } + 'MT::App::CMS', + { + __test_user => $other, + __request_method => 'POST', + __mode => 'save', + _type => 'folder', + label => 'FolderName', + blog_id => 1, + id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Update a folder" ); @@ -259,31 +268,32 @@ ok( $out =~ m/Permission denied/i, "Update a Folder: result" ); # Create a new Comment # __mode=save&_type=comment&&blog_id=1&entry_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'comment', - blog_id => 1, - entry_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'comment', + blog_id => 1, + entry_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new comment" ); -ok( $out =~ m/Permission denied/i, - "Create a new Comment: result" ); +ok( $out =~ m/Permission denied/i, "Create a new Comment: result" ); # Delete Comment # __mode=delete&_type=comment&id=1&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'comment', - id => 1, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'comment', + id => 1, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete comment" ); @@ -292,15 +302,16 @@ ok( $out =~ m/Permission denied/i, "Delete comment: result" ); # Create a new Entry # __mode=save&_type=entry&&blog_id=1&author_id=1&status=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'entry', - blog_id => 1, - author_id => 1, - status => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'entry', + blog_id => 1, + author_id => 1, + status => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new entry" ); @@ -309,14 +320,15 @@ ok( $out =~ m/Permission denied/i, "Create a new Entry: result" ); # Delete Entry # __mode=delete&_type=entry&id=1&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'entry', - id => 1, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'entry', + id => 1, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete entry" ); @@ -325,16 +337,17 @@ ok( $out =~ m/Permission denied/i, "Delete entry: result" ); # Update an Entry # __mode=save&_type=entry&&blog_id=1&author_id=1&status=1&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $other, - __request_method => 'POST', - __mode => 'save', - _type => 'entry', - blog_id => 1, - author_id => 1, - status => 1, - id => 1 - } + 'MT::App::CMS', + { + __test_user => $other, + __request_method => 'POST', + __mode => 'save', + _type => 'entry', + blog_id => 1, + author_id => 1, + status => 1, + id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Update an entry" ); @@ -343,15 +356,16 @@ ok( $out =~ m/Permission denied/i, "Update anEntry: result" ); # Create a new Page # __mode=save&_type=page&&blog_id=1&author_id=1&status=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'page', - blog_id => 1, - author_id => 1, - status => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'page', + blog_id => 1, + author_id => 1, + status => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new page" ); @@ -360,14 +374,15 @@ ok( $out =~ m/Permission denied/i, "Create a new Page: result" ); # Delete Page # __mode=delete&_type=page&id=20&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'page', - id => 20, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'page', + id => 20, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete page" ); @@ -376,16 +391,17 @@ ok( $out =~ m/Permission denied/i, "Delete page: result" ); # Update a Page # __mode=save&_type=page&&blog_id=1&author_id=1&status=1&id=20 $app = _run_app( - 'MT::App::CMS', - { __test_user => $other, - __request_method => 'POST', - __mode => 'save', - _type => 'page', - blog_id => 1, - author_id => 1, - status => 1, - id => 20 - } + 'MT::App::CMS', + { + __test_user => $other, + __request_method => 'POST', + __mode => 'save', + _type => 'page', + blog_id => 1, + author_id => 1, + status => 1, + id => 20 + } ); $out = delete $app->{__test_output}; ok( $out, "Update an page" ); @@ -394,47 +410,47 @@ ok( $out =~ m/Permission denied/i, "Update an Page: result" ); # Create a new Notification # __mode=save&_type=notification&&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'notification', - blog_id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'notification', + blog_id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new notification" ); -ok( $out =~ m/Permission denied/i, - "Create a new Notification: result" -); +ok( $out =~ m/Permission denied/i, "Create a new Notification: result" ); # Delete Notification # __mode=delete&_type=notification&id=1&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'notification', - id => 1, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'notification', + id => 1, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete notification" ); -ok( $out =~ m/Permission denied/i, - "Delete notification: result" ); +ok( $out =~ m/Permission denied/i, "Delete notification: result" ); # Create a new Role # __mode=save&_type=role&&blog_id=1&name=NewRole $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'role', - name => "NewRole" - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'role', + name => "NewRole" + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new role" ); @@ -443,13 +459,14 @@ ok( $out =~ m/Permission denied/i, "Create a new Role: result" ); # Delete Role # __mode=delete&_type=role&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'role', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'role', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete role" ); @@ -458,28 +475,29 @@ ok( $out =~ m/Permission denied/i, "Delete role: result" ); # Create a new Config # __mode=save&_type=config $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'config' - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'config' + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new config" ); -ok( $out =~ m/Permission denied/i, - "Create a new Config: result" ); +ok( $out =~ m/Permission denied/i, "Create a new Config: result" ); # Delete Config # __mode=delete&_type=config&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'config', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'config', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete config" ); @@ -488,29 +506,30 @@ ok( $out =~ m/Permission denied/i, "Delete config: result" ); # Create a new Fileinfo # __mode=save&_type=fileinfo&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'fileinfo', - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'fileinfo', + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new fileinfo" ); -ok( $out =~ m/Permission denied/i, - "Create a new Fileinfo: result" ); +ok( $out =~ m/Permission denied/i, "Create a new Fileinfo: result" ); # Delete Fileinfo # __mode=delete&_type=fileinfo&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'fileinfo', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'fileinfo', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete fileinfo" ); @@ -519,13 +538,14 @@ ok( $out =~ m/Permission denied/i, "Delete fileinfo: result" ); # Create a new Log # __mode=save&_type=log&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'log', - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'log', + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new log" ); @@ -534,13 +554,14 @@ ok( $out =~ m/Permission denied/i, "Create a new Log: result" ); # Delete Log # __mode=delete&_type=log&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'log', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'log', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete log" ); @@ -549,32 +570,32 @@ ok( $out =~ m/Permission denied/i, "Delete log: result" ); # Create a new ObjectAsset # __mode=save&_type=objectasset&asset_id=1&object_id=1&object_ds=entry $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'objectasset', - asset_id => 1, - object_id => 1, - object_ds => 'entry' - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'objectasset', + asset_id => 1, + object_id => 1, + object_ds => 'entry' + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new objectasset" ); -ok( $out =~ m/Permission denied/i, - "Create a new Objectasset: result" -); +ok( $out =~ m/Permission denied/i, "Create a new Objectasset: result" ); # Delete Objectasset # __mode=delete&_type=objectasset&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'objectasset', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'objectasset', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete objectasset" ); @@ -583,31 +604,31 @@ ok( $out =~ m/Permission denied/i, "Delete objectasset: result" ); # Create a new Objectscore # __mode=save&_type=objectscore&namespace=scope_name&object_ds=entry $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'objectscore', - namespace => 'scope_name', - object_ds => 'entry' - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'objectscore', + namespace => 'scope_name', + object_ds => 'entry' + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new objectscore" ); -ok( $out =~ m/Permission denied/i, - "Create a new Objectscore: result" -); +ok( $out =~ m/Permission denied/i, "Create a new Objectscore: result" ); # Delete Objectscore # __mode=delete&_type=objectscore&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'objectscore', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'objectscore', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete objectscore" ); @@ -616,32 +637,32 @@ ok( $out =~ m/Permission denied/i, "Delete objectscore: result" ); # Create a new Objecttag # __mode=save&_type=objecttag&tag_id=1&object_datasource=entry&object_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'objecttag', - object_datasource => 'entry', - tag_id => 1, - object_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'objecttag', + object_datasource => 'entry', + tag_id => 1, + object_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new objecttag" ); -ok( $out =~ m/Permission denied/i, - "Create a new Objecttag: result" -); +ok( $out =~ m/Permission denied/i, "Create a new Objecttag: result" ); # Delete Objecttag # __mode=delete&_type=objecttag&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'objecttag', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'objecttag', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete objecttag" ); @@ -650,31 +671,31 @@ ok( $out =~ m/Permission denied/i, "Delete objecttag: result" ); # Create a new Permission # __mode=save&_type=permission&blog_id=1&author_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'permission', - author_id => 1, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'permission', + author_id => 1, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new permission" ); -ok( $out =~ m/Permission denied/i, - "Create a new Permission: result" -); +ok( $out =~ m/Permission denied/i, "Create a new Permission: result" ); # Delete Permission # __mode=delete&_type=permission&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'permission', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'permission', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete permission" ); @@ -683,33 +704,33 @@ ok( $out =~ m/Permission denied/i, "Delete permission: result" ); # Create a new Placement # __mode=save&_type=placement&blog_id=1&category_id=1&entry_id=1&is_primary=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'placement', - blog_id => 1, - category_id => 1, - entry_id => 1, - is_primary => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'placement', + blog_id => 1, + category_id => 1, + entry_id => 1, + is_primary => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new placement" ); -ok( $out =~ m/Permission denied/i, - "Create a new Placement: result" -); +ok( $out =~ m/Permission denied/i, "Create a new Placement: result" ); # Delete Placement # __mode=delete&_type=placement&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'placement', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'placement', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete placement" ); @@ -718,30 +739,31 @@ ok( $out =~ m/Permission denied/i, "Delete placement: result" ); # Create a new Session # __mode=save&_type=session&id=THIS_IS_A_FAKE_SESSION_2&start=currenttime $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'session', - id => 'THIS_IS_A_FAKE_SESSION_2', - time => time - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'session', + id => 'THIS_IS_A_FAKE_SESSION_2', + time => time + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new session" ); -ok( $out =~ m/Permisison denied/i, - "Create a new Session: result" ); +ok( $out =~ m/Permisison denied/i, "Create a new Session: result" ); # Delete Session # __mode=delete&_type=session&id=THIS_IS_A_FAKE_SESSION $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'session', - id => 'THIS_IS_A_FAKE_SESSION', - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'session', + id => 'THIS_IS_A_FAKE_SESSION', + } ); $out = delete $app->{__test_output}; ok( $out, "Delete session" ); @@ -750,13 +772,14 @@ ok( $out =~ m/Permission denied/i, "Delete session: result" ); # Create a new Tag # __mode=save&_type=tag&name=NewTag $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'tag', - name => 'NewTag' - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'tag', + name => 'NewTag' + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new tag" ); @@ -765,13 +788,14 @@ ok( $out =~ m/Permission denied/i, "Create a new Tag: result" ); # Delete Tag # __mode=delete&_type=tag&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'tag', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'tag', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete tag" ); @@ -780,15 +804,16 @@ ok( $out =~ m/Permission denied/i, "Delete tag: result" ); # Create a new Ping # __mode=save&_type=ping&blog_id=1&ip=1.1.1.1&tb_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'ping', - blog_id => 1, - ip => '1.1.1.1', - tb_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'ping', + blog_id => 1, + ip => '1.1.1.1', + tb_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new ping" ); @@ -797,13 +822,14 @@ ok( $out =~ m/Permission denied/i, "Create a new Ping: result" ); # Delete Ping # __mode=delete&_type=ping&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'ping', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'ping', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete ping" ); @@ -812,12 +838,13 @@ ok( $out =~ m/Permission denied/i, "Delete ping: result" ); # Create a new Touch # __mode=save&_type=touch $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'touch', - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'touch', + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new touch" ); @@ -826,13 +853,14 @@ ok( $out =~ m/Permission denied/i, "Create a new Touch: result" ); # Delete Touch # __mode=delete&_type=touch&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'touch', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'touch', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete touch" ); @@ -841,30 +869,30 @@ ok( $out =~ m/Permission denied/i, "Delete touch: result" ); # Create a new Trackback # __mode=save&_type=trackback&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'trackback', - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'trackback', + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new trackback" ); -ok( $out =~ m/Permission denied/i, - "Create a new Trackback: result" -); +ok( $out =~ m/Permission denied/i, "Create a new Trackback: result" ); # Delete Trackback # __mode=delete&_type=trackback&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'trackback', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'trackback', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete trackback" ); @@ -873,32 +901,33 @@ ok( $out =~ m/Permission denied/i, "Delete trackback: result" ); # Create a new Template # __mode=save&_type=template&blog_id=1&name=NewTemplate&type=custom $user = MT::Author->load(3); # Bobd -$app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'template', - blog_id => 1, - name => 'NewTemplate', - type => 'custom' - } +$app = _run_app( + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'template', + blog_id => 1, + name => 'NewTemplate', + type => 'custom' + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new template" ); -ok( $out =~ m/Permission denied/i, - "Create a new Template: result" ); +ok( $out =~ m/Permission denied/i, "Create a new Template: result" ); # Delete Template # __mode=delete&_type=template&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'template', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'template', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete template" ); @@ -907,32 +936,32 @@ ok( $out =~ m/Permission denied/i, "Delete template: result" ); # Create a new Templatemap # __mode=save&_type=templatemap&blog_id=1&archive_type=Author&template_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'templatemap', - blog_id => 1, - archive_type => 'Author', - template_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'templatemap', + blog_id => 1, + archive_type => 'Author', + template_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new templatemap" ); -ok( $out =~ m/Permission denied/i, - "Create a new Templatemap: result" -); +ok( $out =~ m/Permission denied/i, "Create a new Templatemap: result" ); # Delete Templatemap # __mode=delete&_type=templatemap&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'templatemap', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'templatemap', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete templatemap" ); @@ -945,73 +974,75 @@ if ( $mt->component('commercial') ) { # Create a new Field # __mode=save&_type=field&blog_id=1&name=NewField&object_type=entry&type=SingleLineText&tag=newtag $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'field', - blog_id => 1, - name => 'NewField', - object_type => 'entry', - tag => 'newtag', - type => 'SingleLineText' - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'field', + blog_id => 1, + name => 'NewField', + object_type => 'entry', + tag => 'newtag', + type => 'SingleLineText' + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new field" ); - ok( $out =~ m/Permission denied/i, - "Create a new Field: result" ); + ok( $out =~ m/Permission denied/i, "Create a new Field: result" ); # Delete Field # __mode=delete&_type=field&id=1&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'field', - id => 1, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'field', + id => 1, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete field" ); ok( $out =~ m/Permission denied/i, "Delete field: result" ); -} +} ## end if ( $mt->component('commercial'...)) if ( $mt->component('enterprise') ) { # Create a new Group # __mode=save&_type=group&blog_id=1&name=NewGroup $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'group', - name => 'NewGroup', - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'group', + name => 'NewGroup', + } ); $out = delete $app->{__test_output}; ok( $out, "Create a new group" ); - ok( $out =~ m/Permission denied/i, - "Create a new Group: result" ); + ok( $out =~ m/Permission denied/i, "Create a new Group: result" ); # Delete Group # __mode=delete&_type=group&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'group', - id => 1, - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'group', + id => 1, + } ); $out = delete $app->{__test_output}; ok( $out, "Delete group" ); ok( $out =~ m/Permission denied/i, "Delete group: result" ); -} +} ## end if ( $mt->component('enterprise'...)) ### Different type @@ -1020,273 +1051,264 @@ $user = MT::Author->load(994); #kagawa # Update a Category # __mode=save&_type=category&label=CategoryName&blog_id=1&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'category', - label => 'CategoryName', - blog_id => 1, - id => 20 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'category', + label => 'CategoryName', + blog_id => 1, + id => 20 + } ); $out = delete $app->{__test_output}; ok( $out, "Update a category (different)" ); -ok( $out =~ m/Permission denied/i, - " Update a category (different): result" -); +ok( $out =~ m/Permission denied/i, " Update a category (different): result" ); # Delete Category # __mode=delete&_type=category&id=20&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'category', - id => 20, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'category', + id => 20, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete category (different)" ); -ok( $out =~ m/Permission denied/i, - "Delete category (different): result" -); +ok( $out =~ m/Permission denied/i, "Delete category (different): result" ); $user = MT::Author->load(995); #ogawa # Update a Folder # __mode=save&_type=category&label=CategoryName&blog_id=1&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'folder', - label => 'CategoryName', - blog_id => 1, - id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'folder', + label => 'CategoryName', + blog_id => 1, + id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Update a folder (different)" ); -ok( $out =~ m/Permission denied/i, - " Update a folder (different): result" -); +ok( $out =~ m/Permission denied/i, " Update a folder (different): result" ); # Delete Folder # __mode=delete&_type=folder&id=1&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'folder', - id => 1, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'folder', + id => 1, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete folfer (different)" ); -ok( $out =~ m/Permission denied/i, - "Delete folder (different): result" -); +ok( $out =~ m/Permission denied/i, "Delete folder (different): result" ); $user = MT::Author->load(995); #ogawa # Update a Page # __mode=save&_type=page&&blog_id=1&author_id=1&status=1&id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'page', - blog_id => 1, - author_id => 1, - status => 1, - id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'page', + blog_id => 1, + author_id => 1, + status => 1, + id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Update an page (different)" ); -ok( $out =~ m/Permission denied/i, - "Update an Page(different): result" -); +ok( $out =~ m/Permission denied/i, "Update an Page(different): result" ); # Delete Page # __mode=delete&_type=page&id=1&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'page', - id => 1, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'page', + id => 1, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete page (different)" ); -ok( $out =~ m/Permission denied/i, - "Delete page (different): result" -); +ok( $out =~ m/Permission denied/i, "Delete page (different): result" ); $user = MT::Author->load(994); #kagawa # Update an Entry # __mode=save&_type=entry&&blog_id=1&author_id=1&status=1&id=20 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'save', - _type => 'entry', - blog_id => 1, - author_id => 1, - status => 1, - id => 20 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'save', + _type => 'entry', + blog_id => 1, + author_id => 1, + status => 1, + id => 20 + } ); $out = delete $app->{__test_output}; ok( $out, "Update an entry (different)" ); -ok( $out =~ m/Permission denied/i, - "Update an Entry(different): result" -); +ok( $out =~ m/Permission denied/i, "Update an Entry(different): result" ); # Delete Entry # __mode=delete&_type=entry&id=20&blog_id=1 $app = _run_app( - 'MT::App::CMS', - { __test_user => $user, - __request_method => 'POST', - __mode => 'delete', - _type => 'entry', - id => 20, - blog_id => 1 - } + 'MT::App::CMS', + { + __test_user => $user, + __request_method => 'POST', + __mode => 'delete', + _type => 'entry', + id => 20, + blog_id => 1 + } ); $out = delete $app->{__test_output}; ok( $out, "Delete entry (different)" ); -ok( $out =~ m/Permission denied/i, - "Delete entry (different): result" -); +ok( $out =~ m/Permission denied/i, "Delete entry (different): result" ); sub make_data { ### Author require MT::Author; my $aikawa = MT::Author->new(); - $aikawa->set_values( - { name => 'aikawa', - nickname => 'Ichiro Aikawa', - email => 'aikawa@example.com', - url => 'http://aikawa.com/', - api_password => 'seecret', - auth_type => 'MT', - created_on => '19780131074500', - } + $aikawa->set_values( { + name => 'aikawa', + nickname => 'Ichiro Aikawa', + email => 'aikawa@example.com', + url => 'http://aikawa.com/', + api_password => 'seecret', + auth_type => 'MT', + created_on => '19780131074500', + } ); $aikawa->set_password("pass"); $aikawa->type( MT::Author::AUTHOR() ); $aikawa->id(999); $aikawa->save() - or die "Couldn't save author record 999: " . $aikawa->errstr; + or die "Couldn't save author record 999: " . $aikawa->errstr; MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); my $ichikawa = MT::Author->new(); - $ichikawa->set_values( - { name => 'ichikawa', - nickname => 'Jiro Ichikawa', - email => 'ichikawa@example.com', - url => 'http://ichikawa.com/', - api_password => 'seecret', - auth_type => 'MT', - created_on => '19780131074500', - } + $ichikawa->set_values( { + name => 'ichikawa', + nickname => 'Jiro Ichikawa', + email => 'ichikawa@example.com', + url => 'http://ichikawa.com/', + api_password => 'seecret', + auth_type => 'MT', + created_on => '19780131074500', + } ); $ichikawa->set_password("pass"); $ichikawa->type( MT::Author::AUTHOR() ); $ichikawa->id(998); $ichikawa->save() - or die "Couldn't save author record 998: " . $ichikawa->errstr; + or die "Couldn't save author record 998: " . $ichikawa->errstr; MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); my $ukawa = MT::Author->new(); - $ukawa->set_values( - { name => 'ukawa', - nickname => 'Saburo Ukawa', - email => 'ukawa@example.com', - url => 'http://ukawa.com/', - api_password => 'seecret', - auth_type => 'MT', - created_on => '19780131074500', - } + $ukawa->set_values( { + name => 'ukawa', + nickname => 'Saburo Ukawa', + email => 'ukawa@example.com', + url => 'http://ukawa.com/', + api_password => 'seecret', + auth_type => 'MT', + created_on => '19780131074500', + } ); $ukawa->set_password("pass"); $ukawa->type( MT::Author::AUTHOR() ); $ukawa->id(997); $ukawa->save() - or die "Couldn't save author record 997: " . $ukawa->errstr; + or die "Couldn't save author record 997: " . $ukawa->errstr; MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); my $ogawa = MT::Author->new(); - $ogawa->set_values( - { name => 'ogawa', - nickname => 'Goro Ogawa', - email => 'ogawa@example.com', - url => 'http://ogawa.com/', - api_password => 'seecret', - auth_type => 'MT', - created_on => '19780131074500', - } + $ogawa->set_values( { + name => 'ogawa', + nickname => 'Goro Ogawa', + email => 'ogawa@example.com', + url => 'http://ogawa.com/', + api_password => 'seecret', + auth_type => 'MT', + created_on => '19780131074500', + } ); $ogawa->set_password("pass"); $ogawa->type( MT::Author::AUTHOR() ); $ogawa->id(995); $ogawa->save() - or die "Couldn't save author record 995: " . $ogawa->errstr; + or die "Couldn't save author record 995: " . $ogawa->errstr; MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); my $kagawa = MT::Author->new(); - $kagawa->set_values( - { name => 'kagawa', - nickname => 'Ichiro Kagawa', - email => 'kagawa@example.com', - url => 'http://kagawa.com/', - api_password => 'seecret', - auth_type => 'MT', - created_on => '19780131074500', - } + $kagawa->set_values( { + name => 'kagawa', + nickname => 'Ichiro Kagawa', + email => 'kagawa@example.com', + url => 'http://kagawa.com/', + api_password => 'seecret', + auth_type => 'MT', + created_on => '19780131074500', + } ); $kagawa->set_password("pass"); $kagawa->type( MT::Author::AUTHOR() ); $kagawa->id(994); $kagawa->save() - or die "Couldn't save author record 994: " . $kagawa->errstr; + or die "Couldn't save author record 994: " . $kagawa->errstr; MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); ### Role require MT::Role; my $role = MT::Role->new(); - $role->set_values( - { name => 'Entry Editor', - perms => [ - 'create_post', 'edit_all_posts', - 'edit_tags', 'edit_categories', - 'publish_post', 'comment', - ], - } + $role->set_values( { + name => 'Entry Editor', + perms => [ + 'create_post', 'edit_all_posts', + 'edit_tags', 'edit_categories', + 'publish_post', 'comment', + ], + } ); $role->id(20); - $role->save - or die "Couldn't save role record 20: " . $role->errstr; + $role->save or die "Couldn't save role record 20: " . $role->errstr; ### Association my $designer_role = MT::Role->load( { name => 'Designer' } ); @@ -1343,15 +1365,15 @@ sub make_data { ### Notification require MT::Notification; my $address = MT::Notification->new(); - $address->set_values( - { blog_id => 1, - name => 'Foo Bar', - email => 'foo@example.com', - url => 'http://foo.com', - } + $address->set_values( { + blog_id => 1, + name => 'Foo Bar', + email => 'foo@example.com', + url => 'http://foo.com', + } ); $address->save() - or die "Couldn't save notification record: 1" . $address->errstr; + or die "Couldn't save notification record: 1" . $address->errstr; MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); @@ -1362,16 +1384,15 @@ sub make_data { $sess->kind('UD'); $sess->start(time); $sess->set( 'remember', 1 ); - $sess->save - or die "Couldn't save session record" . $sess->errstr; + $sess->save or die "Couldn't save session record" . $sess->errstr; ### Log - MT->log( - { message => 'This is a log message.', - class => "system", - level => MT::Log::ERROR(), - category => "test", - } + MT->log( { + message => 'This is a log message.', + class => "system", + level => MT::Log::ERROR(), + category => "test", + } ); MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); @@ -1380,17 +1401,17 @@ sub make_data { if ( $mt->component('commercial') ) { require CustomFields::Field; my $field = CustomFields::Field->new(); - $field->set_values( - { blog_id => 1, - name => 'SingleLine', - obj_type => 'entry', - type => 'SingleLineText', - tag => 'EntryDataSingleLine', - basename => 'singleline', - } + $field->set_values( { + blog_id => 1, + name => 'SingleLine', + obj_type => 'entry', + type => 'SingleLineText', + tag => 'EntryDataSingleLine', + basename => 'singleline', + } ); $field->save() - or die "Couldn't save custom field record: 1" . $field->errstr; + or die "Couldn't save custom field record: 1" . $field->errstr; } MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); @@ -1399,16 +1420,12 @@ sub make_data { require MT::Group; my $group = MT::Group->new(); $group->set_values( - { name => 'New Group', - status => 1, - display_name => 'Group', - } - ); + { name => 'New Group', status => 1, display_name => 'Group', } ); $group->save() - or die "Couldn't save group record: 1" . $group->errstr; + or die "Couldn't save group record: 1" . $group->errstr; } MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); -} +} ## end sub make_data diff --git a/t/30-support-files.t b/t/30-support-files.t index d84ee3688..b76cd550f 100644 --- a/t/30-support-files.t +++ b/t/30-support-files.t @@ -2,10 +2,11 @@ use strict; use warnings; + BEGIN { use lib qw( lib extlib t/lib ); $ENV{MT_CONFIG} = 'sqlite-test.cfg'; - $ENV{MT_APP} = 'MT::App::CMS'; + $ENV{MT_APP} = 'MT::App::CMS'; } use Test::More tests => 7; @@ -19,36 +20,37 @@ my $cfg = $app->config; diag('Now testing default SupportDirectoryPath and SupportDirectoryURL'); -is( $cfg->get('SupportDirectoryPath'), '', - 'Default SupportDirectoryPath config'); #1 +is( $cfg->get('SupportDirectoryPath'), + '', 'Default SupportDirectoryPath config' ); #1 -is( $cfg->get('SupportDirectoryURL'), '', - 'Default SupportDirectoryURL config' ); #2 +is( $cfg->get('SupportDirectoryURL'), + '', 'Default SupportDirectoryURL config' ); #2 -is( $app->support_directory_path(), - File::Spec->catdir( $app->static_file_path, 'support').'/', - 'Default $app->support_directory_path()' ); #3 +is( $app->support_directory_path(), + File::Spec->catdir( $app->static_file_path, 'support' ) . '/', + 'Default $app->support_directory_path()' ); #3 is( $app->support_directory_url(), - File::Spec->catdir($app->static_path, 'support').'/', - 'Default $app->support_directory_url()' ); #4 + File::Spec->catdir( $app->static_path, 'support' ) . '/', + 'Default $app->support_directory_url()' ); #4 diag('Now setting SupportDirectoryPath and SupportDirectoryURL'); -$cfg->set('SupportDirectoryPath', '/PATH/TO/SOME/SUPPORT' ); -$cfg->set('SupportDirectoryURL', 'http://example.com/PATH/TO/SOME/SUPPORT' ); +$cfg->set( 'SupportDirectoryPath', '/PATH/TO/SOME/SUPPORT' ); +$cfg->set( 'SupportDirectoryURL', 'http://example.com/PATH/TO/SOME/SUPPORT' ); + +is( $app->support_directory_path(), + '/PATH/TO/SOME/SUPPORT/', 'Updated $app->support_directory_path()' ); #5 -is( $app->support_directory_path(), - '/PATH/TO/SOME/SUPPORT/', - 'Updated $app->support_directory_path()' ); #5 - -is( $app->support_directory_url(), +is( + $app->support_directory_url(), 'http://example.com/PATH/TO/SOME/SUPPORT/', - 'Updated $app->support_directory_path()' ); #6 + 'Updated $app->support_directory_path()' +); #6 my $builder = MT::Builder->new; -my $ctx = MT::Template::Context->new; -my $tokens = $builder->compile( $ctx, '<$mt:SupportDirectoryURL$>' ); #7 -is( $builder->build( $ctx, $tokens ), +my $ctx = MT::Template::Context->new; +my $tokens = $builder->compile( $ctx, '<$mt:SupportDirectoryURL$>' ); #7 +is( $builder->build( $ctx, $tokens ), $app->support_directory_url(), - '<$mt:SupportDirectoryURL$>' ); #7 + '<$mt:SupportDirectoryURL$>' ); #7 diff --git a/t/33-driver.t b/t/33-driver.t index fe316b81f..33b106cd9 100755 --- a/t/33-driver.t +++ b/t/33-driver.t @@ -18,7 +18,8 @@ use lib 't/lib'; BEGIN { plan skip_all => "Configuration file $ENV{MT_CONFIG} not found" - if ! exists $ENV{MT_CONFIG} or !-r "t/$ENV{MT_CONFIG}"; + if !exists $ENV{MT_CONFIG} + or !-r "t/$ENV{MT_CONFIG}"; } use MT::Test qw(:testdb :time); diff --git a/t/92-pubqueue.t b/t/92-pubqueue.t index f57bc84c3..0f60fbcaa 100644 --- a/t/92-pubqueue.t +++ b/t/92-pubqueue.t @@ -134,7 +134,7 @@ foreach my $blog (@blogs) { my $rebuild = $mt->rebuild( BlogID => $blog->id, Force => 1 ) || 0; ok( $rebuild, "Rebuilt all without the publish queue" ) - or diag explain 'A publishing error occurred: '.$mt->errstr; + or diag explain 'A publishing error occurred: ' . $mt->errstr; @jobs = MT::TheSchwartz::Job->load(); $job_count = scalar(@jobs); diff --git a/t/93-init_plugin.t b/t/93-init_plugin.t index 30fffe93a..189c1eef0 100644 --- a/t/93-init_plugin.t +++ b/t/93-init_plugin.t @@ -1,7 +1,8 @@ #!/usr/bin/perl package MT::Test::Plugin::Init; + # -# In this test we prove our assertions about which of our test plugins: +# In this test we prove our assertions about which of our test plugins: # * should NOT BE LOADED ( e.g. stray, non-subfoldered ) # * SHOULD load # * should load BUT should generate a warning ( e.g. perl init plugins) @@ -24,7 +25,7 @@ use Test::More tests => 11; # Serves as a constant boolean flag # determining this package's debug mode -sub DEBUG() { 0 } +sub DEBUG() {0} our $debug = sub { DEBUG && print @_, "\n" }; sub main { @@ -33,71 +34,66 @@ sub main { ### ### CORE INITIALIZATION ### - my %test_data = $pkg->init_test_data(); - my ($app, $stderr) = $pkg->init_test_app(); - $debug = $pkg->debug_handle(); + my %test_data = $pkg->init_test_data(); + my ( $app, $stderr ) = $pkg->init_test_app(); + $debug = $pkg->debug_handle(); # Debug dump post_init state $debug->( MT::Test->mt_package_hashvars_dump() ); - # Re-initialize all component intialization related MT package vars - MT::Test::revert_component_init( $pkg ); + # Re-initialize all component intialization related MT package vars + MT::Test::revert_component_init($pkg); # Debug dump post-reinit state - $debug->( MT::Test->mt_package_hashvars_dump() ); + $debug->( MT::Test->mt_package_hashvars_dump() ); my $Tests = $pkg->merge_observed_data( \%test_data ); - $pkg->test_init_warnings( $stderr ); + $pkg->test_init_warnings($stderr); - foreach my $testinfo ( @$Tests ) { + foreach my $testinfo (@$Tests) { my ( $sig, $test ) = each %$testinfo; - $debug->( Dumper({ sig => $sig, test => $test }) ); + $debug->( Dumper( { sig => $sig, test => $test } ) ); subtest $sig => sub { plan tests => 2; - my $expected = $test->{expected}; + my $expected = $test->{expected}; $expected->{name} ||= 'NO NAME PLUGIN'; $expected->{base_class} ||= 'MT::Plugin'; $expected->{message} ||= " exists"; if ( $expected->{name} eq 'Two YAMLs - second' ) { - TODO: { - local $TODO = 'Alternate YAML config names not yet supported. See https://github.com/openmelody/melody/blob/master/lib/MT.pm#L1756'; - $pkg->test_plugin_loaded( $sig, $expected ); - }; + TODO: { + local $TODO + = 'Alternate YAML config names not yet supported. See https://github.com/openmelody/melody/blob/master/lib/MT.pm#L1756'; + $pkg->test_plugin_loaded( $sig, $expected ); + } } else { $pkg->test_plugin_loaded( $sig, $expected ); } }; - } + } ## end foreach my $testinfo (@$Tests) require MT::Template::Context; my $ctx = MT::Template::Context->new; my $b = MT::Builder->new; - my $result = $b->build( $ctx, $b->compile( $ctx, '' )); - is( (! defined $result and $b->errstr =~ m{Unknown tag found}), 1, - 'IDontExist tag from ignored perl plugin' ); -} + my $result = $b->build( $ctx, $b->compile( $ctx, '' ) ); + is( ( !defined $result and $b->errstr =~ m{Unknown tag found} ), + 1, 'IDontExist tag from ignored perl plugin' ); +} ## end sub main sub test_plugin_loaded { - my $pkg = shift; + my $pkg = shift; my ( $sig, $info ) = @_; - my $loaded = $info->{not_loaded} ? 0 : 1; - is( - ( $sig && exists $MT::Plugins{$sig} ) ? 1 : 0, - $loaded, - $sig . $info->{message} - ); - SKIP: { + my $loaded = $info->{not_loaded} ? 0 : 1; + is( ( $sig && exists $MT::Plugins{$sig} ) ? 1 : 0, + $loaded, $sig . $info->{message} ); + SKIP: { skip "Plugin not loaded", 1 unless $loaded; is( ref( $MT::Plugins{$sig}->{'object'} ), $info->{base_class}, - join(' ', $info->{name}, - 'base class is', - $info->{base_class} - ) + join( ' ', $info->{name}, 'base class is', $info->{base_class} ) ); } } @@ -108,40 +104,27 @@ sub test_plugin_loaded { sub init_test_data { my $pkg = shift; return ( - 'ConfigAssistant.pack/config.yaml' => { - name => 'Configuration Assistant', - base_class => 'MT::Component', - }, - 'Awesome/config.yaml' => { - name => 'Oh Awesome', - }, - 'Rebless/config.yaml' => { - name => 'Rebless Me', - base_class => 'Rebless::Plugin', - }, - 'TwoYAMLs/config.yaml' => { - name => 'Two YAMLs - config', - }, - 'TwoYAMLs/second.yaml' => { - name => 'Two YAMLs - second', - }, - 'IgnorePerl/config.yaml' => { - name => 'Ignore perl - YAML initialized - YAY', - }, - 'stray.pl' => { - message => ': Stray, unloaded perl plugin', - not_loaded => 1, - }, - 'stray.yaml' => { - message => ': Stray, unloaded yaml plugin', - not_loaded => 1, - }, - 'subfoldered/subfoldered.pl' => { - name => 'A Subfoldered Plugin', - base_class => 'MT::Plugin::Subfoldered', - } + 'ConfigAssistant.pack/config.yaml' => { + name => 'Configuration Assistant', + base_class => 'MT::Component', + }, + 'Awesome/config.yaml' => { name => 'Oh Awesome', }, + 'Rebless/config.yaml' => + { name => 'Rebless Me', base_class => 'Rebless::Plugin', }, + 'TwoYAMLs/config.yaml' => { name => 'Two YAMLs - config', }, + 'TwoYAMLs/second.yaml' => { name => 'Two YAMLs - second', }, + 'IgnorePerl/config.yaml' => + { name => 'Ignore perl - YAML initialized - YAY', }, + 'stray.pl' => + { message => ': Stray, unloaded perl plugin', not_loaded => 1, }, + 'stray.yaml' => + { message => ': Stray, unloaded yaml plugin', not_loaded => 1, }, + 'subfoldered/subfoldered.pl' => { + name => 'A Subfoldered Plugin', + base_class => 'MT::Plugin::Subfoldered', + } ); -} +} ## end sub init_test_data ### @@ -149,53 +132,54 @@ sub init_test_data { ### sub init_test_app { my $pkg = shift; - my $warnings = stderr_from { + my $warnings = stderr_from { eval { + # require MT; require MT::Test; import MT::Test qw( :app :db ); }; - if ( $@ ) { diag( $@ ) and die "Aborting" } + if ($@) { diag($@) and die "Aborting" } }; # print STDERR "YOYO: ".${"${$pkg}::debug"}."\n\n"; - $debug->( "WARNINGS generated during app init: $warnings"); + $debug->("WARNINGS generated during app init: $warnings"); return ( MT->instance(), $warnings ); } sub merge_observed_data { my ( $pkg, $test_data ) = @_; - + # Augment the expected plugin test data with the # plugin object and it's enabled status. Store in an # array of hashes each keyed by the plugin's signature my @tests; foreach my $sig ( sort keys %$test_data ) { - my $profile = $MT::Plugins{ $sig }; - push( @tests, - { - $sig => { - expected => $test_data->{ $sig }, - plugin => $profile->{object}, - enabled => $profile->{enabled}, - } - } + my $profile = $MT::Plugins{$sig}; + push( + @tests, + { + $sig => { + expected => $test_data->{$sig}, + plugin => $profile->{object}, + enabled => $profile->{enabled}, + } + } ); } return \@tests; -} +} ## end sub merge_observed_data ### ### TEST GROUP #1: LOAD WARNINGS AND ERRORS ( 1 TEST ) ### sub test_init_warnings { - my $pkg = shift; + my $pkg = shift; my $stderr = shift || ''; like( $stderr, qr/.+plugin \(subfoldered.pl\).+deprecated plugin file format/, - 'Deprecation warning for perl-init plugins' - ); + 'Deprecation warning for perl-init plugins' ); } __PACKAGE__->main(); diff --git a/t/93-plugins.t b/t/93-plugins.t index a936071d4..180a275af 100644 --- a/t/93-plugins.t +++ b/t/93-plugins.t @@ -6,44 +6,41 @@ use Data::Dumper; use Test::Warn; use Test::More tests => 11; use MT; -use MT::Log::Log4perl qw( l4mtdump ); use Log::Log4perl qw( :resurrect ); +use MT::Log::Log4perl qw( l4mtdump ); +use Log::Log4perl qw( :resurrect ); ###l4p our $logger = MT::Log::Log4perl->new(); $logger->trace(); -our ( $app ); -my %Test = (); # Hash of tests to run -my @extra_plugins; # Array of (custom?) plugins which are not included +our ($app); +my %Test = (); # Hash of tests to run +my @extra_plugins; # Array of (custom?) plugins which are not included # Bundled plugins included in our tests indexed by plugin # signature with expected test values my %bundled_plugins = ( 'Markdown.plugin/config.yaml' => { - name => 'Markdown and SmartyPants', - base_class => 'MT::Plugin', # <----- DEFAULT - plugin_path => 'addons', # <----- DEFAULT - enabled => 1, # <----- DEFAULT - }, - 'ThemeExport.plugin/config.yaml' => { name => 'Theme Exporter' }, - 'ThemeManager.plugin/config.yaml' => { name => 'Theme Manager' }, - 'DePoClean.plugin/config.yaml' => { name => 'DePoClean' }, - 'WXRImporter.plugin/config.yaml' => { name => 'WXR Importer' }, - 'ClassicBlogThemePack.plugin/config.yaml' - => { name => 'Classic Blog Theme Pack' }, - 'SixApartEditor.plugin/config.yaml' - => { name => 'Six Apart Rich Text Editor' }, - 'MelodyFeedback.plugin/config.yaml' - => { name => 'Open Melody Community Feedback' }, - 'MultiBlog.plugin/config.yaml' => { - name => 'MultiBlog', - base_class => 'MultiBlog::Plugin', + name => 'Markdown and SmartyPants', + base_class => 'MT::Plugin', # <----- DEFAULT + plugin_path => 'addons', # <----- DEFAULT + enabled => 1, # <----- DEFAULT }, + 'ThemeExport.plugin/config.yaml' => { name => 'Theme Exporter' }, + 'ThemeManager.plugin/config.yaml' => { name => 'Theme Manager' }, + 'DePoClean.plugin/config.yaml' => { name => 'DePoClean' }, + 'WXRImporter.plugin/config.yaml' => { name => 'WXR Importer' }, + 'ClassicBlogThemePack.plugin/config.yaml' => + { name => 'Classic Blog Theme Pack' }, + 'SixApartEditor.plugin/config.yaml' => + { name => 'Six Apart Rich Text Editor' }, + 'MelodyFeedback.plugin/config.yaml' => + { name => 'Open Melody Community Feedback' }, + 'MultiBlog.plugin/config.yaml' => + { name => 'MultiBlog', base_class => 'MultiBlog::Plugin', }, 'TypePadAntiSpam.plugin/config.yaml' => { - name => 'TypePad AntiSpam', - base_class => 'TypePadAntiSpam::Plugin', - }, - 'ConfigAssistant.pack/config.yaml' => { - name => 'Configuration Assistant', - base_class => 'MT::Component', + name => 'TypePad AntiSpam', + base_class => 'TypePadAntiSpam::Plugin', }, + 'ConfigAssistant.pack/config.yaml' => + { name => 'Configuration Assistant', base_class => 'MT::Component', }, ); # Initialize app and plugins @@ -55,24 +52,22 @@ $app->init_plugins(); # Compile test data for LOADED plugins foreach my $sig ( sort keys %MT::Plugins ) { - my $info = delete $bundled_plugins{ $sig }; - unless ( $info ) { + my $info = delete $bundled_plugins{$sig}; + unless ($info) { push( @extra_plugins, $sig ); next; } - my $profile = $MT::Plugins{ $sig }; - $Test{ $sig } = { - enabled => $profile->{enabled} || 0, - plugin => $profile->{object}, - $info ? (info => $info) : (), - } + my $profile = $MT::Plugins{$sig}; + $Test{$sig} = { + enabled => $profile->{enabled} || 0, + plugin => $profile->{object}, + $info ? ( info => $info ) : (), + }; } # Compile test data for NON-LOADED plugins foreach my $sig ( sort keys %bundled_plugins ) { - $Test{ $sig } = { - info => $bundled_plugins{ $sig } - } + $Test{$sig} = { info => $bundled_plugins{$sig} }; } # Execute the tests @@ -84,23 +79,18 @@ foreach my $sig ( sort keys %Test ) { $info->{base_class} ||= 'MT::Plugin'; $info->{message} ||= " exists"; my $loaded = $info->{not_loaded} ? 0 : 1; - is( - ($sig && exists $MT::Plugins{$sig}) ? 1 : 0, - $loaded, - $sig . $info->{message} - ); - SKIP: { + is( ( $sig && exists $MT::Plugins{$sig} ) ? 1 : 0, + $loaded, $sig . $info->{message} ); + SKIP: { skip "Plugin not loaded", 1 unless $loaded; - is( - ref( $MT::Plugins{$sig}->{'object'} ), + is( ref( $MT::Plugins{$sig}->{'object'} ), $info->{base_class}, - $info->{name}.' base class is '.$info->{base_class} - ); + $info->{name} . ' base class is ' . $info->{base_class} ); } }; } # Warn about any plugins not included since they might be newly bundled -diag("The following plugins were not included in the test: \n\t* " - .join("\n\t* ", @extra_plugins)); +diag( "The following plugins were not included in the test: \n\t* " + . join( "\n\t* ", @extra_plugins ) ); diff --git a/t/99-utils-misc.t b/t/99-utils-misc.t index 6d426612d..4d7625451 100755 --- a/t/99-utils-misc.t +++ b/t/99-utils-misc.t @@ -12,7 +12,8 @@ use Test::More tests => 4; use MT; use MT::Util; -use MT::Log::Log4perl qw( l4mtdump ); use Log::Log4perl qw( :resurrect ); +use MT::Log::Log4perl qw( l4mtdump ); +use Log::Log4perl qw( :resurrect ); ###l4p our $logger = MT::Log::Log4perl->new(); $logger->trace(); # Initialize app and plugins @@ -116,104 +117,110 @@ use MT::Test qw( :app :db ); subtest 'file_extension()' => sub { my %tests = ( - 'file.txt' => 'txt', - 'file.tar.gz' => 'gz', - 'file.' => '', - 'file.0' => 0, - 'file' => '', - '.htaccess' => '', - '.my.cnf' => 'cnf', - '.' => '', - '..' => '', + 'file.txt' => 'txt', + 'file.tar.gz' => 'gz', + 'file.' => '', + 'file.0' => 0, + 'file' => '', + '.htaccess' => '', + '.my.cnf' => 'cnf', + '.' => '', + '..' => '', ); plan tests => scalar keys %tests; - is( MT::Util::file_extension( $_ ), $tests{$_}, - "'$_' returns '$tests{$_}'" ) - foreach keys %tests; + is( MT::Util::file_extension($_), + $tests{$_}, "'$_' returns '$tests{$_}'" ) + foreach keys %tests; }; subtest 'file_mime_type()' => sub { my %tests = ( - 'COPYING' => 'text/plain', - 'readme.html' => 'text/html', - 'mt-static/styles.css' => 'text/css', - 'mt-static/mt.js' => 'application/javascript', - 't/images/test.gif' => 'image/gif', - 't/images/test.jpg' => 'image/jpeg', + 'COPYING' => 'text/plain', + 'readme.html' => 'text/html', + 'mt-static/styles.css' => 'text/css', + 'mt-static/mt.js' => 'application/javascript', + 't/images/test.gif' => 'image/gif', + 't/images/test.jpg' => 'image/jpeg', ); plan tests => scalar keys %tests; require File::Spec; foreach my $key ( keys %tests ) { is( - MT::Util::file_mime_type( File::Spec->catfile( $ENV{MT_HOME}, $key )), + MT::Util::file_mime_type( + File::Spec->catfile( $ENV{MT_HOME}, $key ) + ), $tests{$key}, "'$key' returns '$tests{$key}'" - ) + ); } }; subtest "mime_type_extension()" => sub { my %tests = ( - 'text/plain' => 'txt', - 'text/html', => 'html', - 'text/css', => 'css', - 'application/javascript', => 'js', - 'image/gif', => 'gif', - 'image/jpeg', => 'jpeg', - 'video/3gpp' => '3gp', - 'video/mpeg' => 'mpeg', - 'video/mp4' => 'mp4', - 'video/quicktime' => 'mov', - 'audio/mpeg' => 'mp3', - 'audio/x-wav' => 'wav', - 'audio/ogg' => 'ogg', + 'text/plain' => 'txt', + 'text/html', => 'html', + 'text/css', => 'css', + 'application/javascript', => 'js', + 'image/gif', => 'gif', + 'image/jpeg', => 'jpeg', + 'video/3gpp' => '3gp', + 'video/mpeg' => 'mpeg', + 'video/mp4' => 'mp4', + 'video/quicktime' => 'mov', + 'audio/mpeg' => 'mp3', + 'audio/x-wav' => 'wav', + 'audio/ogg' => 'ogg', ); plan tests => scalar keys %tests; foreach my $type ( keys %tests ) { my $ext = $tests{$type}; - my @extensions = MT::Util::mime_type_extension( $type ); - ok(( grep { /^$ext$/ } @extensions ), "'$type' returns '$tests{$type}'" ); + my @extensions = MT::Util::mime_type_extension($type); + ok( ( grep {/^$ext$/} @extensions ), + "'$type' returns '$tests{$type}'" ); } }; subtest "match_file_extension()" => sub { my @tests = ( + # FILE NAME EXTENSION SEARCH ARRAY EXPECTED RESULT - [ 'file.txt' => ['txt'] => '.txt' ], - [ 'file.txt' => [ qw( text doc rtf txt md ) ] => '.txt' ], - [ 'file.js' => [ qw( html js php ) ] => '.js' ], - [ 'file.json' => [ qw( html js php ) ] => '' ], - [ 'file.js' => [ qw( html json php ) ] => '' ], - [ 'file.json' => [ qw( html js.* php ) ] => '.json' ], - [ 'file.js' => [ qw( html js.* php ) ] => '.js' ], - [ 'file.php' => [ qw( html js.* php[s\d]? ) ] => '.php' ], - [ 'file.php3' => [ qw( html js.* php[s\d]? ) ] => '.php3' ], - [ 'file.php5' => [ qw( html js.* php[s\d]? ) ] => '.php5' ], - [ 'file.phps' => [ qw( html js.* php[s\d]? ) ] => '.phps' ], - [ '.htaccess' => [ qw( cnf conf htaccess ) ] => '.htaccess' ], - [ '.my.cnf' => [ qw( cnf conf htaccess ) ] => '.cnf' ], - [ 'file.tar.gz' => [ qw( Z bz2 gz zip ) ] => '.gz' ], - [ 'file.tar.gz' => [ qw( Z bz2 tar zip ) ] => '' ], - [ 'file.tar.gz' => [ qw( Z bz2 tar\.gz zip ) ] => '.tar.gz' ], - [ '.' => [ qw( cgi txt pl ) ] => '' ], - [ '..' => [ qw( cgi txt pl ) ] => '' ], + [ 'file.txt' => ['txt'] => '.txt' ], + [ 'file.txt' => [qw( text doc rtf txt md )] => '.txt' ], + [ 'file.js' => [qw( html js php )] => '.js' ], + [ 'file.json' => [qw( html js php )] => '' ], + [ 'file.js' => [qw( html json php )] => '' ], + [ 'file.json' => [qw( html js.* php )] => '.json' ], + [ 'file.js' => [qw( html js.* php )] => '.js' ], + [ 'file.php' => [qw( html js.* php[s\d]? )] => '.php' ], + [ 'file.php3' => [qw( html js.* php[s\d]? )] => '.php3' ], + [ 'file.php5' => [qw( html js.* php[s\d]? )] => '.php5' ], + [ 'file.phps' => [qw( html js.* php[s\d]? )] => '.phps' ], + [ '.htaccess' => [qw( cnf conf htaccess )] => '.htaccess' ], + [ '.my.cnf' => [qw( cnf conf htaccess )] => '.cnf' ], + [ 'file.tar.gz' => [qw( Z bz2 gz zip )] => '.gz' ], + [ 'file.tar.gz' => [qw( Z bz2 tar zip )] => '' ], + [ 'file.tar.gz' => [qw( Z bz2 tar\.gz zip )] => '.tar.gz' ], + [ '.' => [qw( cgi txt pl )] => '' ], + [ '..' => [qw( cgi txt pl )] => '' ], ); plan tests => @tests * 2; - foreach my $test ( @tests ) { - my ($fname, $exts, $expected) = @$test; + foreach my $test (@tests) { + my ( $fname, $exts, $expected ) = @$test; foreach my $path ( '', '/tmp/' ) { $fname = $path . $fname; is( MT::Util::match_file_extension( $fname, $exts ), $expected, - sprintf( "Matching '%s' against (%s) returns '%s'", - $fname, join(', ', @$exts), $expected ) + sprintf( + "Matching '%s' against (%s) returns '%s'", + $fname, join( ', ', @$exts ), $expected + ) ); } } diff --git a/t/lib/MT/Test.pm b/t/lib/MT/Test.pm index ff6814845..c61ef155e 100644 --- a/t/lib/MT/Test.pm +++ b/t/lib/MT/Test.pm @@ -185,7 +185,7 @@ sub init_testdb { # to only contain the test 'Foo', 'Bar' classes and neuter # the require MT::Upgrade; - + # Add our test 'Foo' and 'Bar' classes to the list of # object classes to install. %MT::Upgrade::classes = ( foo => 'Foo', bar => 'Bar' ); @@ -400,23 +400,24 @@ sub init_db { } sub debug_handle { - return $_[0]->DEBUG ? sub { diag( @_ ) } # Diagnostic output function - : sub { }; # No-op function + return $_[0]->DEBUG + ? sub { diag(@_) } # Diagnostic output function + : sub { }; # No-op function } sub revert_component_init { - my $pkg = shift; - my $debug = $pkg->debug_handle( shift ); - my $mt = MT->instance; + my $pkg = shift; + my $debug = $pkg->debug_handle(shift); + my $mt = MT->instance; # MT package scalar variables we need to reset my @global_scalars = qw( plugin_sig plugin_envelope - plugin_registry plugins_installed - $plugin_full_path ); - my $c_hash = \%MT::Components; # Aliased... - my $c_arry = \@MT::Components; # for... - my $p_hash = \%MT::Plugins; # brevity! - $debug->( 'INITIAL %MT::Components: ' . Dumper( $c_hash )); + plugin_registry plugins_installed + $plugin_full_path ); + my $c_hash = \%MT::Components; # Aliased... + my $c_arry = \@MT::Components; # for... + my $p_hash = \%MT::Plugins; # brevity! + $debug->( 'INITIAL %MT::Components: ' . Dumper($c_hash) ); # We are reinitializing everything *BUT* the core component # so we need to preserve it before destroying the rest. @@ -424,14 +425,15 @@ sub revert_component_init { my $core = delete $c_hash->{core} or die "No core component found!"; - $debug->( 'Undefining all MT package scalar vars ' - . 'related to component/plugin initialization' ); + $debug->( 'Undefining all MT package scalar vars ' + . 'related to component/plugin initialization' ); no strict 'refs'; - undef ${"MT::$_"} and $debug->( "\t\$MT::$_" ) for @global_scalars; + undef ${"MT::$_"} and $debug->("\t\$MT::$_") for @global_scalars; # %MT::addons Anyone??????Bueller?? Bueller?? { + # As it says in MT.pm: # Reset the Text_filters hash in case it was preloaded by plugins # by calling all_text_filters (Markdown in particular does this). @@ -442,61 +444,63 @@ sub revert_component_init { } $debug->('Unloading plugins\' perl init scripts from %INC cache'); + # This forces both perl and MT to treat the file as if it's never been # loaded previously which is necessary for making MT process the plugin # as it does in its own init methods. foreach my $pdata ( values %$p_hash ) { my $path = first { defined($_) and m{\.pl}i } - $pdata->{object}{"full_path","path"}; + $pdata->{object}{ "full_path", "path" }; next unless $path; - delete $INC{ $path } and $debug->("\t$path"); + delete $INC{$path} and $debug->("\t$path"); } # And finally: Re-initialize %MT::Components and @MT::Components # with only the 'core' component and undef %MT::Plugins completely - $c_arry = [ $core ]; + $c_arry = [$core]; $c_hash = { core => $core }; - $p_hash = { }; + $p_hash = {}; # Find and initialize all non-core components #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# - my %path_params = ( - Config => $mt->{config_dir}, - Directory => $mt->{mt_dir} - ); - my $killme = sub { die "FAIL ".Carp::longmess() }; + my %path_params + = ( Config => $mt->{config_dir}, Directory => $mt->{mt_dir} ); + my $killme = sub { die "FAIL " . Carp::longmess() }; + #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# eval { $debug->('Re-initializing addons'); - $mt->init_addons() or $killme->(); + $mt->init_addons() or $killme->(); - $mt->init_config_from_db( \%path_params ) or $killme->(); + $mt->init_config_from_db( \%path_params ) or $killme->(); $mt->init_debug_mode; $debug->('Re-initializing plugins'); - $mt->init_plugins() or $killme->(); + $mt->init_plugins() or $killme->(); # Set the plugins_installed flag signalling that it's # okay to initialize the schema and use the database. no warnings 'once'; - $MT::plugins_installed = 1; + $MT::plugins_installed = 1; }; - die "Failed: $@".Carp::longmess() if $@; + die "Failed: $@" . Carp::longmess() if $@; $debug->('Plugins re-initialization complete'); -} +} ## end sub revert_component_init { my $re_looped = 0; + sub mt_package_hashvars_dump { my $pkg = shift; my $re = $re_looped++ ? 're' : ''; - my $sep = '---'x25; - return join( "\n\n", - $sep, - 'Components ${re}initialized: ' . Dumper(\%MT::Components), - 'Plugins ${re}initialized: ' . Dumper(\%MT::Plugins), - $sep, - ); + my $sep = '---' x 25; + return + join( "\n\n", + $sep, + 'Components ${re}initialized: ' . Dumper( \%MT::Components ), + 'Plugins ${re}initialized: ' . Dumper( \%MT::Plugins ), + $sep, + ); } } diff --git a/t/lib/Test/Output.pm b/t/lib/Test/Output.pm index d0e984a89..ca1f554de 100644 --- a/t/lib/Test/Output.pm +++ b/t/lib/Test/Output.pm @@ -7,50 +7,44 @@ use strict; use Test::Builder; use Test::Output::Tie; use Sub::Exporter -setup => { - exports => [ - qw(output_is output_isnt output_like output_unlike - stderr_is stderr_isnt stderr_like stderr_unlike - stdout_is stdout_isnt stdout_like stdout_unlike - combined_is combined_isnt combined_like combined_unlike - output_from stderr_from stdout_from combined_from - ) - ], - groups => { - stdout => [ - qw( - stdout_is stdout_isnt stdout_like stdout_unlike - ) - ], - stderr => [ - qw( - stderr_is stderr_isnt stderr_like stderr_unlike - ) - ], - output => [ - qw( - output_is output_isnt output_like output_unlike - ) - ], - combined => [ - qw( - combined_is combined_isnt combined_like combined_unlike - ) - ], - functions => [ - qw( - output_from stderr_from stdout_from combined_from - ) - ], - tests => [ - qw( - output_is output_isnt output_like output_unlike - stderr_is stderr_isnt stderr_like stderr_unlike - stdout_is stdout_isnt stdout_like stdout_unlike - combined_is combined_isnt combined_like combined_unlike - ) + exports => [ + qw(output_is output_isnt output_like output_unlike + stderr_is stderr_isnt stderr_like stderr_unlike + stdout_is stdout_isnt stdout_like stdout_unlike + combined_is combined_isnt combined_like combined_unlike + output_from stderr_from stdout_from combined_from + ) ], - default => [ '-tests' ], - }, + groups => { + stdout => [ qw( + stdout_is stdout_isnt stdout_like stdout_unlike + ) + ], + stderr => [ qw( + stderr_is stderr_isnt stderr_like stderr_unlike + ) + ], + output => [ qw( + output_is output_isnt output_like output_unlike + ) + ], + combined => [ qw( + combined_is combined_isnt combined_like combined_unlike + ) + ], + functions => [ qw( + output_from stderr_from stdout_from combined_from + ) + ], + tests => [ qw( + output_is output_isnt output_like output_unlike + stderr_is stderr_isnt stderr_like stderr_unlike + stdout_is stdout_isnt stdout_like stdout_unlike + combined_is combined_isnt combined_like combined_unlike + ) + ], + default => ['-tests'], + }, }; my $Test = Test::Builder->new; @@ -140,35 +134,35 @@ stdout_isnt() passes if STDOUT is not equal to $expected. =cut sub stdout_is (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - my $stdout = stdout_from($test); + my $stdout = stdout_from($test); - my $ok = ( $stdout eq $expected ); + my $ok = ( $stdout eq $expected ); - $Test->ok( $ok, $description ) - || $Test->diag("STDOUT is:\n$stdout\nnot:\n$expected\nas expected"); + $Test->ok( $ok, $description ) + || $Test->diag("STDOUT is:\n$stdout\nnot:\n$expected\nas expected"); - return $ok; + return $ok; } sub stdout_isnt (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - my $stdout = stdout_from($test); + my $stdout = stdout_from($test); - my $ok = ( $stdout ne $expected ); + my $ok = ( $stdout ne $expected ); - $Test->ok( $ok, $description ) - || $Test->diag("STDOUT:\n$stdout\nmatching:\n$expected\nnot expected"); + $Test->ok( $ok, $description ) + || $Test->diag("STDOUT:\n$stdout\nmatching:\n$expected\nnot expected"); - return $ok; + return $ok; } =item B @@ -190,43 +184,44 @@ stdout_unlike() passes if STDOUT does not match the regex. =cut sub stdout_like (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - unless ( my $regextest = _chkregex( 'stdout_like' => $expected ) ) { - return $regextest; - } + unless ( my $regextest = _chkregex( 'stdout_like' => $expected ) ) { + return $regextest; + } - my $stdout = stdout_from($test); + my $stdout = stdout_from($test); - my $ok = ( $stdout =~ $expected ); + my $ok = ( $stdout =~ $expected ); - $Test->ok( $ok, $description ) - || $Test->diag("STDOUT:\n$stdout\ndoesn't match:\n$expected\nas expected"); + $Test->ok( $ok, $description ) + || $Test->diag( + "STDOUT:\n$stdout\ndoesn't match:\n$expected\nas expected"); - return $ok; -} + return $ok; +} ## end sub stdout_like (&$;$$) sub stdout_unlike (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - unless ( my $regextest = _chkregex( 'stdout_unlike' => $expected ) ) { - return $regextest; - } + unless ( my $regextest = _chkregex( 'stdout_unlike' => $expected ) ) { + return $regextest; + } - my $stdout = stdout_from($test); + my $stdout = stdout_from($test); - my $ok = ( $stdout !~ $expected ); + my $ok = ( $stdout !~ $expected ); - $Test->ok( $ok, $description ) - || $Test->diag("STDOUT:\n$stdout\nmatches:\n$expected\nnot expected"); + $Test->ok( $ok, $description ) + || $Test->diag("STDOUT:\n$stdout\nmatches:\n$expected\nnot expected"); - return $ok; + return $ok; } =head2 STDERR @@ -250,35 +245,35 @@ stderr_isnt() passes if STDERR is not equal to $expected. =cut sub stderr_is (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - my $stderr = stderr_from($test); + my $stderr = stderr_from($test); - my $ok = ( $stderr eq $expected ); + my $ok = ( $stderr eq $expected ); - $Test->ok( $ok, $description ) - || $Test->diag("STDERR is:\n$stderr\nnot:\n$expected\nas expected"); + $Test->ok( $ok, $description ) + || $Test->diag("STDERR is:\n$stderr\nnot:\n$expected\nas expected"); - return $ok; + return $ok; } sub stderr_isnt (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - my $stderr = stderr_from($test); + my $stderr = stderr_from($test); - my $ok = ( $stderr ne $expected ); + my $ok = ( $stderr ne $expected ); - $Test->ok( $ok, $description ) - || $Test->diag("STDERR:\n$stderr\nmatches:\n$expected\nnot expected"); + $Test->ok( $ok, $description ) + || $Test->diag("STDERR:\n$stderr\nmatches:\n$expected\nnot expected"); - return $ok; + return $ok; } =item B @@ -301,43 +296,44 @@ stderr_unlike() passes if STDERR does not match the regex. =cut sub stderr_like (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - unless ( my $regextest = _chkregex( 'stderr_like' => $expected ) ) { - return $regextest; - } + unless ( my $regextest = _chkregex( 'stderr_like' => $expected ) ) { + return $regextest; + } - my $stderr = stderr_from($test); + my $stderr = stderr_from($test); - my $ok = ( $stderr =~ $expected ); + my $ok = ( $stderr =~ $expected ); - $Test->ok( $ok, $description ) - || $Test->diag("STDERR:\n$stderr\ndoesn't match:\n$expected\nas expected"); + $Test->ok( $ok, $description ) + || $Test->diag( + "STDERR:\n$stderr\ndoesn't match:\n$expected\nas expected"); - return $ok; -} + return $ok; +} ## end sub stderr_like (&$;$$) sub stderr_unlike (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - unless ( my $regextest = _chkregex( 'stderr_unlike' => $expected ) ) { - return $regextest; - } + unless ( my $regextest = _chkregex( 'stderr_unlike' => $expected ) ) { + return $regextest; + } - my $stderr = stderr_from($test); + my $stderr = stderr_from($test); - my $ok = ( $stderr !~ $expected ); + my $ok = ( $stderr !~ $expected ); - $Test->ok( $ok, $description ) - || $Test->diag("STDERR:\n$stderr\nmatches:\n$expected\nnot expected"); + $Test->ok( $ok, $description ) + || $Test->diag("STDERR:\n$stderr\nmatches:\n$expected\nnot expected"); - return $ok; + return $ok; } =head2 COMBINED OUTPUT @@ -363,37 +359,37 @@ to $expected. =cut sub combined_is (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - my $combined = combined_from($test); + my $combined = combined_from($test); - my $ok = ( $combined eq $expected ); + my $ok = ( $combined eq $expected ); - $Test->ok( $ok, $description ) - || $Test->diag( - "STDOUT & STDERR are:\n$combined\nnot:\n$expected\nas expected"); + $Test->ok( $ok, $description ) + || $Test->diag( + "STDOUT & STDERR are:\n$combined\nnot:\n$expected\nas expected"); - return $ok; + return $ok; } sub combined_isnt (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - my $combined = combined_from($test); + my $combined = combined_from($test); - my $ok = ( $combined ne $expected ); + my $ok = ( $combined ne $expected ); - $Test->ok( $ok, $description ) - || $Test->diag( - "STDOUT & STDERR:\n$combined\nmatching:\n$expected\nnot expected"); + $Test->ok( $ok, $description ) + || $Test->diag( + "STDOUT & STDERR:\n$combined\nmatching:\n$expected\nnot expected"); - return $ok; + return $ok; } =item B @@ -417,46 +413,46 @@ the regex. =cut sub combined_like (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - unless ( my $regextest = _chkregex( 'combined_like' => $expected ) ) { - return $regextest; - } + unless ( my $regextest = _chkregex( 'combined_like' => $expected ) ) { + return $regextest; + } - my $combined = combined_from($test); + my $combined = combined_from($test); - my $ok = ( $combined =~ $expected ); + my $ok = ( $combined =~ $expected ); - $Test->ok( $ok, $description ) - || $Test->diag( - "STDOUT & STDERR:\n$combined\ndon't match:\n$expected\nas expected"); + $Test->ok( $ok, $description ) + || $Test->diag( + "STDOUT & STDERR:\n$combined\ndon't match:\n$expected\nas expected"); - return $ok; -} + return $ok; +} ## end sub combined_like (&$;$$) sub combined_unlike (&$;$$) { - my $test = shift; - my $expected = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; + my $test = shift; + my $expected = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; - unless ( my $regextest = _chkregex( 'combined_unlike' => $expected ) ) { - return $regextest; - } + unless ( my $regextest = _chkregex( 'combined_unlike' => $expected ) ) { + return $regextest; + } - my $combined = combined_from($test); + my $combined = combined_from($test); - my $ok = ( $combined !~ $expected ); + my $ok = ( $combined !~ $expected ); - $Test->ok( $ok, $description ) - || $Test->diag( - "STDOUT & STDERR:\n$combined\nmatching:\n$expected\nnot expected"); + $Test->ok( $ok, $description ) + || $Test->diag( + "STDOUT & STDERR:\n$combined\nmatching:\n$expected\nnot expected"); - return $ok; -} + return $ok; +} ## end sub combined_unlike (&$;$$) =head2 OUTPUT @@ -516,100 +512,100 @@ is the same as =cut sub output_is (&$$;$$) { - my $test = shift; - my $expout = shift; - my $experr = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; - - my ( $stdout, $stderr ) = output_from($test); - - my $ok = 1; - my $diag; - - if ( defined($experr) && defined($expout) ) { - unless ( $stdout eq $expout ) { - $ok = 0; - $diag .= "STDOUT is:\n$stdout\nnot:\n$expout\nas expected"; + my $test = shift; + my $expout = shift; + my $experr = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; + + my ( $stdout, $stderr ) = output_from($test); + + my $ok = 1; + my $diag; + + if ( defined($experr) && defined($expout) ) { + unless ( $stdout eq $expout ) { + $ok = 0; + $diag .= "STDOUT is:\n$stdout\nnot:\n$expout\nas expected"; + } + unless ( $stderr eq $experr ) { + $diag .= "\n" unless ($ok); + $ok = 0; + $diag .= "STDERR is:\n$stderr\nnot:\n$experr\nas expected"; + } } - unless ( $stderr eq $experr ) { - $diag .= "\n" unless ($ok); - $ok = 0; - $diag .= "STDERR is:\n$stderr\nnot:\n$experr\nas expected"; + elsif ( defined($expout) ) { + $ok = ( $stdout eq $expout ); + $diag .= "STDOUT is:\n$stdout\nnot:\n$expout\nas expected"; } - } - elsif ( defined($expout) ) { - $ok = ( $stdout eq $expout ); - $diag .= "STDOUT is:\n$stdout\nnot:\n$expout\nas expected"; - } - elsif ( defined($experr) ) { - $ok = ( $stderr eq $experr ); - $diag .= "STDERR is:\n$stderr\nnot:\n$experr\nas expected"; - } - else { - unless ( $stdout eq '' ) { - $ok = 0; - $diag .= "STDOUT is:\n$stdout\nnot:\n\nas expected"; + elsif ( defined($experr) ) { + $ok = ( $stderr eq $experr ); + $diag .= "STDERR is:\n$stderr\nnot:\n$experr\nas expected"; } - unless ( $stderr eq '' ) { - $diag .= "\n" unless ($ok); - $ok = 0; - $diag .= "STDERR is:\n$stderr\nnot:\n\nas expected"; + else { + unless ( $stdout eq '' ) { + $ok = 0; + $diag .= "STDOUT is:\n$stdout\nnot:\n\nas expected"; + } + unless ( $stderr eq '' ) { + $diag .= "\n" unless ($ok); + $ok = 0; + $diag .= "STDERR is:\n$stderr\nnot:\n\nas expected"; + } } - } - $Test->ok( $ok, $description ) || $Test->diag($diag); + $Test->ok( $ok, $description ) || $Test->diag($diag); - return $ok; -} + return $ok; +} ## end sub output_is (&$$;$$) sub output_isnt (&$$;$$) { - my $test = shift; - my $expout = shift; - my $experr = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; - - my ( $stdout, $stderr ) = output_from($test); - - my $ok = 1; - my $diag; - - if ( defined($experr) && defined($expout) ) { - if ( $stdout eq $expout ) { - $ok = 0; - $diag .= "STDOUT:\n$stdout\nmatching:\n$expout\nnot expected"; + my $test = shift; + my $expout = shift; + my $experr = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; + + my ( $stdout, $stderr ) = output_from($test); + + my $ok = 1; + my $diag; + + if ( defined($experr) && defined($expout) ) { + if ( $stdout eq $expout ) { + $ok = 0; + $diag .= "STDOUT:\n$stdout\nmatching:\n$expout\nnot expected"; + } + if ( $stderr eq $experr ) { + $diag .= "\n" unless ($ok); + $ok = 0; + $diag .= "STDERR:\n$stderr\nmatching:\n$experr\nnot expected"; + } } - if ( $stderr eq $experr ) { - $diag .= "\n" unless ($ok); - $ok = 0; - $diag .= "STDERR:\n$stderr\nmatching:\n$experr\nnot expected"; + elsif ( defined($expout) ) { + $ok = ( $stdout ne $expout ); + $diag = "STDOUT:\n$stdout\nmatching:\n$expout\nnot expected"; } - } - elsif ( defined($expout) ) { - $ok = ( $stdout ne $expout ); - $diag = "STDOUT:\n$stdout\nmatching:\n$expout\nnot expected"; - } - elsif ( defined($experr) ) { - $ok = ( $stderr ne $experr ); - $diag = "STDERR:\n$stderr\nmatching:\n$experr\nnot expected"; - } - else { - if ( $stdout eq '' ) { - $ok = 0; - $diag = "STDOUT:\n$stdout\nmatching:\n\nnot expected"; + elsif ( defined($experr) ) { + $ok = ( $stderr ne $experr ); + $diag = "STDERR:\n$stderr\nmatching:\n$experr\nnot expected"; } - if ( $stderr eq '' ) { - $diag .= "\n" unless ($ok); - $ok = 0; - $diag .= "STDERR:\n$stderr\nmatching:\n\nnot expected"; + else { + if ( $stdout eq '' ) { + $ok = 0; + $diag = "STDOUT:\n$stdout\nmatching:\n\nnot expected"; + } + if ( $stderr eq '' ) { + $diag .= "\n" unless ($ok); + $ok = 0; + $diag .= "STDERR:\n$stderr\nmatching:\n\nnot expected"; + } } - } - $Test->ok( $ok, $description ) || $Test->diag($diag); + $Test->ok( $ok, $description ) || $Test->diag($diag); - return $ok; -} + return $ok; +} ## end sub output_isnt (&$$;$$) =item B @@ -647,109 +643,105 @@ $regex_stdout and $regex_stderr. =cut sub output_like (&$$;$$) { - my $test = shift; - my $expout = shift; - my $experr = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; - - my ( $stdout, $stderr ) = output_from($test); - - my $ok = 1; - - unless ( - my $regextest = _chkregex( - 'output_like_STDERR' => $experr, - 'output_like_STDOUT' => $expout - ) - ) - { - return $regextest; - } - - my $diag; - if ( defined($experr) && defined($expout) ) { - unless ( $stdout =~ $expout ) { - $ok = 0; - $diag .= "STDOUT:\n$stdout\ndoesn't match:\n$expout\nas expected"; + my $test = shift; + my $expout = shift; + my $experr = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; + + my ( $stdout, $stderr ) = output_from($test); + + my $ok = 1; + + unless ( + my $regextest = _chkregex( 'output_like_STDERR' => $experr, + 'output_like_STDOUT' => $expout ) + ) + { + return $regextest; + } + + my $diag; + if ( defined($experr) && defined($expout) ) { + unless ( $stdout =~ $expout ) { + $ok = 0; + $diag .= "STDOUT:\n$stdout\ndoesn't match:\n$expout\nas expected"; + } + unless ( $stderr =~ $experr ) { + $diag .= "\n" unless ($ok); + $ok = 0; + $diag .= "STDERR:\n$stderr\ndoesn't match:\n$experr\nas expected"; + } } - unless ( $stderr =~ $experr ) { - $diag .= "\n" unless ($ok); - $ok = 0; - $diag .= "STDERR:\n$stderr\ndoesn't match:\n$experr\nas expected"; + elsif ( defined($expout) ) { + $ok = ( $stdout =~ $expout ); + $diag .= "STDOUT:\n$stdout\ndoesn't match:\n$expout\nas expected"; } - } - elsif ( defined($expout) ) { - $ok = ( $stdout =~ $expout ); - $diag .= "STDOUT:\n$stdout\ndoesn't match:\n$expout\nas expected"; - } - elsif ( defined($experr) ) { - $ok = ( $stderr =~ $experr ); - $diag .= "STDERR:\n$stderr\ndoesn't match:\n$experr\nas expected"; - } - else { - unless ( $stdout eq '' ) { - $ok = 0; - $diag .= "STDOUT is:\n$stdout\nnot:\n\nas expected"; + elsif ( defined($experr) ) { + $ok = ( $stderr =~ $experr ); + $diag .= "STDERR:\n$stderr\ndoesn't match:\n$experr\nas expected"; } - unless ( $stderr eq '' ) { - $diag .= "\n" unless ($ok); - $ok = 0; - $diag .= "STDERR is:\n$stderr\nnot:\n\nas expected"; + else { + unless ( $stdout eq '' ) { + $ok = 0; + $diag .= "STDOUT is:\n$stdout\nnot:\n\nas expected"; + } + unless ( $stderr eq '' ) { + $diag .= "\n" unless ($ok); + $ok = 0; + $diag .= "STDERR is:\n$stderr\nnot:\n\nas expected"; + } } - } - $Test->ok( $ok, $description ) || $Test->diag($diag); + $Test->ok( $ok, $description ) || $Test->diag($diag); - return $ok; -} + return $ok; +} ## end sub output_like (&$$;$$) sub output_unlike (&$$;$$) { - my $test = shift; - my $expout = shift; - my $experr = shift; - my $options = shift if ( ref( $_[0] ) ); - my $description = shift; - - my ( $stdout, $stderr ) = output_from($test); - - my $ok = 1; - - unless ( - my $regextest = _chkregex( - 'output_unlike_STDERR' => $experr, - 'output_unlike_STDOUT' => $expout - ) - ) - { - return $regextest; - } - - my $diag; - if ( defined($experr) && defined($expout) ) { - if ( $stdout =~ $expout ) { - $ok = 0; - $diag .= "STDOUT:\n$stdout\nmatches:\n$expout\nnot expected"; + my $test = shift; + my $expout = shift; + my $experr = shift; + my $options = shift if ( ref( $_[0] ) ); + my $description = shift; + + my ( $stdout, $stderr ) = output_from($test); + + my $ok = 1; + + unless ( + my $regextest = _chkregex( 'output_unlike_STDERR' => $experr, + 'output_unlike_STDOUT' => $expout ) + ) + { + return $regextest; } - if ( $stderr =~ $experr ) { - $diag .= "\n" unless ($ok); - $ok = 0; - $diag .= "STDERR:\n$stderr\nmatches:\n$experr\nnot expected"; + + my $diag; + if ( defined($experr) && defined($expout) ) { + if ( $stdout =~ $expout ) { + $ok = 0; + $diag .= "STDOUT:\n$stdout\nmatches:\n$expout\nnot expected"; + } + if ( $stderr =~ $experr ) { + $diag .= "\n" unless ($ok); + $ok = 0; + $diag .= "STDERR:\n$stderr\nmatches:\n$experr\nnot expected"; + } + } + elsif ( defined($expout) ) { + $ok = ( $stdout !~ $expout ); + $diag .= "STDOUT:\n$stdout\nmatches:\n$expout\nnot expected"; + } + elsif ( defined($experr) ) { + $ok = ( $stderr !~ $experr ); + $diag .= "STDERR:\n$stderr\nmatches:\n$experr\nnot expected"; } - } - elsif ( defined($expout) ) { - $ok = ( $stdout !~ $expout ); - $diag .= "STDOUT:\n$stdout\nmatches:\n$expout\nnot expected"; - } - elsif ( defined($experr) ) { - $ok = ( $stderr !~ $experr ); - $diag .= "STDERR:\n$stderr\nmatches:\n$experr\nnot expected"; - } - - $Test->ok( $ok, $description ) || $Test->diag($diag); - - return $ok; -} + + $Test->ok( $ok, $description ) || $Test->diag($diag); + + return $ok; +} ## end sub output_unlike (&$$;$$) =head1 EXPORTS @@ -817,18 +809,18 @@ stdout_from() executes $coderef and captures STDOUT. =cut sub stdout_from (&) { - my $test = shift; + my $test = shift; - select( ( select(STDOUT), $| = 1 )[0] ); - my $out = tie *STDOUT, 'Test::Output::Tie'; + select( ( select(STDOUT), $| = 1 )[0] ); + my $out = tie *STDOUT, 'Test::Output::Tie'; - &$test; - my $stdout = $out->read; + &$test; + my $stdout = $out->read; - undef $out; - untie *STDOUT; + undef $out; + untie *STDOUT; - return $stdout; + return $stdout; } =head2 stderr_from @@ -841,21 +833,21 @@ stderr_from() executes $coderef and captures STDERR. =cut sub stderr_from (&) { - my $test = shift; + my $test = shift; + + local $SIG{__WARN__} = sub { print STDERR @_ } + if $] < 5.008; - local $SIG{__WARN__} = sub { print STDERR @_ } - if $] < 5.008; - - select( ( select(STDERR), $| = 1 )[0] ); - my $err = tie *STDERR, 'Test::Output::Tie'; + select( ( select(STDERR), $| = 1 )[0] ); + my $err = tie *STDERR, 'Test::Output::Tie'; - &$test; - my $stderr = $err->read; + &$test; + my $stderr = $err->read; - undef $err; - untie *STDERR; + undef $err; + untie *STDERR; - return $stderr; + return $stderr; } =head2 output_from @@ -868,23 +860,23 @@ output_from() executes $coderef one time capturing both STDOUT and STDERR. =cut sub output_from (&) { - my $test = shift; + my $test = shift; - select( ( select(STDOUT), $| = 1 )[0] ); - select( ( select(STDERR), $| = 1 )[0] ); - my $out = tie *STDOUT, 'Test::Output::Tie'; - my $err = tie *STDERR, 'Test::Output::Tie'; + select( ( select(STDOUT), $| = 1 )[0] ); + select( ( select(STDERR), $| = 1 )[0] ); + my $out = tie *STDOUT, 'Test::Output::Tie'; + my $err = tie *STDERR, 'Test::Output::Tie'; - &$test; - my $stdout = $out->read; - my $stderr = $err->read; + &$test; + my $stdout = $out->read; + my $stderr = $err->read; - undef $out; - undef $err; - untie *STDOUT; - untie *STDERR; + undef $out; + undef $err; + untie *STDOUT; + untie *STDERR; - return ( $stdout, $stderr ); + return ( $stdout, $stderr ); } =head2 combined_from @@ -898,47 +890,49 @@ captures them. combined_from() is equivalent to using 2>&1 in UNIX. =cut sub combined_from (&) { - my $test = shift; + my $test = shift; - select( ( select(STDOUT), $| = 1 )[0] ); - select( ( select(STDERR), $| = 1 )[0] ); + select( ( select(STDOUT), $| = 1 )[0] ); + select( ( select(STDERR), $| = 1 )[0] ); - open( STDERR, ">&STDOUT" ); + open( STDERR, ">&STDOUT" ); - my $out = tie *STDOUT, 'Test::Output::Tie'; - tie *STDERR, 'Test::Output::Tie', $out; + my $out = tie *STDOUT, 'Test::Output::Tie'; + tie *STDERR, 'Test::Output::Tie', $out; - &$test; - my $combined = $out->read; + &$test; + my $combined = $out->read; - undef $out; - { - no warnings; - untie *STDOUT; - untie *STDERR; - } - - return ($combined); -} + undef $out; + { + no warnings; + untie *STDOUT; + untie *STDERR; + } + + return ($combined); +} ## end sub combined_from (&) sub _chkregex { - my %regexs = @_; + my %regexs = @_; - foreach my $test ( keys(%regexs) ) { - next unless ( defined( $regexs{$test} ) ); + foreach my $test ( keys(%regexs) ) { + next unless ( defined( $regexs{$test} ) ); - my $usable_regex = $Test->maybe_regex( $regexs{$test} ); - unless ( defined($usable_regex) ) { - my $ok = $Test->ok( 0, $test ); + my $usable_regex = $Test->maybe_regex( $regexs{$test} ); + unless ( defined($usable_regex) ) { + my $ok = $Test->ok( 0, $test ); + + $Test->diag( + "'$regexs{$test}' doesn't look much like a regex to me."); - $Test->diag("'$regexs{$test}' doesn't look much like a regex to me."); # unless $ok; - return $ok; + return $ok; + } } - } - return 1; -} + return 1; +} ## end sub _chkregex =head1 AUTHOR diff --git a/t/lib/Test/Output/Tie.pm b/t/lib/Test/Output/Tie.pm index 4d69e62f3..e333fc4a4 100644 --- a/t/lib/Test/Output/Tie.pm +++ b/t/lib/Test/Output/Tie.pm @@ -1,7 +1,7 @@ package Test::Output::Tie; use vars qw($VERSION); -$VERSION='0.14'; +$VERSION = '0.14'; use strict; use warnings; @@ -29,11 +29,11 @@ The constructor for the class. =cut sub TIEHANDLE { - my $class = shift; - my $scalar = ''; - my $obj = shift || \$scalar; + my $class = shift; + my $scalar = ''; + my $obj = shift || \$scalar; - bless( $obj, $class); + bless( $obj, $class ); } =item PRINT @@ -44,7 +44,7 @@ This method is called each time STDERR or STDOUT are printed to. sub PRINT { my $self = shift; - $$self .= join('', @_); + $$self .= join( '', @_ ); } =item PRINTF @@ -63,13 +63,13 @@ sub PRINTF { =cut -sub FILENO {} +sub FILENO { } =item BINMODE =cut -sub BINMODE {} +sub BINMODE { } =item read diff --git a/t/plugins/IgnorePerl/IgnorePerl.pl b/t/plugins/IgnorePerl/IgnorePerl.pl index 955a1fcd9..40c00e1f0 100644 --- a/t/plugins/IgnorePerl/IgnorePerl.pl +++ b/t/plugins/IgnorePerl/IgnorePerl.pl @@ -6,17 +6,22 @@ package MT::Plugin::IgnorePerl; our $VERSION = '1.0'; my $plugin; -MT->add_plugin($plugin = __PACKAGE__->new({ - name => 'Ignore perl - Perl initialized', - version => $VERSION, - description => 'Perl-initialized version of a plugin that should be ignored because of the config.yaml', - author_name => 'Jay Allen', - key => 'IgnorePerl', - id => 'ignoreperl', -})); +MT->add_plugin( + $plugin = + __PACKAGE__->new( { + name => 'Ignore perl - Perl initialized', + version => $VERSION, + description => + 'Perl-initialized version of a plugin that should be ignored because of the config.yaml', + author_name => 'Jay Allen', + key => 'IgnorePerl', + id => 'ignoreperl', + } + ) +); use MT::Template::Context; MT::Template::Context->add_tag( IDontExist => sub {1} ); -1; \ No newline at end of file +1; diff --git a/t/plugins/stray.pl b/t/plugins/stray.pl index 05d0cb9a1..744899071 100644 --- a/t/plugins/stray.pl +++ b/t/plugins/stray.pl @@ -12,14 +12,19 @@ package MT::Plugin::NakedPerl; our $VERSION = '0.1'; my $plugin; -MT->add_plugin($plugin = __PACKAGE__->new({ - name => "Naked perl-initialized test", - version => $VERSION, - description => "Bad legacy plugin without a plugin envelope. No cookie", - author_name => "Whatnot Smith", - key => 'NakedPerl', - id => 'NakedPerl', -})); +MT->add_plugin( + $plugin = + __PACKAGE__->new( { + name => "Naked perl-initialized test", + version => $VERSION, + description => + "Bad legacy plugin without a plugin envelope. No cookie", + author_name => "Whatnot Smith", + key => 'NakedPerl', + id => 'NakedPerl', + } + ) +); use MT::Template::Context; diff --git a/t/plugins/subfoldered/subfoldered.pl b/t/plugins/subfoldered/subfoldered.pl index c3c71362e..e9428b7fe 100644 --- a/t/plugins/subfoldered/subfoldered.pl +++ b/t/plugins/subfoldered/subfoldered.pl @@ -7,13 +7,17 @@ package MT::Plugin::Subfoldered; our $VERSION = '0.1'; my $plugin; -MT->add_plugin( $plugin = __PACKAGE__->new({ - name => 'A Subfoldered Plugin', - id => 'Subfoldered', - key => 'Subfoldered', - version => $VERSION, - description => "Subfoldered legacy format plugin", - author_name => "Whomever", -})); +MT->add_plugin( + $plugin = + __PACKAGE__->new( { + name => 'A Subfoldered Plugin', + id => 'Subfoldered', + key => 'Subfoldered', + version => $VERSION, + description => "Subfoldered legacy format plugin", + author_name => "Whomever", + } + ) +); 1; diff --git a/tools/convert-db b/tools/convert-db index cd0d76bcc..3b85473f0 100755 --- a/tools/convert-db +++ b/tools/convert-db @@ -23,12 +23,12 @@ unless ($new_config) { $old_config ||= '.'; my @CLASSES = qw( MT::Author MT::Blog MT::Category MT::Comment MT::Entry - MT::Log MT::Notification MT::Permission - MT::Placement MT::Template MT::TemplateMap MT::Trackback - MT::TBPing MT::Session MT::PluginData MT::Config MT::FileInfo - MT::Tag MT::ObjectTag MT::Group MT::Role MT::Association - MT::Asset - ); + MT::Log MT::Notification MT::Permission + MT::Placement MT::Template MT::TemplateMap MT::Trackback + MT::TBPing MT::Session MT::PluginData MT::Config MT::FileInfo + MT::Tag MT::ObjectTag MT::Group MT::Role MT::Association + MT::Asset +); use File::Spec; diff --git a/tools/export-theme b/tools/export-theme index 76f1cf7a3..bbe126b1c 100755 --- a/tools/export-theme +++ b/tools/export-theme @@ -54,10 +54,13 @@ sub help { --zip Produce a zip file of the resulting theme. (default: off) }; -} +} ## end sub help -my ( $BLOG_IDS, $TS_NAME, $TS_ID, $TS_KEY, $DRYRUN, $INTERACTIVE, $ZIP, - $TS_VERSION, $VERBOSE, $BASE_DIR, $STATIC, %seen, %static_map ); +my ( + $BLOG_IDS, $TS_NAME, $TS_ID, $TS_KEY, $DRYRUN, + $INTERACTIVE, $ZIP, $TS_VERSION, $VERBOSE, $BASE_DIR, + $STATIC, %seen, %static_map +); $TS_NAME = 'My Template Set'; $TS_VERSION = '1.0'; @@ -65,15 +68,15 @@ $INTERACTIVE = 0; sub options { return ( - 'blog=s' => \$BLOG_IDS, - 'name=s' => \$TS_NAME, - 'static' => \$STATIC, - 'id=s' => \$TS_ID, - 'key=s' => \$TS_KEY, - 'version=s' => \$TS_VERSION, - 'dryrun' => \$DRYRUN, - 'i' => \$INTERACTIVE, - 'zip' => \$ZIP, + 'blog=s' => \$BLOG_IDS, + 'name=s' => \$TS_NAME, + 'static' => \$STATIC, + 'id=s' => \$TS_ID, + 'key=s' => \$TS_KEY, + 'version=s' => \$TS_VERSION, + 'dryrun' => \$DRYRUN, + 'i' => \$INTERACTIVE, + 'zip' => \$ZIP, ); } @@ -86,36 +89,36 @@ sub main { # No use doing a dry run if we can't see what's happening $VERBOSE = $DRYRUN if $DRYRUN; - - $class->show_usage() && exit if (! defined $BLOG_IDS) || !$TS_NAME; + + $class->show_usage() && exit if ( !defined $BLOG_IDS ) || !$TS_NAME; my $blog; - my (%pack_opts, %export_opts); + my ( %pack_opts, %export_opts ); $pack_opts{'pack_name'} = 'My Theme Pack'; - my $id = $TS_ID; - my $key = $TS_KEY; - my $name = $TS_NAME; - - $id ||= MT::Util::dirify($TS_NAME); - $key ||= MT::Util::dirify($TS_NAME); + my $id = $TS_ID; + my $key = $TS_KEY; + my $name = $TS_NAME; + + $id ||= MT::Util::dirify($TS_NAME); + $key ||= MT::Util::dirify($TS_NAME); my $pack_opts = { - logger => sub { print STDERR $_[0] }, - key => $TS_KEY, - pack_version => $TS_VERSION, - verbose => $VERBOSE, - dryrun => $DRYRUN, - zip => $ZIP, + logger => sub { print STDERR $_[0] }, + key => $TS_KEY, + pack_version => $TS_VERSION, + verbose => $VERBOSE, + dryrun => $DRYRUN, + zip => $ZIP, }; - my @blog_ids = split(',',$BLOG_IDS); - if ($#blog_ids == 0 && !$name) { + my @blog_ids = split( ',', $BLOG_IDS ); + if ( $#blog_ids == 0 && !$name ) { $blog = MT->model('blog')->load( $blog_ids[0] ); $pack_opts->{'pack_name'} = $blog->name . ' Theme Pack'; } - my $exporter = MT::Theme::Exporter->new( $pack_opts ); + my $exporter = MT::Theme::Exporter->new($pack_opts); my $static_base = MT::Theme::Exporter::_static_file_path( MT->instance ); foreach my $blog_id (@blog_ids) { $blog = MT->model('blog')->load( MT::Util::trim($blog_id) ); @@ -124,70 +127,84 @@ sub main { if ( $blog->template_set ) { my $plugin = find_theme_plugin( $blog->template_set ); my $static; - if (defined( $static_map{ $blog->template_set }) ) { + if ( defined( $static_map{ $blog->template_set } ) ) { $export_opts{'static'} = $static_map{ $blog->template_set }; - } else { - $static = File::Spec->catdir( $static_base, 'plugins', $plugin->key ); - if (-e $static) { - $export_opts{'static'} = File::Spec->catdir( 'plugins', $plugin->key ); + } + else { + $static = File::Spec->catdir( $static_base, 'plugins', + $plugin->key ); + if ( -e $static ) { + $export_opts{'static'} + = File::Spec->catdir( 'plugins', $plugin->key ); } } } - if (!defined($export_opts{'static'}) && $INTERACTIVE) { -PROMPT: - my $path = _prompt("Path to static files for " . $blog->name ." (press to skip)\n". - "Relative to '".$static_base."'",''); + if ( !defined( $export_opts{'static'} ) && $INTERACTIVE ) { + PROMPT: + my $path = _prompt( + "Path to static files for " + . $blog->name + . " (press to skip)\n" + . "Relative to '" + . $static_base . "'", + '' + ); my $fullpath = File::Spec->catdir( $static_base, $path ); - if (! -e $fullpath ) { + if ( !-e $fullpath ) { print "The path you entered '$fullpath' does not exist.\n"; goto PROMPT; } - if ($path ne "") { + if ( $path ne "" ) { $export_opts{'static'} = $path; $static_map{ $blog->template_set } = $path; } - } + } ## end if ( !defined( $export_opts...)) my $id = _generate_unique_id( $blog->name ); - $exporter->export({ - blog_id => $blog_id, - name => $blog->name . " Theme", - id => $id, - key => $id, - %export_opts - }); - } + $exporter->export( { + blog_id => $blog_id, + name => $blog->name . " Theme", + id => $id, + key => $id, + %export_opts + } + ); + } ## end foreach my $blog_id (@blog_ids) $exporter->write(); -} +} ## end sub main sub _generate_unique_id { my ($str) = @_; - my $name = MT::Util::dirify( $str ); - if ( defined $seen{ $name } ) { - if ($name =~ s/_(\d+)$//) { - $name = $name . ($1 + 1); - return _generate_unique_id( $name ); - } else { + my $name = MT::Util::dirify($str); + if ( defined $seen{$name} ) { + if ( $name =~ s/_(\d+)$// ) { + $name = $name . ( $1 + 1 ); + return _generate_unique_id($name); + } + else { return _generate_unique_id( $name . "_1" ); } - } else { - $seen{ $name } = 1; + } + else { + $seen{$name} = 1; return $name; } } sub _prompt { - my ($promptString,$defaultValue) = @_; + my ( $promptString, $defaultValue ) = @_; if ($defaultValue) { print $promptString, "[", $defaultValue, "]: "; - } else { + } + else { print $promptString, ": "; } - $| = 1; # force a flush after our print - $_ = ; # get the input from STDIN (presumably the keyboard) + $| = 1; # force a flush after our print + $_ = ; # get the input from STDIN (presumably the keyboard) chomp; if ("$defaultValue") { return $_ ? $_ : $defaultValue; # return $_ if it has a value - } else { + } + else { return $_; } } diff --git a/tools/populate b/tools/populate index dd3b49ed1..c340ca253 100755 --- a/tools/populate +++ b/tools/populate @@ -62,27 +62,27 @@ srand(1); # these are all the numbers that control how many of what are generated -sub weighted { +shift * $weight_factor } -sub randint { int(rand( +shift )) } -my $notifications_per_blog = sub { 3 + randint( 20 ) }; -my $blog_count = sub { weighted( $blogs ) }; -my $authors_per_blog = sub { weighted( $authors ) }; -my $categories_per_blog = sub { weighted( $cats + randint( 10 )) }; -my $entries_per_blog = sub { weighted( $entries + randint( 30 )) }; -my $comments_per_entry = sub { weighted( randint( 10 ) ) }; -my $tags_per_entry = sub { weighted( randint( 5 ) ) }; -my $pings_per_trackback = sub { weighted( randint( 10 ) ) }; +sub weighted { +shift *$weight_factor } +sub randint { int( rand( +shift ) ) } +my $notifications_per_blog = sub { 3 + randint(20) }; +my $blog_count = sub { weighted($blogs) }; +my $authors_per_blog = sub { weighted($authors) }; +my $categories_per_blog = sub { weighted( $cats + randint(10) ) }; +my $entries_per_blog = sub { weighted( $entries + randint(30) ) }; +my $comments_per_entry = sub { weighted( randint(10) ) }; +my $tags_per_entry = sub { weighted( randint(5) ) }; +my $pings_per_trackback = sub { weighted( randint(10) ) }; my %defs = ( 'MT::Blog' => { table => 'blog', as_of => 1.0, needs => [ - 'MT::Author' => $authors_per_blog, - 'MT::Category' => $categories_per_blog, - 'MT::Entry' => $entries_per_blog, - 'MT::Template' => \&template_loader, - 'MT::Notification' => $notifications_per_blog + 'MT::Author' => $authors_per_blog, + 'MT::Category' => $categories_per_blog, + 'MT::Entry' => $entries_per_blog, + 'MT::Template' => \&template_loader, + 'MT::Notification' => $notifications_per_blog ], fields => [ field( 'name', \&random_blog_name ), @@ -396,11 +396,8 @@ my %defs = ( # field('build_dynamic', [], 3.1), # ], }, - 'MT::TemplateMap' => { - table => 'templatemap', - as_of => 2.0, - }, - 'MT::Log' => { + 'MT::TemplateMap' => { table => 'templatemap', as_of => 2.0, }, + 'MT::Log' => { table => 'log', as_of => 1.0, diff --git a/tools/run-periodic-tasks b/tools/run-periodic-tasks index c71db3a86..9492562b3 100755 --- a/tools/run-periodic-tasks +++ b/tools/run-periodic-tasks @@ -54,7 +54,7 @@ require MT; my $mt = MT->new() or die MT->errstr; if ( defined( MT->config('RPTProcessCap') ) && $proc_process_table ) { - my $t = new Proc::ProcessTable; + my $t = new Proc::ProcessTable; my $rpt_count = 0; foreach my $p ( @{ $t->table } ) { my $cmd = $p->cmndline;